File: test_propertymap.cpp

package info (click to toggle)
taglib 2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,192 kB
  • sloc: cpp: 44,736; ansic: 137; makefile: 28
file content (234 lines) | stat: -rw-r--r-- 7,526 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/***************************************************************************
    copyright           : (C) 2012 by Michael Helmling
    email               : helmling@mathematik.uni-kl.de
 ***************************************************************************/

/***************************************************************************
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Lesser General Public License version   *
 *   2.1 as published by the Free Software Foundation.                     *
 *                                                                         *
 *   This library is distributed in the hope that it will be useful, but   *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *   Lesser General Public License for more details.                       *
 *                                                                         *
 *   You should have received a copy of the GNU Lesser General Public      *
 *   License along with this library; if not, write to the Free Software   *
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA         *
 *   02110-1301  USA                                                       *
 *                                                                         *
 *   Alternatively, this file is available under the Mozilla Public        *
 *   License Version 1.1.  You may obtain a copy of the License at         *
 *   http://www.mozilla.org/MPL/                                           *
 ***************************************************************************/

#include "taglib_config.h"
#include "tpropertymap.h"
#include "tag.h"
#include "id3v1tag.h"
#include "id3v2tag.h"
#ifdef TAGLIB_WITH_APE
#include "apetag.h"
#endif
#ifdef TAGLIB_WITH_ASF
#include "asftag.h"
#endif
#ifdef TAGLIB_WITH_RIFF
#include "infotag.h"
#endif
#ifdef TAGLIB_WITH_MP4
#include "mp4tag.h"
#endif
#ifdef TAGLIB_WITH_VORBIS
#include "xiphcomment.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"

using namespace TagLib;

class TestPropertyMap : public CppUnit::TestFixture
{
  CPPUNIT_TEST_SUITE(TestPropertyMap);
  CPPUNIT_TEST(testInvalidKeys);
  CPPUNIT_TEST(testGetSetId3v1);
  CPPUNIT_TEST(testGetSetId3v2);
  CPPUNIT_TEST(testGetSet);
#ifdef TAGLIB_WITH_APE
  CPPUNIT_TEST(testGetSetApe);
#endif
#ifdef TAGLIB_WITH_ASF
  CPPUNIT_TEST(testGetSetAsf);
#endif
#ifdef TAGLIB_WITH_RIFF
  CPPUNIT_TEST(testGetSetInfo);
#endif
#ifdef TAGLIB_WITH_MP4
  CPPUNIT_TEST(testGetSetMp4);
#endif
#ifdef TAGLIB_WITH_VORBIS
  CPPUNIT_TEST(testGetSetXiphComment);
#endif
  CPPUNIT_TEST_SUITE_END();

public:
  void testInvalidKeys()
  {
    PropertyMap map1;
    CPPUNIT_ASSERT(map1.isEmpty());
    map1[L"\x00c4\x00d6\x00dc"].append("test");
    CPPUNIT_ASSERT_EQUAL(map1.size(), 1u);

    PropertyMap map2;
    map2[L"\x00c4\x00d6\x00dc"].append("test");
    CPPUNIT_ASSERT(map1 == map2);
    CPPUNIT_ASSERT(map1.contains(map2));

    map2["ARTIST"] = String("Test Artist");
    CPPUNIT_ASSERT(map1 != map2);
    CPPUNIT_ASSERT(map2.contains(map1));

    map2[L"\x00c4\x00d6\x00dc"].append("test 2");
    CPPUNIT_ASSERT(!map2.contains(map1));

  }

  template <typename T>
  void tagGetSet()
  {
    T 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());
    CPPUNIT_ASSERT(!tag.isEmpty());

    PropertyMap props = tag.properties();
    CPPUNIT_ASSERT_EQUAL(StringList("Test Artist 2"), props.find("ARTIST")->second);
    CPPUNIT_ASSERT(props.find("COMMENT") == props.end());
    props.replace("ARTIST", StringList("Test Artist 3"));
    CPPUNIT_ASSERT_EQUAL(StringList("Test Artist 3"), props["ARTIST"]);

