| 1 | #include <string> |
| 2 | #include <cstdio> |
| 3 | |
| 4 | #include "tbytevectorlist.h" |
| 5 | #include "tpropertymap.h" |
| 6 | #include "tag.h" |
| 7 | #include "dsffile.h" |
| 8 | #include "plainfile.h" |
| 9 | #include <cppunit/extensions/HelperMacros.h> |
| 10 | #include "utils.h" |
| 11 | |
| 12 | using namespace std; |
| 13 | using namespace TagLib; |
| 14 | |
| 15 | class TestDSF : public CppUnit::TestFixture |
| 16 | { |
| 17 | CPPUNIT_TEST_SUITE(TestDSF); |
| 18 | CPPUNIT_TEST(testBasic); |
| 19 | CPPUNIT_TEST(testTags); |
| 20 | CPPUNIT_TEST_SUITE_END(); |
| 21 | |
| 22 | public: |
| 23 | |
| 24 | void testBasic() |
| 25 | { |
| 26 | DSF::File f(TEST_FILE_PATH_C("empty10ms.dsf")); |
| 27 | CPPUNIT_ASSERT(f.audioProperties()); |
| 28 | CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds()); |
| 29 | CPPUNIT_ASSERT_EQUAL(10, f.audioProperties()->lengthInMilliseconds()); |
| 30 | CPPUNIT_ASSERT_EQUAL(5645, f.audioProperties()->bitrate()); |
| 31 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels()); |
| 32 | CPPUNIT_ASSERT_EQUAL(2822400, f.audioProperties()->sampleRate()); |
| 33 | CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->formatVersion()); |
| 34 | CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->formatID()); |
| 35 | CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channelType()); |
| 36 | CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->bitsPerSample()); |
| 37 | CPPUNIT_ASSERT_EQUAL(static_cast<long long>(28224), f.audioProperties()->sampleCount()); |
| 38 | CPPUNIT_ASSERT_EQUAL(4096, f.audioProperties()->blockSizePerChannel()); |
| 39 | } |
| 40 | |
| 41 | void testTags() |
| 42 | { |
| 43 | ScopedFileCopy copy("empty10ms", ".dsf"); |
| 44 | string newname = copy.fileName(); |
| 45 | |
| 46 | { |
| 47 | DSF::File f(newname.c_str()); |
| 48 | CPPUNIT_ASSERT(f.properties().isEmpty()); |
| 49 | CPPUNIT_ASSERT_EQUAL(String(""), f.tag()->artist()); |
| 50 | f.tag()->setArtist("The Artist"); |
| 51 | PropertyMap properties = f.properties(); |
| 52 | properties["ALBUMARTIST"] = StringList("Album Artist"); |
| 53 | f.setProperties(properties); |
| 54 | f.save(); |
| 55 | } |
| 56 | |
| 57 | { |
| 58 | DSF::File f(newname.c_str()); |
| 59 | CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist()); |
| 60 | CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.properties()["ARTIST"].front()); |
| 61 | CPPUNIT_ASSERT_EQUAL(String("Album Artist"), f.properties()["ALBUMARTIST"].front()); |
| 62 | f.setProperties(PropertyMap()); |
| 63 | f.save(); |
| 64 | } |
| 65 | |
| 66 | // Check if file without tags is same as original empty file |
| 67 | const ByteVector dsfData = PlainFile(TEST_FILE_PATH_C("empty10ms.dsf")).readAll(); |
| 68 | const ByteVector fileData = PlainFile(newname.c_str()).readAll(); |
| 69 | CPPUNIT_ASSERT(dsfData == fileData); |
| 70 | } |
| 71 | |
| 72 | }; |
| 73 | |
| 74 | CPPUNIT_TEST_SUITE_REGISTRATION(TestDSF); |