| 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 "tstring.h" |
| 30 | #include "mpegfile.h" |
| 31 | #include "id3v1tag.h" |
| 32 | #include "id3v1genres.h" |
| 33 | #include <cppunit/extensions/HelperMacros.h> |
| 34 | #include "utils.h" |
| 35 | |
| 36 | using namespace std; |
| 37 | using namespace TagLib; |
| 38 | |
| 39 | class TestID3v1 : public CppUnit::TestFixture |
| 40 | { |
| 41 | CPPUNIT_TEST_SUITE(TestID3v1); |
| 42 | CPPUNIT_TEST(testStripWhiteSpace); |
| 43 | CPPUNIT_TEST(testGenres); |
| 44 | CPPUNIT_TEST(testRenamedGenres); |
| 45 | CPPUNIT_TEST_SUITE_END(); |
| 46 | |
| 47 | public: |
| 48 | |
| 49 | void testStripWhiteSpace() |
| 50 | { |
| 51 | ScopedFileCopy copy("xing", ".mp3"); |
| 52 | string newname = copy.fileName(); |
| 53 | |
| 54 | { |
| 55 | MPEG::File f(newname.c_str()); |
| 56 | f.ID3v1Tag(true)->setArtist("Artist "); |
| 57 | f.save(); |
| 58 | } |
| 59 | |
| 60 | { |
| 61 | MPEG::File f(newname.c_str()); |
| 62 | CPPUNIT_ASSERT(f.ID3v1Tag(false)); |
| 63 | CPPUNIT_ASSERT_EQUAL(String("Artist"), f.ID3v1Tag(false)->artist()); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | void testGenres() |
| 68 | { |
| 69 | CPPUNIT_ASSERT_EQUAL(String("Darkwave"), ID3v1::genre(50)); |
| 70 | CPPUNIT_ASSERT_EQUAL(100, ID3v1::genreIndex("Humour")); |
| 71 | CPPUNIT_ASSERT(ID3v1::genreList().contains("Heavy Metal")); |
| 72 | CPPUNIT_ASSERT_EQUAL(79, ID3v1::genreMap()["Hard Rock"]); |
| 73 | } |
| 74 | |
| 75 | void testRenamedGenres() |
| 76 | { |
| 77 | CPPUNIT_ASSERT_EQUAL(String("Bebop"), ID3v1::genre(85)); |
| 78 | CPPUNIT_ASSERT_EQUAL(85, ID3v1::genreIndex("Bebop")); |
| 79 | CPPUNIT_ASSERT_EQUAL(85, ID3v1::genreIndex("Bebob")); |
| 80 | |
| 81 | ID3v1::Tag tag; |
| 82 | tag.setGenre("Hardcore"); |
| 83 | CPPUNIT_ASSERT_EQUAL(String("Hardcore Techno"), tag.genre()); |
| 84 | CPPUNIT_ASSERT_EQUAL(129U, tag.genreNumber()); |
| 85 | } |
| 86 | |
| 87 | }; |
| 88 | |
| 89 | CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v1); |