    PropertyMap eraseMap;
    eraseMap.insert("ARTIST", StringList());
    eraseMap.insert("ALBUM", StringList());
    eraseMap.insert("TITLE", StringList());
    props.erase(eraseMap);
    CPPUNIT_ASSERT_EQUAL(String("DATE=2015\nTRACKNUMBER=5\n"), props.toString());

    tag.setProperties(PropertyMap());

    CPPUNIT_ASSERT(tag.isEmpty());
    CPPUNIT_ASSERT(tag.properties().isEmpty());
    CPPUNIT_ASSERT_EQUAL(String(""), tag.title());
    CPPUNIT_ASSERT_EQUAL(String(""), tag.artist());
    CPPUNIT_ASSERT_EQUAL(String(""), tag.album());
    CPPUNIT_ASSERT_EQUAL(String(""), tag.comment());
    CPPUNIT_ASSERT_EQUAL(String(""), tag.genre());
    CPPUNIT_ASSERT_EQUAL(0U, tag.track());
    CPPUNIT_ASSERT(tag.isEmpty());
    CPPUNIT_ASSERT(tag.properties().isEmpty());
  }

  void testGetSetId3v1()
  {
    tagGetSet<ID3v1::Tag>();
  }

  void testGetSetId3v2()
  {
    tagGetSet<ID3v2::Tag>();
  }

#ifdef TAGLIB_WITH_VORBIS
  void testGetSetXiphComment()
  {
    tagGetSet<Ogg::XiphComment>();
  }
#endif

#ifdef TAGLIB_WITH_APE
  void testGetSetApe()
  {
    tagGetSet<APE::Tag>();
  }
#endif

#ifdef TAGLIB_WITH_ASF
  void testGetSetAsf()
  {
    tagGetSet<ASF::Tag>();
  }
#endif

#ifdef TAGLIB_WITH_MP4
  void testGetSetMp4()
  {
    tagGetSet<MP4::Tag>();
  }
#endif

#ifdef TAGLIB_WITH_RIFF
  void testGetSetInfo()
  {
    tagGetSet<RIFF::Info::Tag>();
  }
#endif

  void testGetSet()
  {
    PropertyMap props;
    props["Title"] = String("Test Title");
    StringList artists("Artist 1");
    artists.append("Artist 2");
    props.insert("Artist", artists);
    CPPUNIT_ASSERT_EQUAL(StringList("Test Title"), props.value("TITLE"));
    CPPUNIT_ASSERT_EQUAL(StringList("Test Title"), props.value("Title"));
    CPPUNIT_ASSERT_EQUAL(StringList("Test Title"), props["TITLE"]);
    CPPUNIT_ASSERT_EQUAL(StringList("Test Title"), props["Title"]);
    CPPUNIT_ASSERT(props.contains("title"));
    CPPUNIT_ASSERT_EQUAL(StringList("Test Title"), props.find("TITLE")->second);
    CPPUNIT_ASSERT_EQUAL(2U, props.size());
    CPPUNIT_ASSERT(!props.isEmpty());
    props.clear();
    CPPUNIT_ASSERT(props.isEmpty());
    CPPUNIT_ASSERT_EQUAL(StringList(), props.value("TITLE"));
    CPPUNIT_ASSERT_EQUAL(StringList(), props.value("Title"));
    CPPUNIT_ASSERT_EQUAL(artists, props.value("Title", artists));
    CPPUNIT_ASSERT(!props.contains("title"));
    CPPUNIT_ASSERT(props.find("TITLE") == props.end());
    CPPUNIT_ASSERT_EQUAL(0U, props.size());
    CPPUNIT_ASSERT(props.isEmpty());
    CPPUNIT_ASSERT_EQUAL(StringList(), props["TITLE"]);
    CPPUNIT_ASSERT_EQUAL(StringList(), props["Title"]);
    CPPUNIT_ASSERT(props.contains("title"));
    CPPUNIT_ASSERT(props.find("TITLE") != props.end());
    CPPUNIT_ASSERT_EQUAL(1U, props.size());
    CPPUNIT_ASSERT(!props.isEmpty());
  }

};

CPPUNIT_TEST_SUITE_REGISTRATION(TestPropertyMap);