Debian Codegraph @

tests/test_wavpack.cpp

raw symbols SCIP
1 /***************************************************************************
2 copyright : (C) 2010 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 "tbytevectorlist.h"
30 #include "tpropertymap.h"
31 #include "apetag.h"
32 #include "id3v1tag.h"
33 #include "wavpackfile.h"
34 #include <cppunit/extensions/HelperMacros.h>
35 #include "utils.h"
36
37 using namespace std;
38 using namespace TagLib;
39
40 class TestWavPack : public CppUnit::TestFixture
41 {
42 CPPUNIT_TEST_SUITE(TestWavPack);
43 CPPUNIT_TEST(testNoLengthProperties);
44 CPPUNIT_TEST(testMultiChannelProperties);
45 CPPUNIT_TEST(testDsdStereoProperties);
46 CPPUNIT_TEST(testNonStandardRateProperties);
47 CPPUNIT_TEST(testTaggedProperties);
48 CPPUNIT_TEST(testFuzzedFile);
49 CPPUNIT_TEST(testStripAndProperties);
50 CPPUNIT_TEST(testRepeatedSave);
51 CPPUNIT_TEST_SUITE_END();
52
53 public:
54
55 void testNoLengthProperties()
56 {
57 WavPack::File f(TEST_FILE_PATH_C("no_length.wv"));
58 CPPUNIT_ASSERT(f.audioProperties());
59 CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
60 CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds());
61 CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->bitrate());
62 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
63 CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
64 CPPUNIT_ASSERT_EQUAL(true, f.audioProperties()->isLossless());
65 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
66 CPPUNIT_ASSERT_EQUAL(163392U, f.audioProperties()->sampleFrames());
67 CPPUNIT_ASSERT_EQUAL(1031, f.audioProperties()->version());
68 }
69
70 void testMultiChannelProperties()
71 {
72 WavPack::File f(TEST_FILE_PATH_C("four_channels.wv"));
73 CPPUNIT_ASSERT(f.audioProperties());
74 CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
75 CPPUNIT_ASSERT_EQUAL(3833, f.audioProperties()->lengthInMilliseconds());
76 CPPUNIT_ASSERT_EQUAL(112, f.audioProperties()->bitrate());
77 CPPUNIT_ASSERT_EQUAL(4, f.audioProperties()->channels());
78 CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
79 CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isLossless());
80 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
81 CPPUNIT_ASSERT_EQUAL(169031U, f.audioProperties()->sampleFrames());
82 CPPUNIT_ASSERT_EQUAL(1031, f.audioProperties()->version());
83 }
84
85 void testDsdStereoProperties()
86 {
87 WavPack::File f(TEST_FILE_PATH_C("dsd_stereo.wv"));
88 CPPUNIT_ASSERT(f.audioProperties());
89 CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
90 CPPUNIT_ASSERT_EQUAL(200, f.audioProperties()->lengthInMilliseconds());
91 CPPUNIT_ASSERT_EQUAL(2096, f.audioProperties()->bitrate());
92 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
93 CPPUNIT_ASSERT_EQUAL(8, f.audioProperties()->bitsPerSample());
94 CPPUNIT_ASSERT_EQUAL(true, f.audioProperties()->isLossless());
95 CPPUNIT_ASSERT_EQUAL(352800, f.audioProperties()->sampleRate());
96 CPPUNIT_ASSERT_EQUAL(70560U, f.audioProperties()->sampleFrames());
97 CPPUNIT_ASSERT_EQUAL(1040, f.audioProperties()->version());
98 }
99
100 void testNonStandardRateProperties()
101 {
102 WavPack::File f(TEST_FILE_PATH_C("non_standard_rate.wv"));
103 CPPUNIT_ASSERT(f.audioProperties());
104 CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
105 CPPUNIT_ASSERT_EQUAL(3675, f.audioProperties()->lengthInMilliseconds());
106 CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
107 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
108 CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
109 CPPUNIT_ASSERT_EQUAL(true, f.audioProperties()->isLossless());
110 CPPUNIT_ASSERT_EQUAL(1000, f.audioProperties()->sampleRate());
111 CPPUNIT_ASSERT_EQUAL(3675U, f.audioProperties()->sampleFrames());
112 CPPUNIT_ASSERT_EQUAL(1040, f.audioProperties()->version());
113 }
114
115 void testTaggedProperties()
116 {
117 WavPack::File f(TEST_FILE_PATH_C("tagged.wv"));
118 CPPUNIT_ASSERT(f.audioProperties());
119 CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
120 CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
121 CPPUNIT_ASSERT_EQUAL(172, f.audioProperties()->bitrate());
122 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
123 CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
124 CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isLossless());
125 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
126 CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
127 CPPUNIT_ASSERT_EQUAL(1031, f.audioProperties()->version());
128 }
129
130 void testFuzzedFile()
131 {
132 WavPack::File f(TEST_FILE_PATH_C("infloop.wv"));
133 CPPUNIT_ASSERT(f.isValid());
134 }
135
136 void testStripAndProperties()
137 {
138 ScopedFileCopy copy("click", ".wv");
139
140 {
141 WavPack::File f(copy.fileName().c_str());
142 f.APETag(true)->setTitle("APE");
143 f.ID3v1Tag(true)->setTitle("ID3v1");
144 f.save();
145 }
146 {
147 WavPack::File f(copy.fileName().c_str());
148 CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
149 f.strip(WavPack::File::APE);
150 CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
151 f.strip(WavPack::File::ID3v1);
152 CPPUNIT_ASSERT(f.properties().isEmpty());
153 }
154 }
155
156 void testRepeatedSave()
157 {
158 ScopedFileCopy copy("click", ".wv");
159
160 {
161 WavPack::File f(copy.fileName().c_str());
162 CPPUNIT_ASSERT(!f.hasAPETag());
163 CPPUNIT_ASSERT(!f.hasID3v1Tag());
164
165 f.APETag(true)->setTitle("01234 56789 ABCDE FGHIJ");
166 f.save();
167
168 f.APETag()->setTitle("0");
169 f.save();
170
171 f.ID3v1Tag(true)->setTitle("01234 56789 ABCDE FGHIJ");
172 f.APETag()->setTitle("01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789");
173 f.save();
174 }
175 {
176 WavPack::File f(copy.fileName().c_str());
177 CPPUNIT_ASSERT(f.hasAPETag());
178 CPPUNIT_ASSERT(f.hasID3v1Tag());
179 }
180 }
181
182 };
183
184 CPPUNIT_TEST_SUITE_REGISTRATION(TestWavPack);