| 1 | /*************************************************************************** |
| 2 | copyright : (C) 2007 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 "tpropertymap.h" |
| 30 | #include "id3v1tag.h" |
| 31 | #include "id3v2tag.h" |
| 32 | #include "trueaudiofile.h" |
| 33 | #include <cppunit/extensions/HelperMacros.h> |
| 34 | #include "utils.h" |
| 35 | |
| 36 | using namespace std; |
| 37 | using namespace TagLib; |
| 38 | |
| 39 | class TestTrueAudio : public CppUnit::TestFixture |
| 40 | { |
| 41 | CPPUNIT_TEST_SUITE(TestTrueAudio); |
| 42 | CPPUNIT_TEST(testReadPropertiesWithoutID3v2); |
| 43 | CPPUNIT_TEST(testReadPropertiesWithTags); |
| 44 | CPPUNIT_TEST(testStripAndProperties); |
| 45 | CPPUNIT_TEST(testRepeatedSave); |
| 46 | CPPUNIT_TEST_SUITE_END(); |
| 47 | |
| 48 | public: |
| 49 | |
| 50 | void testReadPropertiesWithoutID3v2() |
| 51 | { |
| 52 | TrueAudio::File f(TEST_FILE_PATH_C("empty.tta")); |
| 53 | CPPUNIT_ASSERT(f.audioProperties()); |
| 54 | CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds()); |
| 55 | CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds()); |
| 56 | CPPUNIT_ASSERT_EQUAL(173, f.audioProperties()->bitrate()); |
| 57 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels()); |
| 58 | CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate()); |
| 59 | CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample()); |
| 60 | CPPUNIT_ASSERT_EQUAL(162496U, f.audioProperties()->sampleFrames()); |
| 61 | CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->ttaVersion()); |
| 62 | } |
| 63 | |
| 64 | void testReadPropertiesWithTags() |
| 65 | { |
| 66 | TrueAudio::File f(TEST_FILE_PATH_C("tagged.tta")); |
| 67 | CPPUNIT_ASSERT(f.audioProperties()); |
| 68 | CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds()); |
| 69 | CPPUNIT_ASSERT_EQUAL(3685, f.audioProperties()->lengthInMilliseconds()); |
| 70 | CPPUNIT_ASSERT_EQUAL(173, f.audioProperties()->bitrate()); |
| 71 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels()); |
| 72 | CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate()); |
| 73 | CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample()); |
| 74 | CPPUNIT_ASSERT_EQUAL(162496U, f.audioProperties()->sampleFrames()); |
| 75 | CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->ttaVersion()); |
| 76 | } |
| 77 | |
| 78 | void testStripAndProperties() |
| 79 | { |
| 80 | ScopedFileCopy copy("empty", ".tta"); |
| 81 | |
| 82 | { |
| 83 | TrueAudio::File f(copy.fileName().c_str()); |
| 84 | f.ID3v2Tag(true)->setTitle("ID3v2"); |
| 85 | f.ID3v1Tag(true)->setTitle("ID3v1"); |
| 86 | f.save(); |
| 87 | } |
| 88 | { |
| 89 | TrueAudio::File f(copy.fileName().c_str()); |
| 90 | CPPUNIT_ASSERT(f.hasID3v1Tag()); |
| 91 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 92 | CPPUNIT_ASSERT_EQUAL(String("ID3v2"), f.properties()["TITLE"].front()); |
| 93 | f.strip(TrueAudio::File::ID3v2); |
| 94 | CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front()); |
| 95 | f.strip(TrueAudio::File::ID3v1); |
| 96 | CPPUNIT_ASSERT(f.properties().isEmpty()); |
| 97 | f.save(); |
| 98 | } |
| 99 | { |
| 100 | TrueAudio::File f(copy.fileName().c_str()); |
| 101 | CPPUNIT_ASSERT(!f.hasID3v1Tag()); |
| 102 | CPPUNIT_ASSERT(!f.hasID3v2Tag()); |
| 103 | CPPUNIT_ASSERT(f.properties()["TITLE"].isEmpty()); |
| 104 | CPPUNIT_ASSERT(f.properties().isEmpty()); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void testRepeatedSave() |
| 109 | { |
| 110 | ScopedFileCopy copy("empty", ".tta"); |
| 111 | |
| 112 | { |
| 113 | TrueAudio::File f(copy.fileName().c_str()); |
| 114 | CPPUNIT_ASSERT(!f.hasID3v2Tag()); |
| 115 | CPPUNIT_ASSERT(!f.hasID3v1Tag()); |
| 116 | |
| 117 | f.ID3v2Tag(true)->setTitle("01234 56789 ABCDE FGHIJ"); |
| 118 | f.save(); |
| 119 | |
| 120 | f.ID3v2Tag()->setTitle("0"); |
| 121 | f.save(); |
| 122 | |
| 123 | f.ID3v1Tag(true)->setTitle("01234 56789 ABCDE FGHIJ"); |
| 124 | f.ID3v2Tag()->setTitle("01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789"); |
| 125 | f.save(); |
| 126 | } |
| 127 | { |
| 128 | TrueAudio::File f(copy.fileName().c_str()); |
| 129 | CPPUNIT_ASSERT(f.hasID3v2Tag()); |
| 130 | CPPUNIT_ASSERT(f.hasID3v1Tag()); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | }; |
| 135 | |
| 136 | CPPUNIT_TEST_SUITE_REGISTRATION(TestTrueAudio); |