| 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 "id3v2tag.h" |
| 30 | #include "infotag.h" |
| 31 | #include "tbytevectorlist.h" |
| 32 | #include "tbytevectorstream.h" |
| 33 | #include "tfilestream.h" |
| 34 | #include "tpropertymap.h" |
| 35 | #include "wavfile.h" |
| 36 | #include "plainfile.h" |
| 37 | #include <cppunit/extensions/HelperMacros.h> |
| 38 | #include "utils.h" |
| 39 | |
| 40 | using namespace std; |
| 41 | using namespace TagLib; |
| 42 | |
| 43 | class TestWAV : public CppUnit::TestFixture |
| 44 | { |
| 45 | CPPUNIT_TEST_SUITE(TestWAV); |
| 46 | CPPUNIT_TEST(testPCMProperties); |
| 47 | CPPUNIT_TEST(testALAWProperties); |
| 48 | CPPUNIT_TEST(testFloatProperties); |
| 49 | CPPUNIT_TEST(testFloatWithoutFactChunkProperties); |
| 50 | CPPUNIT_TEST(testZeroSizeDataChunk); |
| 51 | CPPUNIT_TEST(testID3v2Tag); |
| 52 | CPPUNIT_TEST(testSaveID3v23); |
| 53 | CPPUNIT_TEST(testInfoTag); |
| 54 | CPPUNIT_TEST(testStripTags); |
| 55 | CPPUNIT_TEST(testDuplicateTags); |
| 56 | CPPUNIT_TEST(testFuzzedFile1); |
| 57 | CPPUNIT_TEST(testFuzzedFile2); |
| 58 | CPPUNIT_TEST(testFileWithGarbageAppended); |
| 59 | CPPUNIT_TEST(testStripAndProperties); |
| 60 | CPPUNIT_TEST(testPCMWithFactChunk); |
| 61 | CPPUNIT_TEST(testWaveFormatExtensible); |
| 62 | CPPUNIT_TEST(testInvalidChunk); |
| 63 | CPPUNIT_TEST(testRIFFInfoProperties); |
| 64 | CPPUNIT_TEST(testBEXTTag); |
| 65 | CPPUNIT_TEST(testBEXTTagWithOtherTags); |
| 66 | CPPUNIT_TEST(testiXMLTag); |
| 67 | CPPUNIT_TEST(testiXMLTagWithOtherTags); |
| 68 | CPPUNIT_TEST_SUITE_END(); |
| 69 | |
| 70 | public: |
| 71 | |
| 72 | void testPCMProperties() |
| 73 | { |
| 74 | RIFF::WAV::File f(TEST_FILE_PATH_C("empty.wav")); |
| 75 | CPPUNIT_ASSERT(f.audioProperties()); |
| 76 | CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds()); |
| 77 | CPPUNIT_ASSERT_EQUAL(3675, f.audioProperties()->lengthInMilliseconds()); |
| 78 | CPPUNIT_ASSERT_EQUAL(32, f.audioProperties()->bitrate()); |
| 79 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels()); |
| 80 | CPPUNIT_ASSERT_EQUAL(1000, f.audioProperties()->sampleRate()); |
| 81 | CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample()); |
| 82 | CPPUNIT_ASSERT_EQUAL(3675U, f.audioProperties()->sampleFrames()); |
| 83 | CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->format()); |
| 84 | } |
| 85 | |
| 86 | void testALAWProperties() |
| 87 | { |
| 88 | RIFF::WAV::File f(TEST_FILE_PATH_C("alaw.wav")); |
| 89 | CPPUNIT_ASSERT(f.audioProperties()); |
| 90 | CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds()); |
| 91 | CPPUNIT_ASSERT_EQUAL(3550, f.audioProperties()->lengthInMilliseconds()); |
| 92 | CPPUNIT_ASSERT_EQUAL(128, f.audioProperties()->bitrate()); |
| 93 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels()); |
| 94 | CPPUNIT_ASSERT_EQUAL(8000, f.audioProperties()->sampleRate()); |
| 95 | CPPUNIT_ASSERT_EQUAL(8, f.audioProperties()->bitsPerSample()); |
| 96 | CPPUNIT_ASSERT_EQUAL(28400U, f.audioProperties()->sampleFrames()); |
| 97 | CPPUNIT_ASSERT_EQUAL(6, f.audioProperties()->format()); |
| 98 | } |
| 99 | |
| 100 | void testFloatProperties() |
| 101 | { |
| 102 | RIFF::WAV::File f(TEST_FILE_PATH_C("float64.wav")); |
| 103 | CPPUNIT_ASSERT(f.audioProperties()); |
| 104 | CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds()); |
| 105 | CPPUNIT_ASSERT_EQUAL(97, f.audioProperties()->lengthInMilliseconds()); |
| 106 | CPPUNIT_ASSERT_EQUAL(5645, f.audioProperties()->bitrate()); |
| 107 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels()); |
| 108 | CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate()); |
| 109 | CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitsPerSample()); |
| 110 | CPPUNIT_ASSERT_EQUAL(4281U, f.audioProperties()->sampleFrames()); |
| 111 | CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->format()); |
| 112 | } |
| 113 | |
| 114 | void testFloatWithoutFactChunkProperties() |
| 115 | { |
| 116 | ByteVector wavData = PlainFile(TEST_FILE_PATH_C("float64.wav")).readAll(); |
| 117 | CPPUNIT_ASSERT_EQUAL(ByteVector("fact"), wavData.mid(36, 4)); |
| 118 | // Remove the fact chunk by renaming it to fakt |
| 119 | wavData[38] = 'k'; |
| 120 | ByteVectorStream wavStream(wavData); |
| 121 | RIFF::WAV::File f(&wavStream); |
| 122 | CPPUNIT_ASSERT(f.audioProperties()); |
| 123 | CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds()); |
| 124 | CPPUNIT_ASSERT_EQUAL(97, f.audioProperties()->lengthInMilliseconds()); |
| 125 | CPPUNIT_ASSERT_EQUAL(5645, f.audioProperties()->bitrate()); |
| 126 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels()); |
| 127 | CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate()); |
| 128 | CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitsPerSample()); |
| 129 | CPPUNIT_ASSERT_EQUAL(4281U, f.audioProperties()->sampleFrames()); |
| 130 | CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->format()); |
| 131 | } |
| 132 | |
| 133 | void testZeroSizeDataChunk() |
| 134 | { |
| 135 | RIFF::WAV::File f(TEST_FILE_PATH_C("zero-size-chunk.wav")); |
| 136 | CPPUNIT_ASSERT(f.isValid()); |
| 137 | } |
| 138 | |
| 139 | void testID3v2Tag() |
| 140 | { |
| 141 | ScopedFileCopy copy("empty", ".wav"); |
| 142 | string filename = copy.fileName(); |
| 143 | |
| 144 | { |
| 145 | RIFF::WAV::File f(filename.c_str()); |
| 146 | CPPUNIT_ASSERT(f.isValid()); |
| 147 | CPPUNIT_ASSERT(!f.hasID3v2Tag()); |
| 148 | |
| 149 | f.ID3v2Tag()->setTitle(L"Title"); |
| 150 | f.ID3v2Tag()->setArtist(L"Artist"); |
| 151 | f.save(); |
| 152 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 153 | } |
| 154 | { |
| 155 | RIFF::WAV::File f(filename.c_str()); |
| 156 | CPPUNIT_ASSERT(f.isValid()); |
| 157 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 158 | CPPUNIT_ASSERT_EQUAL(String(L"Title"), f.ID3v2Tag()->title()); |
| 159 | CPPUNIT_ASSERT_EQUAL(String(L"Artist"), f.ID3v2Tag()->artist()); |
| 160 | |
| 161 | f.ID3v2Tag()->setTitle(L""); |
| 162 | f.ID3v2Tag()->setArtist(L""); |
| 163 | f.save(); |
| 164 | CPPUNIT_ASSERT(!f.hasID3v2Tag()); |
| 165 | } |
| 166 | { |
| 167 | RIFF::WAV::File f(filename.c_str()); |
| 168 | CPPUNIT_ASSERT(f.isValid()); |
| 169 | CPPUNIT_ASSERT(!f.hasID3v2Tag()); |
| 170 | CPPUNIT_ASSERT_EQUAL(String(L""), f.ID3v2Tag()->title()); |
| 171 | CPPUNIT_ASSERT_EQUAL(String(L""), f.ID3v2Tag()->artist()); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | void testSaveID3v23() |
| 176 | { |
| 177 | ScopedFileCopy copy("empty", ".wav"); |
| 178 | string newname = copy.fileName(); |
| 179 | |
| 180 | String xxx = ByteVector(254, 'X'); |
| 181 | { |
| 182 | RIFF::WAV::File f(newname.c_str()); |
| 183 | CPPUNIT_ASSERT_EQUAL(false, f.hasID3v2Tag()); |
| 184 | |
| 185 | f.tag()->setTitle(xxx); |
| 186 | f.tag()->setArtist("Artist A"); |
| 187 | f.save(RIFF::WAV::File::AllTags, File::StripOthers, ID3v2::v3); |
| 188 | CPPUNIT_ASSERT_EQUAL(true, f.hasID3v2Tag()); |
| 189 | } |
| 190 | { |
| 191 | RIFF::WAV::File f2(newname.c_str()); |
| 192 | CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), f2.ID3v2Tag()->header()->majorVersion()); |
| 193 | CPPUNIT_ASSERT_EQUAL(String("Artist A"), f2.tag()->artist()); |
| 194 | CPPUNIT_ASSERT_EQUAL(xxx, f2.tag()->title()); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | void testInfoTag() |
| 199 | { |
| 200 | ScopedFileCopy copy("empty", ".wav"); |
| 201 | string filename = copy.fileName(); |
| 202 | |
| 203 | { |
| 204 | RIFF::WAV::File f(filename.c_str()); |
| 205 | CPPUNIT_ASSERT(f.isValid()); |
| 206 | CPPUNIT_ASSERT(!f.hasInfoTag()); |
| 207 | |
| 208 | f.InfoTag()->setTitle(L"Title"); |
| 209 | f.InfoTag()->setArtist(L"Artist"); |
| 210 | f.save(); |
| 211 | CPPUNIT_ASSERT(f.hasInfoTag()); |
| 212 | } |
| 213 | { |
| 214 | RIFF::WAV::File f(filename.c_str()); |
| 215 | CPPUNIT_ASSERT(f.isValid()); |
| 216 | CPPUNIT_ASSERT(f.hasInfoTag()); |
| 217 | CPPUNIT_ASSERT_EQUAL(String(L"Title"), f.InfoTag()->title()); |
| 218 | CPPUNIT_ASSERT_EQUAL(String(L"Artist"), f.InfoTag()->artist()); |
| 219 | |
| 220 | f.InfoTag()->setTitle(L""); |
| 221 | f.InfoTag()->setArtist(L""); |
| 222 | f.save(); |
| 223 | CPPUNIT_ASSERT(!f.hasInfoTag()); |
| 224 | } |
| 225 | |
| 226 | { |
| 227 | RIFF::WAV::File f(filename.c_str()); |
| 228 | CPPUNIT_ASSERT(f.isValid()); |
| 229 | CPPUNIT_ASSERT(!f.hasInfoTag()); |
| 230 | CPPUNIT_ASSERT_EQUAL(String(L""), f.InfoTag()->title()); |
| 231 | CPPUNIT_ASSERT_EQUAL(String(L""), f.InfoTag()->artist()); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | void testStripTags() |
| 236 | { |
| 237 | ScopedFileCopy copy("empty", ".wav"); |
| 238 | string filename = copy.fileName(); |
| 239 | |
| 240 | { |
| 241 | RIFF::WAV::File f(filename.c_str()); |
| 242 | f.ID3v2Tag()->setTitle("test title"); |
| 243 | f.InfoTag()->setTitle("test title"); |
| 244 | f.save(); |
| 245 | } |
| 246 | { |
| 247 | RIFF::WAV::File f(filename.c_str()); |
| 248 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 249 | CPPUNIT_ASSERT(f.hasInfoTag()); |
| 250 | f.save(RIFF::WAV::File::ID3v2, File::StripOthers); |
| 251 | } |
| 252 | { |
| 253 | RIFF::WAV::File f(filename.c_str()); |
| 254 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 255 | CPPUNIT_ASSERT(!f.hasInfoTag()); |
| 256 | f.ID3v2Tag()->setTitle("test title"); |
| 257 | f.InfoTag()->setTitle("test title"); |
| 258 | f.save(); |
| 259 | } |
| 260 | { |
| 261 | RIFF::WAV::File f(filename.c_str()); |
| 262 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 263 | CPPUNIT_ASSERT(f.hasInfoTag()); |
| 264 | f.save(RIFF::WAV::File::Info, File::StripOthers); |
| 265 | } |
| 266 | { |
| 267 | RIFF::WAV::File f(filename.c_str()); |
| 268 | CPPUNIT_ASSERT(!f.hasID3v2Tag()); |
| 269 | CPPUNIT_ASSERT(f.hasInfoTag()); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | void testDuplicateTags() |
| 274 | { |
| 275 | ScopedFileCopy copy("duplicate_tags", ".wav"); |
| 276 | |
| 277 | RIFF::WAV::File f(copy.fileName().c_str()); |
| 278 | CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(17052), f.length()); |
| 279 | |
| 280 | // duplicate_tags.wav has duplicate ID3v2/INFO tags. |
| 281 | // title() returns "Title2" if can't skip the second tag. |
| 282 | |
| 283 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 284 | CPPUNIT_ASSERT_EQUAL(String("Title1"), f.ID3v2Tag()->title()); |
| 285 | |
| 286 | CPPUNIT_ASSERT(f.hasInfoTag()); |
| 287 | CPPUNIT_ASSERT_EQUAL(String("Title1"), f.InfoTag()->title()); |
| 288 | |
| 289 | f.save(); |
| 290 | CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(15898), f.length()); |
| 291 | CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(-1), f.find("Title2")); |
| 292 | } |
| 293 | |
| 294 | void testFuzzedFile1() |
| 295 | { |
| 296 | RIFF::WAV::File f1(TEST_FILE_PATH_C("infloop.wav")); |
| 297 | CPPUNIT_ASSERT(f1.isValid()); |
| 298 | // The file has problems: |
| 299 | // Chunk 'ISTt' has invalid size (larger than the file size). |
| 300 | // Its properties can nevertheless be read. |
| 301 | RIFF::WAV::Properties* properties = f1.audioProperties(); |
| 302 | CPPUNIT_ASSERT_EQUAL(1, properties->channels()); |
| 303 | CPPUNIT_ASSERT_EQUAL(88, properties->bitrate()); |
| 304 | CPPUNIT_ASSERT_EQUAL(8, properties->bitsPerSample()); |
| 305 | CPPUNIT_ASSERT_EQUAL(11025, properties->sampleRate()); |
| 306 | CPPUNIT_ASSERT(!f1.hasInfoTag()); |
| 307 | CPPUNIT_ASSERT(!f1.hasID3v2Tag()); |
| 308 | } |
| 309 | |
| 310 | void testFuzzedFile2() |
| 311 | { |
| 312 | RIFF::WAV::File f2(TEST_FILE_PATH_C("segfault.wav")); |
| 313 | CPPUNIT_ASSERT(f2.isValid()); |
| 314 | } |
| 315 | |
| 316 | void testFileWithGarbageAppended() |
| 317 | { |
| 318 | ScopedFileCopy copy("empty", ".wav"); |
| 319 | ByteVector contentsBeforeModification; |
| 320 | { |
| 321 | FileStream stream(copy.fileName().c_str()); |
| 322 | stream.seek(0, IOStream::End); |
| 323 | constexpr char garbage[] = "\r2345678"; |
| 324 | stream.writeBlock(ByteVector(garbage, sizeof(garbage) - 1)); |
| 325 | stream.seek(0); |
| 326 | contentsBeforeModification = stream.readBlock(stream.length()); |
| 327 | } |
| 328 | { |
| 329 | RIFF::WAV::File f(copy.fileName().c_str()); |
| 330 | CPPUNIT_ASSERT(f.isValid()); |
| 331 | f.ID3v2Tag()->setTitle("ID3v2 Title"); |
| 332 | f.InfoTag()->setTitle("INFO Title"); |
| 333 | CPPUNIT_ASSERT(f.save()); |
| 334 | } |
| 335 | { |
| 336 | RIFF::WAV::File f(copy.fileName().c_str()); |
| 337 | f.strip(); |
| 338 | } |
| 339 | { |
| 340 | FileStream stream(copy.fileName().c_str()); |
| 341 | ByteVector contentsAfterModification = stream.readBlock(stream.length()); |
| 342 | CPPUNIT_ASSERT_EQUAL(contentsBeforeModification, contentsAfterModification); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | void testStripAndProperties() |
| 347 | { |
| 348 | ScopedFileCopy copy("empty", ".wav"); |
| 349 | |
| 350 | { |
| 351 | RIFF::WAV::File f(copy.fileName().c_str()); |
| 352 | f.ID3v2Tag()->setTitle("ID3v2"); |
| 353 | f.InfoTag()->setTitle("INFO"); |
| 354 | f.save(); |
| 355 | } |
| 356 | { |
| 357 | RIFF::WAV::File f(copy.fileName().c_str()); |
| 358 | CPPUNIT_ASSERT_EQUAL(String("ID3v2"), f.properties()["TITLE"].front()); |
| 359 | f.strip(RIFF::WAV::File::ID3v2); |
| 360 | CPPUNIT_ASSERT_EQUAL(String("INFO"), f.properties()["TITLE"].front()); |
| 361 | f.strip(RIFF::WAV::File::Info); |
| 362 | CPPUNIT_ASSERT(f.properties().isEmpty()); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | void testPCMWithFactChunk() |
| 367 | { |
| 368 | RIFF::WAV::File f(TEST_FILE_PATH_C("pcm_with_fact_chunk.wav")); |
| 369 | CPPUNIT_ASSERT(f.audioProperties()); |
| 370 | CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds()); |
| 371 | CPPUNIT_ASSERT_EQUAL(3675, f.audioProperties()->lengthInMilliseconds()); |
| 372 | CPPUNIT_ASSERT_EQUAL(32, f.audioProperties()->bitrate()); |
| 373 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels()); |
| 374 | CPPUNIT_ASSERT_EQUAL(1000, f.audioProperties()->sampleRate()); |
| 375 | CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample()); |
| 376 | CPPUNIT_ASSERT_EQUAL(3675U, f.audioProperties()->sampleFrames()); |
| 377 | CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->format()); |
| 378 | } |
| 379 | |
| 380 | void testWaveFormatExtensible() |
| 381 | { |
| 382 | RIFF::WAV::File f(TEST_FILE_PATH_C("uint8we.wav")); |
| 383 | CPPUNIT_ASSERT(f.audioProperties()); |
| 384 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->lengthInSeconds()); |
| 385 | CPPUNIT_ASSERT_EQUAL(2937, f.audioProperties()->lengthInMilliseconds()); |
| 386 | CPPUNIT_ASSERT_EQUAL(128, f.audioProperties()->bitrate()); |
| 387 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels()); |
| 388 | CPPUNIT_ASSERT_EQUAL(8000, f.audioProperties()->sampleRate()); |
| 389 | CPPUNIT_ASSERT_EQUAL(8, f.audioProperties()->bitsPerSample()); |
| 390 | CPPUNIT_ASSERT_EQUAL(23493U, f.audioProperties()->sampleFrames()); |
| 391 | CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->format()); |
| 392 | } |
| 393 | |
| 394 | void testInvalidChunk() |
| 395 | { |
| 396 | ScopedFileCopy copy("invalid-chunk", ".wav"); |
| 397 | |
| 398 | { |
| 399 | RIFF::WAV::File f(copy.fileName().c_str()); |
| 400 | CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds()); |
| 401 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 402 | f.ID3v2Tag()->setTitle("Title"); |
| 403 | f.save(); |
| 404 | } |
| 405 | { |
| 406 | RIFF::WAV::File f(copy.fileName().c_str()); |
| 407 | CPPUNIT_ASSERT(!f.hasID3v2Tag()); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | void testRIFFInfoProperties() |
| 412 | { |
| 413 | PropertyMap tags; |
| 414 | tags["ALBUM"] = StringList("Album"); |
| 415 | tags["ARRANGER"] = StringList("Arranger"); |
| 416 | tags["ARTIST"] = StringList("Artist"); |
| 417 | tags["ARTISTWEBPAGE"] = StringList("Artist Webpage"); |
| 418 | tags["BPM"] = StringList("123"); |
| 419 | tags["COMMENT"] = StringList("Comment"); |
| 420 | tags["COMPOSER"] = StringList("Composer"); |
| 421 | tags["COPYRIGHT"] = StringList("2023 Copyright"); |
| 422 | tags["DATE"] = StringList("2023"); |
| 423 | tags["DISCSUBTITLE"] = StringList("Disc Subtitle"); |
| 424 | tags["ENCODEDBY"] = StringList("Encoded by"); |
| 425 | tags["ENCODING"] = StringList("Encoding"); |
| 426 | tags["ENCODINGTIME"] = StringList("2023-11-25 15:42:39"); |
| 427 | tags["GENRE"] = StringList("Genre"); |
| 428 | tags["ISRC"] = StringList("UKAAA0500001"); |
| 429 | tags["LABEL"] = StringList("Label"); |
| 430 | tags["LANGUAGE"] = StringList("eng"); |
| 431 | tags["LYRICIST"] = StringList("Lyricist"); |
| 432 | tags["MEDIA"] = StringList("Media"); |
| 433 | tags["PERFORMER"] = StringList("Performer"); |
| 434 | tags["RELEASECOUNTRY"] = StringList("Release Country"); |
| 435 | tags["REMIXER"] = StringList("Remixer"); |
| 436 | tags["TITLE"] = StringList("Title"); |
| 437 | tags["TRACKNUMBER"] = StringList("2/4"); |
| 438 | |
| 439 | ScopedFileCopy copy("empty", ".wav"); |
| 440 | { |
| 441 | RIFF::WAV::File f(copy.fileName().c_str()); |
| 442 | RIFF::Info::Tag *infoTag = f.InfoTag(); |
| 443 | CPPUNIT_ASSERT(infoTag->isEmpty()); |
| 444 | PropertyMap properties = infoTag->properties(); |
| 445 | CPPUNIT_ASSERT(properties.isEmpty()); |
| 446 | infoTag->setProperties(tags); |
| 447 | f.save(); |
| 448 | } |
| 449 | { |
| 450 | const RIFF::WAV::File f(copy.fileName().c_str()); |
| 451 | RIFF::Info::Tag *infoTag = f.InfoTag(); |
| 452 | CPPUNIT_ASSERT(!infoTag->isEmpty()); |
| 453 | PropertyMap properties = infoTag->properties(); |
| 454 | if (tags != properties) { |
| 455 | CPPUNIT_ASSERT_EQUAL(tags.toString(), properties.toString()); |
| 456 | } |
| 457 | CPPUNIT_ASSERT(tags == properties); |
| 458 | |
| 459 | const RIFF::Info::FieldListMap expectedFields = { |
| 460 | {"IPRD", "Album"}, |
| 461 | {"IENG", "Arranger"}, |
| 462 | {"IART", "Artist"}, |
| 463 | {"IBSU", "Artist Webpage"}, |
| 464 | {"IBPM", "123"}, |
| 465 | {"ICMT", "Comment"}, |
| 466 | {"IMUS", "Composer"}, |
| 467 | {"ICOP", "2023 Copyright"}, |
| 468 | {"ICRD", "2023"}, |
| 469 | {"PRT1", "Disc Subtitle"}, |
| 470 | {"ITCH", "Encoded by"}, |
| 471 | {"ISFT", "Encoding"}, |
| 472 | {"IDIT", "2023-11-25 15:42:39"}, |
| 473 | {"IGNR", "Genre"}, |
| 474 | {"ISRC", "UKAAA0500001"}, |
| 475 | {"IPUB", "Label"}, |
| 476 | {"ILNG", "eng"}, |
| 477 | {"IWRI", "Lyricist"}, |
| 478 | {"IMED", "Media"}, |
| 479 | {"ISTR", "Performer"}, |
| 480 | {"ICNT", "Release Country"}, |
| 481 | {"IEDT", "Remixer"}, |
| 482 | {"INAM", "Title"}, |
| 483 | {"IPRT", "2/4"} |
| 484 | }; |
| 485 | CPPUNIT_ASSERT(expectedFields == infoTag->fieldListMap()); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | void testBEXTTag() |
| 490 | { |
| 491 | ScopedFileCopy copy("empty", ".wav"); |
| 492 | string filename = copy.fileName(); |
| 493 | |
| 494 | { |
| 495 | RIFF::WAV::File f(filename.c_str()); |
| 496 | CPPUNIT_ASSERT(f.isValid()); |
| 497 | CPPUNIT_ASSERT(!f.hasBEXTData()); |
| 498 | CPPUNIT_ASSERT(f.BEXTData().isEmpty()); |
| 499 | |
| 500 | f.setBEXTData(ByteVector("test bext data")); |
| 501 | f.save(); |
| 502 | CPPUNIT_ASSERT(f.hasBEXTData()); |
| 503 | } |
| 504 | { |
| 505 | RIFF::WAV::File f(filename.c_str()); |
| 506 | CPPUNIT_ASSERT(f.isValid()); |
| 507 | CPPUNIT_ASSERT(f.hasBEXTData()); |
| 508 | CPPUNIT_ASSERT_EQUAL(ByteVector("test bext data"), f.BEXTData()); |
| 509 | |
| 510 | f.setBEXTData(ByteVector()); |
| 511 | f.save(); |
| 512 | CPPUNIT_ASSERT(!f.hasBEXTData()); |
| 513 | } |
| 514 | { |
| 515 | RIFF::WAV::File f(filename.c_str()); |
| 516 | CPPUNIT_ASSERT(f.isValid()); |
| 517 | CPPUNIT_ASSERT(!f.hasBEXTData()); |
| 518 | CPPUNIT_ASSERT(f.BEXTData().isEmpty()); |
| 519 | } |
| 520 | |
| 521 | // Check if file without BEXT is same as original empty file |
| 522 | const ByteVector origData = PlainFile(TEST_FILE_PATH_C("empty.wav")).readAll(); |
| 523 | const ByteVector fileData = PlainFile(filename.c_str()).readAll(); |
| 524 | CPPUNIT_ASSERT(origData == fileData); |
| 525 | } |
| 526 | |
| 527 | void testBEXTTagWithOtherTags() |
| 528 | { |
| 529 | ScopedFileCopy copy("empty", ".wav"); |
| 530 | string filename = copy.fileName(); |
| 531 | |
| 532 | { |
| 533 | RIFF::WAV::File f(filename.c_str()); |
| 534 | f.ID3v2Tag()->setTitle("ID3v2 Title"); |
| 535 | f.InfoTag()->setTitle("INFO Title"); |
| 536 | f.setBEXTData(ByteVector("bext payload")); |
| 537 | f.save(); |
| 538 | } |
| 539 | { |
| 540 | RIFF::WAV::File f(filename.c_str()); |
| 541 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 542 | CPPUNIT_ASSERT(f.hasInfoTag()); |
| 543 | CPPUNIT_ASSERT(f.hasBEXTData()); |
| 544 | CPPUNIT_ASSERT_EQUAL(String("ID3v2 Title"), f.ID3v2Tag()->title()); |
| 545 | CPPUNIT_ASSERT_EQUAL(String("INFO Title"), f.InfoTag()->title()); |
| 546 | CPPUNIT_ASSERT_EQUAL(ByteVector("bext payload"), f.BEXTData()); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | void testiXMLTag() |
| 551 | { |
| 552 | ScopedFileCopy copy("empty", ".wav"); |
| 553 | string filename = copy.fileName(); |
| 554 | |
| 555 | { |
| 556 | RIFF::WAV::File f(filename.c_str()); |
| 557 | CPPUNIT_ASSERT(f.isValid()); |
| 558 | CPPUNIT_ASSERT(!f.hasiXMLData()); |
| 559 | CPPUNIT_ASSERT(f.iXMLData().isEmpty()); |
| 560 | |
| 561 | f.setiXMLData("<BWFXML><IXML_VERSION>1.0</IXML_VERSION></BWFXML>"); |
| 562 | f.save(); |
| 563 | CPPUNIT_ASSERT(f.hasiXMLData()); |
| 564 | } |
| 565 | { |
| 566 | RIFF::WAV::File f(filename.c_str()); |
| 567 | CPPUNIT_ASSERT(f.isValid()); |
| 568 | CPPUNIT_ASSERT(f.hasiXMLData()); |
| 569 | CPPUNIT_ASSERT_EQUAL( |
| 570 | String("<BWFXML><IXML_VERSION>1.0</IXML_VERSION></BWFXML>"), |
| 571 | f.iXMLData()); |
| 572 | |
| 573 | f.setiXMLData(String()); |
| 574 | f.save(); |
| 575 | CPPUNIT_ASSERT(!f.hasiXMLData()); |
| 576 | } |
| 577 | { |
| 578 | RIFF::WAV::File f(filename.c_str()); |
| 579 | CPPUNIT_ASSERT(f.isValid()); |
| 580 | CPPUNIT_ASSERT(!f.hasiXMLData()); |
| 581 | CPPUNIT_ASSERT(f.iXMLData().isEmpty()); |
| 582 | } |
| 583 | |
| 584 | // Check if file without iXML is same as original empty file |
| 585 | const ByteVector origData = PlainFile(TEST_FILE_PATH_C("empty.wav")).readAll(); |
| 586 | const ByteVector fileData = PlainFile(filename.c_str()).readAll(); |
| 587 | CPPUNIT_ASSERT(origData == fileData); |
| 588 | } |
| 589 | |
| 590 | void testiXMLTagWithOtherTags() |
| 591 | { |
| 592 | ScopedFileCopy copy("empty", ".wav"); |
| 593 | string filename = copy.fileName(); |
| 594 | |
| 595 | { |
| 596 | RIFF::WAV::File f(filename.c_str()); |
| 597 | f.ID3v2Tag()->setTitle("ID3v2 Title"); |
| 598 | f.setiXMLData("<BWFXML><SCENE>1</SCENE></BWFXML>"); |
| 599 | f.setBEXTData(ByteVector("bext data")); |
| 600 | f.save(); |
| 601 | } |
| 602 | { |
| 603 | RIFF::WAV::File f(filename.c_str()); |
| 604 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 605 | CPPUNIT_ASSERT(f.hasiXMLData()); |
| 606 | CPPUNIT_ASSERT(f.hasBEXTData()); |
| 607 | CPPUNIT_ASSERT_EQUAL(String("ID3v2 Title"), f.ID3v2Tag()->title()); |
| 608 | CPPUNIT_ASSERT_EQUAL( |
| 609 | String("<BWFXML><SCENE>1</SCENE></BWFXML>"), |
| 610 | f.iXMLData()); |
| 611 | CPPUNIT_ASSERT_EQUAL(ByteVector("bext data"), f.BEXTData()); |
| 612 | |
| 613 | f.setiXMLData(String()); |
| 614 | f.setBEXTData(ByteVector()); |
| 615 | f.strip(); |
| 616 | CPPUNIT_ASSERT(f.save()); |
| 617 | } |
| 618 | { |
| 619 | RIFF::WAV::File f(filename.c_str()); |
| 620 | CPPUNIT_ASSERT(f.isValid()); |
| 621 | CPPUNIT_ASSERT(!f.hasID3v2Tag()); |
| 622 | CPPUNIT_ASSERT(!f.hasiXMLData()); |
| 623 | CPPUNIT_ASSERT(f.iXMLData().isEmpty()); |
| 624 | CPPUNIT_ASSERT(!f.hasBEXTData()); |
| 625 | CPPUNIT_ASSERT(f.BEXTData().isEmpty()); |
| 626 | } |
| 627 | |
| 628 | // Check if file without tags is same as original empty file |
| 629 | const ByteVector origData = PlainFile(TEST_FILE_PATH_C("empty.wav")).readAll(); |
| 630 | const ByteVector fileData = PlainFile(filename.c_str()).readAll(); |
| 631 | CPPUNIT_ASSERT(origData == fileData); |
| 632 | } |
| 633 | |
| 634 | }; |
| 635 | |
| 636 | CPPUNIT_TEST_SUITE_REGISTRATION(TestWAV); |