Debian Codegraph @

tests/test_ape.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 "tstringlist.h"
30 #include "tbytevectorlist.h"
31 #include "tpropertymap.h"
32 #include "apetag.h"
33 #include "id3v1tag.h"
34 #include "apefile.h"
35 #include <cppunit/extensions/HelperMacros.h>
36 #include "utils.h"
37
38 using namespace std;
39 using namespace TagLib;
40
41 class TestAPE : public CppUnit::TestFixture
42 {
43 CPPUNIT_TEST_SUITE(TestAPE);
44 CPPUNIT_TEST(testProperties399);
45 CPPUNIT_TEST(testProperties399Tagged);
46 CPPUNIT_TEST(testProperties399Id3v2);
47 CPPUNIT_TEST(testProperties396);
48 CPPUNIT_TEST(testProperties390);
49 CPPUNIT_TEST(testFuzzedFile1);
50 CPPUNIT_TEST(testFuzzedFile2);
51 CPPUNIT_TEST(testStripAndProperties);
52 CPPUNIT_TEST(testRepeatedSave);
53 CPPUNIT_TEST_SUITE_END();
54
55 public:
56
57 void testProperties399()
58 {
59 APE::File f(TEST_FILE_PATH_C("mac-399.ape"));
60 CPPUNIT_ASSERT(f.audioProperties());
61 CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
62 CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
63 CPPUNIT_ASSERT_EQUAL(192, f.audioProperties()->bitrate());
64 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
65 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
66 CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
67 CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
68 CPPUNIT_ASSERT_EQUAL(3990, f.audioProperties()->version());
69 }
70
71 void testProperties399Tagged()
72 {
73 APE::File f(TEST_FILE_PATH_C("mac-399-tagged.ape"));
74 CPPUNIT_ASSERT(f.audioProperties());
75 CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
76 CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
77 CPPUNIT_ASSERT_EQUAL(192, f.audioProperties()->bitrate());
78 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
79 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
80 CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
81 CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
82 CPPUNIT_ASSERT_EQUAL(3990, f.audioProperties()->version());
83 }
84
85 void testProperties399Id3v2()
86 {
87 APE::File f(TEST_FILE_PATH_C("mac-399-id3v2.ape"));
88 CPPUNIT_ASSERT(f.audioProperties());
89 CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
90 CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds());
91 CPPUNIT_ASSERT_EQUAL(192, f.audioProperties()->bitrate());
92 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
93 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
94 CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
95 CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
96 CPPUNIT_ASSERT_EQUAL(3990, f.audioProperties()->version());
97 }
98
99 void testProperties396()
100 {
101 APE::File f(TEST_FILE_PATH_C("mac-396.ape"));
102 CPPUNIT_ASSERT(f.audioProperties());
103 CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
104 CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds());
105 CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
106 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
107 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
108 CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
109 CPPUNIT_ASSERT_EQUAL(162496U, f.audioProperties()->sampleFrames());
110 CPPUNIT_ASSERT_EQUAL(3960, f.audioProperties()->version());
111 }
112
113 void testProperties390()
114 {
115 APE::File f(TEST_FILE_PATH_C("mac-390-hdr.ape"));
116 CPPUNIT_ASSERT(f.audioProperties());
117 CPPUNIT_ASSERT_EQUAL(15, f.audioProperties()->lengthInSeconds());
118 CPPUNIT_ASSERT_EQUAL(15630, f.audioProperties()->lengthInMilliseconds());
119 CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
120 CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
121 CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
122 CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
123 CPPUNIT_ASSERT_EQUAL(689262U, f.audioProperties()->sampleFrames());
124 CPPUNIT_ASSERT_EQUAL(3900, f.audioProperties()->version());
125 }
126
127 void testFuzzedFile1()
128 {
129 APE::File f(TEST_FILE_PATH_C("longloop.ape"));
130 CPPUNIT_ASSERT(f.isValid());
131 }
132
133 void testFuzzedFile2()
134 {
135 APE::File f(TEST_FILE_PATH_C("zerodiv.ape"));
136 CPPUNIT_ASSERT(f.isValid());
137 }
138
139 void testStripAndProperties()
140 {
141 ScopedFileCopy copy("mac-399", ".ape");
142
143 {
144 APE::File f(copy.fileName().c_str());
145 f.APETag(true)->setTitle("APE");
146 f.ID3v1Tag(true)->setTitle("ID3v1");
147 f.save();
148 }
149 {
150 APE::File f(copy.fileName().c_str());
151 CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
152 f.strip(APE::File::APE);
153 CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
154 f.strip(APE::File::ID3v1);
155 CPPUNIT_ASSERT(f.properties().isEmpty());
156 }
157 }
158
159 void testProperties()
160 {
161 PropertyMap tags;
162 tags["ALBUM"] = StringList("Album");
163 tags["ALBUMARTIST"] = StringList("Album Artist");
164 tags["ALBUMARTISTSORT"] = StringList("Album Artist Sort");
165 tags["ALBUMSORT"] = StringList("Album Sort");
166 tags["ARTIST"] = StringList("Artist");
167 tags["ARTISTS"] = StringList("Artists");
168 tags["ARTISTSORT"] = StringList("Artist Sort");
169 tags["ASIN"] = StringList("ASIN");
170 tags["BARCODE"] = StringList("Barcode");
171 tags["CATALOGNUMBER"] = StringList("Catalog Number 1").append("Catalog Number 2");
172 tags["COMMENT"] = StringList("Comment");
173 tags["DATE"] = StringList("2021-01-10");
174 tags["DISCNUMBER"] = StringList("3/5");
175 tags["GENRE"] = StringList("Genre");
176 tags["ISRC"] = StringList("UKAAA0500001");
177 tags["LABEL"] = StringList("Label 1").append("Label 2");
178 tags["MEDIA"] = StringList("Media");
179 tags["MUSICBRAINZ_ALBUMARTISTID"] = StringList("MusicBrainz_AlbumartistID");
180 tags["MUSICBRAINZ_ALBUMID"] = StringList("MusicBrainz_AlbumID");
181 tags["MUSICBRAINZ_ARTISTID"] = StringList("MusicBrainz_ArtistID");
182 tags["MUSICBRAINZ_RELEASEGROUPID"] = StringList("MusicBrainz_ReleasegroupID");
183 tags["MUSICBRAINZ_RELEASETRACKID"] = StringList("MusicBrainz_ReleasetrackID");
184 tags["MUSICBRAINZ_TRACKID"] = StringList("MusicBrainz_TrackID");
185 tags["ORIGINALDATE"] = StringList("2021-01-09");
186 tags["RELEASECOUNTRY"] = StringList("Release Country");
187 tags["RELEASESTATUS"] = StringList("Release Status");
188 tags["RELEASETYPE"] = StringList("Release Type");
189 tags["SCRIPT"] = StringList("Script");
190 tags["TITLE"] = StringList("Title");
191 tags["TRACKNUMBER"] = StringList("2/3");
192
193 ScopedFileCopy copy("mac-399", ".ape");
194 {
195 APE::File f(copy.fileName().c_str());
196 PropertyMap properties = f.properties();
197 CPPUNIT_ASSERT(properties.isEmpty());
198 f.setProperties(tags);
199 f.save();
200 }
201 {
202 const APE::File f(copy.fileName().c_str());
203 PropertyMap properties = f.properties();
204 if (tags != properties) {
205 CPPUNIT_ASSERT_EQUAL(tags.toString(), properties.toString());
206 }
207 CPPUNIT_ASSERT(tags == properties);
208 }
209 }
210
211 void testRepeatedSave()
212 {
213 ScopedFileCopy copy("mac-399", ".ape");
214
215 {
216 APE::File f(copy.fileName().c_str());
217 CPPUNIT_ASSERT(!f.hasAPETag());
218 CPPUNIT_ASSERT(!f.hasID3v1Tag());
219
220 f.APETag(true)->setTitle("01234 56789 ABCDE FGHIJ");
221 f.save();
222
223 f.APETag()->setTitle("0");
224 f.save();
225
226 f.ID3v1Tag(true)->setTitle("01234 56789 ABCDE FGHIJ");
227 f.APETag()->setTitle("01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789");
228 f.save();
229 }
230 {
231 APE::File f(copy.fileName().c_str());
232 CPPUNIT_ASSERT(f.hasAPETag());
233 CPPUNIT_ASSERT(f.hasID3v1Tag());
234 }
235 }
236
237 };
238
239 CPPUNIT_TEST_SUITE_REGISTRATION(TestAPE);