From 68c0b0591b0ee154e4faf35f8fae91e9e13b352e Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Fri, 20 Mar 2015 13:33:13 +0900 Subject: [PATCH] Fix a bug that Tag::setProperties() clears the date instead of the track number. --- taglib/tag.cpp | 2 +- tests/test_propertymap.cpp | 52 +++++++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/taglib/tag.cpp b/taglib/tag.cpp index 98c23043..eb8fab7a 100644 --- a/taglib/tag.cpp +++ b/taglib/tag.cpp @@ -137,7 +137,7 @@ PropertyMap Tag::setProperties(const PropertyMap &origProps) setTrack(0); } else - setYear(0); + setTrack(0); // for each tag that has been set above, remove the first entry in the corresponding // value list. The others will be returned as unsupported by this format. diff --git a/tests/test_propertymap.cpp b/tests/test_propertymap.cpp index 0ca7b723..49d856a0 100644 --- a/tests/test_propertymap.cpp +++ b/tests/test_propertymap.cpp @@ -1,25 +1,32 @@ -#include #include +#include +#include +#include +#include "utils.h" + +using namespace TagLib; + class TestPropertyMap : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(TestPropertyMap); CPPUNIT_TEST(testInvalidKeys); + CPPUNIT_TEST(testGetSet); CPPUNIT_TEST_SUITE_END(); public: void testInvalidKeys() { - TagLib::PropertyMap map1; + PropertyMap map1; CPPUNIT_ASSERT(map1.isEmpty()); map1[L"\x00c4\x00d6\x00dc"].append("test"); CPPUNIT_ASSERT_EQUAL(map1.size(), 1u); - TagLib::PropertyMap map2; + PropertyMap map2; map2[L"\x00c4\x00d6\x00dc"].append("test"); CPPUNIT_ASSERT(map1 == map2); CPPUNIT_ASSERT(map1.contains(map2)); - map2["ARTIST"] = TagLib::String("Test Artist"); + map2["ARTIST"] = String("Test Artist"); CPPUNIT_ASSERT(map1 != map2); CPPUNIT_ASSERT(map2.contains(map1)); @@ -27,6 +34,43 @@ public: CPPUNIT_ASSERT(!map2.contains(map1)); } + + void testGetSet() + { + ID3v1::Tag tag; + + tag.setTitle("Test Title"); + tag.setArtist("Test Artist"); + tag.setAlbum("Test Album"); + tag.setYear(2015); + tag.setTrack(10); + + { + PropertyMap prop = tag.properties(); + CPPUNIT_ASSERT_EQUAL(String("Test Title"), prop["TITLE" ].front()); + CPPUNIT_ASSERT_EQUAL(String("Test Artist"), prop["ARTIST" ].front()); + CPPUNIT_ASSERT_EQUAL(String("Test Album"), prop["ALBUM" ].front()); + CPPUNIT_ASSERT_EQUAL(String("2015"), prop["DATE" ].front()); + CPPUNIT_ASSERT_EQUAL(String("10"), prop["TRACKNUMBER"].front()); + + prop["TITLE" ].front() = "Test Title 2"; + prop["ARTIST" ].front() = "Test Artist 2"; + prop["TRACKNUMBER"].front() = "5"; + + tag.setProperties(prop); + } + + CPPUNIT_ASSERT_EQUAL(String("Test Title 2"), tag.title()); + CPPUNIT_ASSERT_EQUAL(String("Test Artist 2"), tag.artist()); + CPPUNIT_ASSERT_EQUAL(5U, tag.track()); + + tag.setProperties(PropertyMap()); + + CPPUNIT_ASSERT_EQUAL(String(""), tag.title()); + CPPUNIT_ASSERT_EQUAL(String(""), tag.artist()); + CPPUNIT_ASSERT_EQUAL(0U, tag.track()); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestPropertyMap);