Debian Codegraph @

tests/test_mpc.cpp

raw symbols SCIP
1 /***************************************************************************
2 copyright : (C) 2012 by Lukas Lalinsky
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 <string>
27 #include <cstdio>
28
29 #include "tstringlist.h"
30 #include "tbytevectorlist.h"
31 #include "tpropertymap.h"
32 #include "apetag.h"
33 #include "id3v1tag.h"
34 #include "mpcfile.h"
35 #include <cppunit/extensions/HelperMacros.h>
36 #include "utils.h"
37
38 using namespace std;
39 using namespace TagLib;
40
41 class TestMPC : public CppUnit::TestFixture
42 {
43 CPPUNIT_TEST_SUITE(TestMPC);
44 CPPUNIT_TEST(testPropertiesSV8);
45 CPPUNIT_TEST(testPropertiesSV7);
46 CPPUNIT_TEST(testPropertiesSV5);
47 CPPUNIT_TEST(testPropertiesSV4);
48 CPPUNIT_TEST(testFuzzedFile1);
49 CPPUNIT_TEST(testFuzzedFile2);
50 CPPUNIT_TEST(testFuzzedFile3);
51 CPPUNIT_TEST(testFuzzedFile4);
52 CPPUNIT_TEST(testStripAndProperties);
53 CPPUNIT_TEST(testRepeatedSave);
54 CPPUNIT_TEST_SUITE_END();
55
56 public:
57
58 void testPropertiesSV8()
59 {
60 MPC::File f(TEST_FILE_PATH_C("sv8_header.mpc"));
61 CPPUNIT_ASSERT(f.audioProperties());
62 CPPUNIT_ASSERT_EQUAL(8, f.audioProperties()->mpcVersion());
63 CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->lengthInSeconds());
64 CPPUNIT_ASSERT_EQUAL(1497, f.audioProperties()->lengthInMilliseconds());
65 CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->bitrate());
66 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
67 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
68 CPPUNIT_ASSERT_EQUAL(66014UL, f.audioProperties()->sampleFrames());
69 }
70
71 void testPropertiesSV7()
72 {
73 MPC::File f(TEST_FILE_PATH_C("click.mpc"));
74 CPPUNIT_ASSERT(f.audioProperties());
75 CPPUNIT_ASSERT_EQUAL(7, f.audioProperties()->mpcVersion());
76 CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
77 CPPUNIT_ASSERT_EQUAL(40, f.audioProperties()->lengthInMilliseconds());
78 CPPUNIT_ASSERT_EQUAL(318, f.audioProperties()->bitrate());
79 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
80 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
81 CPPUNIT_ASSERT_EQUAL(1760UL, f.audioProperties()->sampleFrames());
82 CPPUNIT_ASSERT_EQUAL(14221, f.audioProperties()->trackGain());
83 CPPUNIT_ASSERT_EQUAL(19848, f.audioProperties()->trackPeak());
84 CPPUNIT_ASSERT_EQUAL(14221, f.audioProperties()->albumGain());
85 CPPUNIT_ASSERT_EQUAL(19848, f.audioProperties()->albumPeak());
86 }
87
88 void testPropertiesSV5()
89 {
90 MPC::File f(TEST_FILE_PATH_C("sv5_header.mpc"));
91 CPPUNIT_ASSERT(f.audioProperties());
92 CPPUNIT_ASSERT_EQUAL(5, f.audioProperties()->mpcVersion());
93 CPPUNIT_ASSERT_EQUAL(26, f.audioProperties()->lengthInSeconds());
94 CPPUNIT_ASSERT_EQUAL(26371, f.audioProperties()->lengthInMilliseconds());
95 CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
96 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
97 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
98 CPPUNIT_ASSERT_EQUAL(1162944UL, f.audioProperties()->sampleFrames());
99 }
100
101 void testPropertiesSV4()
102 {
103 MPC::File f(TEST_FILE_PATH_C("sv4_header.mpc"));
104 CPPUNIT_ASSERT(f.audioProperties());
105 CPPUNIT_ASSERT_EQUAL(4, f.audioProperties()->mpcVersion());
106 CPPUNIT_ASSERT_EQUAL(26, f.audioProperties()->lengthInSeconds());
107 CPPUNIT_ASSERT_EQUAL(26371, f.audioProperties()->lengthInMilliseconds());
108 CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
109 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
110 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
111 CPPUNIT_ASSERT_EQUAL(1162944UL, f.audioProperties()->sampleFrames());
112 }
113
114 void testFuzzedFile1()
115 {
116 MPC::File f(TEST_FILE_PATH_C("zerodiv.mpc"));
117 CPPUNIT_ASSERT(f.isValid());
118 }
119
120 void testFuzzedFile2()
121 {
122 MPC::File f(TEST_FILE_PATH_C("infloop.mpc"));
123 CPPUNIT_ASSERT(f.isValid());
124 }
125
126 void testFuzzedFile3()
127 {
128 MPC::File f(TEST_FILE_PATH_C("segfault.mpc"));
129 CPPUNIT_ASSERT(f.isValid());
130 }
131
132 void testFuzzedFile4()
133 {
134 MPC::File f(TEST_FILE_PATH_C("segfault2.mpc"));
135 CPPUNIT_ASSERT(f.isValid());
136 }
137
138 void testStripAndProperties()
139 {
140 ScopedFileCopy copy("click", ".mpc");
141
142 {
143 MPC::File f(copy.fileName().c_str());
144 f.APETag(true)->setTitle("APE");
145 f.ID3v1Tag(true)->setTitle("ID3v1");
146 f.save();
147 }
148 {
149 MPC::File f(copy.fileName().c_str());
150 CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
151 f.strip(MPC::File::APE);
152 CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
153 f.strip(MPC::File::ID3v1);
154 CPPUNIT_ASSERT(f.properties().isEmpty());
155 f.save();
156 }
157 {
158 MPC::File f(copy.fileName().c_str());
159 CPPUNIT_ASSERT(!f.hasAPETag());
160 CPPUNIT_ASSERT(!f.hasID3v1Tag());
161 CPPUNIT_ASSERT(f.properties()["TITLE"].isEmpty());
162 CPPUNIT_ASSERT(f.properties().isEmpty());
163 }
164 }
165
166 void testRepeatedSave()
167 {
168 ScopedFileCopy copy("click", ".mpc");
169
170 {
171 MPC::File f(copy.fileName().c_str());
172 CPPUNIT_ASSERT(!f.hasAPETag());
173 CPPUNIT_ASSERT(!f.hasID3v1Tag());
174
175 f.APETag(true)->setTitle("01234 56789 ABCDE FGHIJ");
176 f.save();
177
178 f.APETag()->setTitle("0");
179 f.save();
180
181 f.ID3v1Tag(true)->setTitle("01234 56789 ABCDE FGHIJ");
182 f.APETag()->setTitle("01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789");
183 f.save();
184 }
185 {
186 MPC::File f(copy.fileName().c_str());
187 CPPUNIT_ASSERT(f.hasAPETag());
188 CPPUNIT_ASSERT(f.hasID3v1Tag());
189 }
190 }
191
192 };
193
194 CPPUNIT_TEST_SUITE_REGISTRATION(TestMPC);