Debian Codegraph @

tests/test_it.cpp

raw symbols SCIP
1 /***************************************************************************
2 copyright : (C) 2011 by Mathias Panzenböck
3 email : [email protected]
4 ***************************************************************************/
5
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
10 * *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
19 * 02110-1301 USA *
20 * *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
25
26 #include <cassert>
27 #include "tstringlist.h"
28 #include "itfile.h"
29 #include <cppunit/extensions/HelperMacros.h>
30 #include "utils.h"
31
32 using namespace std;
33 using namespace TagLib;
34
35 static const String titleBefore("test song name");
36 static const String titleAfter("changed title");
37
38 static const String commentBefore(
39 "This is a sample name.\n"
40 "In module file formats\n"
41 "sample names are abused\n"
42 "as multiline comments.\n"
43 " ");
44
45 static const String newComment(
46 "This is a sample name!\n"
47 "In module file formats\n"
48 "sample names are abused\n"
49 "as multiline comments.\n"
50 "-----------------------------------\n"
51 "The previous line is truncated but starting with this line\n"
52 "the comment is not limeted in the line length but to 8000\n"
53 "additional characters (bytes).\n"
54 "\n"
55 "This is because it is saved in the 'message' proportion of\n"
56 "IT files.");
57
58 static const String commentAfter(
59 "This is a sample name!\n"
60 "In module file formats\n"
61 "sample names are abused\n"
62 "as multiline comments.\n"
63 "-------------------------\n"
64 "The previous line is truncated but starting with this line\n"
65 "the comment is not limeted in the line length but to 8000\n"
66 "additional characters (bytes).\n"
67 "\n"
68 "This is because it is saved in the 'message' proportion of\n"
69 "IT files.");
70
71 class TestIT : public CppUnit::TestFixture
72 {
73 CPPUNIT_TEST_SUITE(TestIT);
74 CPPUNIT_TEST(testReadTags);
75 CPPUNIT_TEST(testWriteTags);
76 CPPUNIT_TEST_SUITE_END();
77
78 public:
79 void testReadTags()
80 {
81 testRead(TEST_FILE_PATH_C("test.it"), titleBefore, commentBefore);
82 }
83
84 void testWriteTags()
85 {
86 ScopedFileCopy copy("test", ".it");
87 {
88 IT::File file(copy.fileName().c_str());
89 CPPUNIT_ASSERT(file.tag() != nullptr);
90 file.tag()->setTitle(titleAfter);
91 file.tag()->setComment(newComment);
92 file.tag()->setTrackerName("won't be saved");
93 CPPUNIT_ASSERT(file.save());
94 }
95 testRead(copy.fileName().c_str(), titleAfter, commentAfter);
96 }
97
98 private:
99 void testRead(FileName fileName, const String &title, const String &comment)
100 {
101 IT::File file(fileName);
102
103 CPPUNIT_ASSERT(file.isValid());
104
105 IT::Properties *p = file.audioProperties();
106 Mod::Tag *t = file.tag();
107
108 CPPUNIT_ASSERT(nullptr != p);
109 CPPUNIT_ASSERT(nullptr != t);
110 assert(p != nullptr); // to silence the clang analyzer
111
112 CPPUNIT_ASSERT_EQUAL( 0, p->lengthInSeconds());
113 CPPUNIT_ASSERT_EQUAL( 0, p->bitrate());
114 CPPUNIT_ASSERT_EQUAL( 0, p->sampleRate());
115 CPPUNIT_ASSERT_EQUAL(64, p->channels());
116 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(0), p->lengthInPatterns());
117 CPPUNIT_ASSERT_EQUAL(true, p->stereo());
118 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(0), p->instrumentCount());
119 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(5), p->sampleCount());
120 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1), p->patternCount());
121 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(535), p->version());
122 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(532), p->compatibleVersion());
123 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(9), p->flags());
124 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(128), p->globalVolume());
125 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(48), p->mixVolume());
126 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(125), p->tempo());
127 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(6), p->bpmSpeed());
128 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(128), p->panningSeparation());
129 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(0), p->pitchWheelDepth());
130 CPPUNIT_ASSERT_EQUAL(title, t->title());
131 CPPUNIT_ASSERT_EQUAL(String(), t->artist());
132 CPPUNIT_ASSERT_EQUAL(String(), t->album());
133 CPPUNIT_ASSERT_EQUAL(comment, t->comment());
134 CPPUNIT_ASSERT_EQUAL(String(), t->genre());
135 CPPUNIT_ASSERT_EQUAL(0U, t->year());
136 CPPUNIT_ASSERT_EQUAL(0U, t->track());
137 CPPUNIT_ASSERT_EQUAL(String("Impulse Tracker"), t->trackerName());
138 }
139 };
140
141 CPPUNIT_TEST_SUITE_REGISTRATION(TestIT);