Debian Codegraph @

tests/test_xm.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 "xmfile.h"
28 #include <cppunit/extensions/HelperMacros.h>
29 #include "utils.h"
30
31 using namespace std;
32 using namespace TagLib;
33
34 static const String titleBefore("title of song");
35 static const String titleAfter("changed title");
36
37 static const String trackerNameBefore("MilkyTracker ");
38 static const String trackerNameAfter("TagLib");
39
40 static const String commentBefore(
41 "Instrument names\n"
42 "are abused as\n"
43 "comments in\n"
44 "module file formats.\n"
45 "-+-+-+-+-+-+-+-+-+-+-+\n"
46 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
47 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
48 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
49 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
50 "\n\n\n"
51 "Sample\n"
52 "names\n"
53 "are sometimes\n"
54 "also abused as\n"
55 "comments.");
56
57 static const String newCommentShort(
58 "Instrument names\n"
59 "are abused as\n"
60 "comments in\n"
61 "module file formats.\n"
62 "======================\n"
63 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
64 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
65 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
66 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
67 "\n\n\n"
68 "Sample names\n"
69 "are sometimes\n"
70 "also abused as\n"
71 "comments.");
72
73 static const String newCommentLong(
74 "Instrument names\n"
75 "are abused as\n"
76 "comments in\n"
77 "module file formats.\n"
78 "======================\n"
79 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
80 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
81 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
82 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
83 "\n\n\n"
84 "Sample names\n"
85 "are sometimes\n"
86 "also abused as\n"
87 "comments.\n"
88 "\n\n\n\n\n\n\n"
89 "TEST");
90
91 static const String commentAfter(
92 "Instrument names\n"
93 "are abused as\n"
94 "comments in\n"
95 "module file formats.\n"
96 "======================\n"
97 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
98 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
99 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
100 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
101 "\n\n\n"
102 "Sample names\n"
103 "are sometimes\n"
104 "also abused as\n"
105 "comments.\n");
106
107 class TestXM : public CppUnit::TestFixture
108 {
109 CPPUNIT_TEST_SUITE(TestXM);
110 CPPUNIT_TEST(testReadTags);
111 CPPUNIT_TEST(testReadStrippedTags);
112 CPPUNIT_TEST(testWriteTagsShort);
113 CPPUNIT_TEST(testWriteTagsLong);
114 CPPUNIT_TEST_SUITE_END();
115
116 public:
117 void testReadTags()
118 {
119 testRead(TEST_FILE_PATH_C("test.xm"), titleBefore,
120 commentBefore, trackerNameBefore);
121 }
122
123 void testReadStrippedTags()
124 {
125 XM::File file(TEST_FILE_PATH_C("stripped.xm"));
126 CPPUNIT_ASSERT(file.isValid());
127
128 XM::Properties *p = file.audioProperties();
129 Mod::Tag *t = file.tag();
130
131 CPPUNIT_ASSERT(nullptr != p);
132 CPPUNIT_ASSERT(nullptr != t);
133 assert(p != nullptr); // to silence the clang analyzer
134
135 CPPUNIT_ASSERT_EQUAL(0, p->lengthInSeconds());
136 CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
137 CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
138 CPPUNIT_ASSERT_EQUAL(8, p->channels());
139 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1), p->lengthInPatterns());
140 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(0), p->version());
141 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(0) , p->restartPosition());
142 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1), p->patternCount());
143 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(0), p->instrumentCount());
144 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1), p->flags());
145 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(6), p->tempo());
146 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(125), p->bpmSpeed());
147 CPPUNIT_ASSERT_EQUAL(titleBefore, t->title());
148 CPPUNIT_ASSERT_EQUAL(String(), t->artist());
149 CPPUNIT_ASSERT_EQUAL(String(), t->album());
150 CPPUNIT_ASSERT_EQUAL(String(), t->comment());
151 CPPUNIT_ASSERT_EQUAL(String(), t->genre());
152 CPPUNIT_ASSERT_EQUAL(0U, t->year());
153 CPPUNIT_ASSERT_EQUAL(0U, t->track());
154 CPPUNIT_ASSERT_EQUAL(String(), t->trackerName());
155 }
156
157 void testWriteTagsShort()
158 {
159 testWriteTags(newCommentShort);
160 }
161
162 void testWriteTagsLong()
163 {
164 testWriteTags(newCommentLong);
165 }
166
167 private:
168 void testRead(FileName fileName, const String &title,
169 const String &comment, const String &trackerName)
170 {
171 XM::File file(fileName);
172
173 CPPUNIT_ASSERT(file.isValid());
174
175 XM::Properties *p = file.audioProperties();
176 Mod::Tag *t = file.tag();
177
178 CPPUNIT_ASSERT(nullptr != p);
179 CPPUNIT_ASSERT(nullptr != t);
180 assert(p != nullptr); // to silence the clang analyzer
181
182 CPPUNIT_ASSERT_EQUAL(0, p->lengthInSeconds());
183 CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
184 CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
185 CPPUNIT_ASSERT_EQUAL(8, p->channels());
186 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1), p->lengthInPatterns());
187 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(260), p->version());
188 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(0), p->restartPosition());
189 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1), p->patternCount());
190 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(128), p->instrumentCount());
191 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(1), p->flags());
192 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(6), p->tempo());
193 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned short>(125), p->bpmSpeed());
194 CPPUNIT_ASSERT_EQUAL(title, t->title());
195 CPPUNIT_ASSERT_EQUAL(String(), t->artist());
196 CPPUNIT_ASSERT_EQUAL(String(), t->album());
197 CPPUNIT_ASSERT_EQUAL(comment, t->comment());
198 CPPUNIT_ASSERT_EQUAL(String(), t->genre());
199 CPPUNIT_ASSERT_EQUAL(0U, t->year());
200 CPPUNIT_ASSERT_EQUAL(0U, t->track());
201 CPPUNIT_ASSERT_EQUAL(trackerName, t->trackerName());
202 }
203
204 void testWriteTags(const String &comment)
205 {
206 ScopedFileCopy copy("test", ".xm");
207 {
208 XM::File file(copy.fileName().c_str());
209 CPPUNIT_ASSERT(file.tag() != nullptr);
210 file.tag()->setTitle(titleAfter);
211 file.tag()->setComment(comment);
212 file.tag()->setTrackerName(trackerNameAfter);
213 CPPUNIT_ASSERT(file.save());
214 }
215 testRead(copy.fileName().c_str(), titleAfter,
216 commentAfter, trackerNameAfter);
217 CPPUNIT_ASSERT(fileEqual(
218 copy.fileName(),
219 testFilePath("changed.xm")));
220 }
221 };
222
223 CPPUNIT_TEST_SUITE_REGISTRATION(TestXM);