| 1 | /*************************************************************************** |
| 2 | copyright : (C) 2011 by Mathias Panzenböck |
| 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 <cassert> |
| 27 | #include "tpropertymap.h" |
| 28 | #include "modfile.h" |
| 29 | #include <cppunit/extensions/HelperMacros.h> |
| 30 | #include "utils.h" |
| 31 | |
| 32 | using namespace std; |
| 33 | using namespace TagLib; |
| 34 | |
| 35 | static const String titleBefore("title of song"); |
| 36 | static const String titleAfter("changed title"); |
| 37 | |
| 38 | static const String commentBefore( |
| 39 | "Instrument names\n" |
| 40 | "are abused as\n" |
| 41 | "comments in\n" |
| 42 | "module file formats.\n" |
| 43 | "-+-+-+-+-+-+-+-+-+-+-+\n" |
| 44 | "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); |
| 45 | |
| 46 | static const String newComment( |
| 47 | "This line will be truncated because it is too long for a mod instrument name.\n" |
| 48 | "This line is ok."); |
| 49 | |
| 50 | static const String commentAfter( |
| 51 | "This line will be trun\n" |
| 52 | "This line is ok.\n" |
| 53 | "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); |
| 54 | |
| 55 | class TestMod : public CppUnit::TestFixture |
| 56 | { |
| 57 | CPPUNIT_TEST_SUITE(TestMod); |
| 58 | CPPUNIT_TEST(testReadTags); |
| 59 | CPPUNIT_TEST(testWriteTags); |
| 60 | CPPUNIT_TEST(testPropertyInterface); |
| 61 | CPPUNIT_TEST_SUITE_END(); |
| 62 | |
| 63 | public: |
| 64 | void testReadTags() |
| 65 | { |
| 66 | testRead(TEST_FILE_PATH_C("test.mod"), titleBefore, commentBefore); |
| 67 | } |
| 68 | |
| 69 | void testWriteTags() |
| 70 | { |
| 71 | ScopedFileCopy copy("test", ".mod"); |
| 72 | { |
| 73 | Mod::File file(copy.fileName().c_str()); |
| 74 | CPPUNIT_ASSERT(file.tag() != nullptr); |
| 75 | file.tag()->setTitle(titleAfter); |
| 76 | file.tag()->setComment(newComment); |
| 77 | CPPUNIT_ASSERT(file.save()); |
| 78 | } |
| 79 | testRead(copy.fileName().c_str(), titleAfter, commentAfter); |
| 80 | CPPUNIT_ASSERT(fileEqual( |
| 81 | copy.fileName(), |
| 82 | testFilePath("changed.mod"))); |
| 83 | } |
| 84 | |
| 85 | void testPropertyInterface() |
| 86 | { |
| 87 | Mod::Tag t; |
| 88 | PropertyMap properties; |
| 89 | properties["BLA"] = String("bla"); |
| 90 | properties["ARTIST"] = String("artist1"); |
| 91 | properties["ARTIST"].append("artist2"); |
| 92 | properties["TITLE"] = String("title"); |
| 93 | |
| 94 | PropertyMap unsupported = t.setProperties(properties); |
| 95 | CPPUNIT_ASSERT(unsupported.contains("BLA")); |
| 96 | CPPUNIT_ASSERT(unsupported.contains("ARTIST")); |
| 97 | CPPUNIT_ASSERT_EQUAL(properties["ARTIST"], unsupported["ARTIST"]); |
| 98 | CPPUNIT_ASSERT(!unsupported.contains("TITLE")); |
| 99 | |
| 100 | properties = t.properties(); |
| 101 | CPPUNIT_ASSERT_EQUAL(StringList("title"), properties["TITLE"]); |
| 102 | } |
| 103 | |
| 104 | private: |
| 105 | void testRead(FileName fileName, const String &title, const String &comment) |
| 106 | { |
| 107 | Mod::File file(fileName); |
| 108 | |
| 109 | CPPUNIT_ASSERT(file.isValid()); |
| 110 | |
| 111 | Mod::Properties *p = file.audioProperties(); |
| 112 | Mod::Tag *t = file.tag(); |
| 113 | |
| 114 | CPPUNIT_ASSERT(nullptr != p); |
| 115 | CPPUNIT_ASSERT(nullptr != t); |
| 116 | assert(p != nullptr); // to silence the clang analyzer |
| 117 | |
| 118 | CPPUNIT_ASSERT_EQUAL(0, p->lengthInSeconds()); |
| 119 | CPPUNIT_ASSERT_EQUAL(0, p->bitrate()); |
| 120 | CPPUNIT_ASSERT_EQUAL(0, p->sampleRate()); |
| 121 | CPPUNIT_ASSERT_EQUAL(8, p->channels()); |
| 122 | CPPUNIT_ASSERT_EQUAL(31U, p->instrumentCount()); |
| 123 | CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(1), p->lengthInPatterns()); |
| 124 | CPPUNIT_ASSERT_EQUAL(title, t->title()); |
| 125 | CPPUNIT_ASSERT_EQUAL(String(), t->artist()); |
| 126 | CPPUNIT_ASSERT_EQUAL(String(), t->album()); |
| 127 | CPPUNIT_ASSERT_EQUAL(comment, t->comment()); |
| 128 | CPPUNIT_ASSERT_EQUAL(String(), t->genre()); |
| 129 | CPPUNIT_ASSERT_EQUAL(0U, t->year()); |
| 130 | CPPUNIT_ASSERT_EQUAL(0U, t->track()); |
| 131 | CPPUNIT_ASSERT_EQUAL(String("StarTrekker"), t->trackerName()); |
| 132 | } |
| 133 | }; |
| 134 | |
| 135 | CPPUNIT_TEST_SUITE_REGISTRATION(TestMod); |