Debian Codegraph @

tests/test_mp4item.cpp

raw symbols SCIP
1 /***************************************************************************
2 copyright : (C) 2009 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 "tag.h"
30 #include "mp4coverart.h"
31 #include "mp4item.h"
32 #include <cppunit/extensions/HelperMacros.h>
33 #include "utils.h"
34
35 using namespace std;
36 using namespace TagLib;
37
38 class TestMP4Item : public CppUnit::TestFixture
39 {
40 CPPUNIT_TEST_SUITE(TestMP4Item);
41 CPPUNIT_TEST(testCoverArtList);
42 CPPUNIT_TEST(testItemOperations);
43 CPPUNIT_TEST_SUITE_END();
44
45 public:
46
47 void testCoverArtList()
48 {
49 MP4::CoverArtList l;
50 l.append(MP4::CoverArt(MP4::CoverArt::PNG, "foo"));
51 l.append(MP4::CoverArt(MP4::CoverArt::JPEG, "bar"));
52
53 MP4::Item i(l);
54 MP4::CoverArtList l2 = i.toCoverArtList();
55
56 CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format());
57 CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), l[0].data());
58 CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format());
59 CPPUNIT_ASSERT_EQUAL(ByteVector("bar"), l[1].data());
60 }
61
62 void testItemOperations()
63 {
64 MP4::Item e;
65 MP4::Item i1(1);
66 MP4::Item i2(1);
67 MP4::Item i3(-1);
68 MP4::Item c1(static_cast<unsigned char>('A'));
69 MP4::Item c2(static_cast<unsigned char>('A'));
70 MP4::Item c3(static_cast<unsigned char>('Z'));
71 MP4::Item u1(2U);
72 MP4::Item u2(2U);
73 MP4::Item u3(0U);
74 MP4::Item l1(3LL);
75 MP4::Item l2(3LL);
76 MP4::Item l3(-7LL);
77 MP4::Item b1(true);
78 MP4::Item b2(true);
79 MP4::Item b3(false);
80 MP4::Item p1(4, 5);
81 MP4::Item p2(4, 5);
82 MP4::Item p3(-4, -5);
83 MP4::Item s1(StringList{"abc", "de"});
84 MP4::Item s2(StringList{"abc", "de"});
85 MP4::Item s3(StringList{"abc"});
86 MP4::Item v1(ByteVectorList{"f", "gh"});
87 MP4::Item v2(ByteVectorList{"f", "gh"});
88 MP4::Item v3(ByteVectorList{});
89 MP4::Item a1(MP4::CoverArtList{
90 MP4::CoverArt(MP4::CoverArt::PNG, "foo"),
91 MP4::CoverArt(MP4::CoverArt::JPEG, "bar")
92 });
93 MP4::Item a2(MP4::CoverArtList{
94 MP4::CoverArt(MP4::CoverArt::PNG, "foo"),
95 MP4::CoverArt(MP4::CoverArt::JPEG, "bar")
96 });
97 MP4::Item a3(MP4::CoverArtList{
98 MP4::CoverArt(MP4::CoverArt::JPEG, "bar")
99 });
100
101 CPPUNIT_ASSERT(i1 == i2);
102 CPPUNIT_ASSERT(i2 != i3);
103 CPPUNIT_ASSERT(i3 != c1);
104 CPPUNIT_ASSERT(c1 == c1);
105 CPPUNIT_ASSERT(c1 == c2);
106 CPPUNIT_ASSERT(c2 != c3);
107 CPPUNIT_ASSERT(c3 != u1);
108 CPPUNIT_ASSERT(u1 == u2);
109 CPPUNIT_ASSERT(u2 != u3);
110 CPPUNIT_ASSERT(u3 != l1);
111 CPPUNIT_ASSERT(l1 == l2);
112 CPPUNIT_ASSERT(l2 != l3);
113 CPPUNIT_ASSERT(l3 != b1);
114 CPPUNIT_ASSERT(b1 == b2);
115 CPPUNIT_ASSERT(b2 != b3);
116 CPPUNIT_ASSERT(b3 != p1);
117 CPPUNIT_ASSERT(p1 == p2);
118 CPPUNIT_ASSERT(p2 != p3);
119 CPPUNIT_ASSERT(p3 != s1);
120 CPPUNIT_ASSERT(s1 == s2);
121 CPPUNIT_ASSERT(s2 != s3);
122 CPPUNIT_ASSERT(s3 != v1);
123 CPPUNIT_ASSERT(v1 == v2);
124 CPPUNIT_ASSERT(v2 != v3);
125 CPPUNIT_ASSERT(v3 != a1);
126 CPPUNIT_ASSERT(a1 == a2);
127 CPPUNIT_ASSERT(a2 != a3);
128 CPPUNIT_ASSERT(a3 != e);
129
130 CPPUNIT_ASSERT(!e.isValid());
131 CPPUNIT_ASSERT(i1.isValid());
132 CPPUNIT_ASSERT_EQUAL(MP4::Item::Type::Void, e.type());
133 CPPUNIT_ASSERT_EQUAL(MP4::Item::Type::Int, i1.type());
134 CPPUNIT_ASSERT_EQUAL(MP4::Item::Type::Byte, c1.type());
135 CPPUNIT_ASSERT_EQUAL(MP4::Item::Type::UInt, u1.type());
136 CPPUNIT_ASSERT_EQUAL(MP4::Item::Type::LongLong, l1.type());
137 CPPUNIT_ASSERT_EQUAL(MP4::Item::Type::Bool, b1.type());
138 CPPUNIT_ASSERT_EQUAL(MP4::Item::Type::IntPair, p1.type());
139 CPPUNIT_ASSERT_EQUAL(MP4::Item::Type::StringList, s1.type());
140 CPPUNIT_ASSERT_EQUAL(MP4::Item::Type::ByteVectorList, v1.type());
141 CPPUNIT_ASSERT_EQUAL(MP4::Item::Type::CoverArtList, a1.type());
142
143 CPPUNIT_ASSERT_EQUAL(1, i1.toInt());
144 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>('A'), c1.toByte());
145 CPPUNIT_ASSERT_EQUAL(2U, u1.toUInt());
146 CPPUNIT_ASSERT_EQUAL(3LL, l1.toLongLong());
147 CPPUNIT_ASSERT_EQUAL(true, b1.toBool());
148 CPPUNIT_ASSERT_EQUAL(4, p1.toIntPair().first);
149 CPPUNIT_ASSERT_EQUAL((StringList{"abc", "de"}), s1.toStringList());
150 CPPUNIT_ASSERT_EQUAL((ByteVectorList{"f", "gh"}), v1.toByteVectorList());
151 CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, a1.toCoverArtList().front().format());
152
153 s3.swap(s1);
154 CPPUNIT_ASSERT_EQUAL((StringList{"abc"}), s1.toStringList());
155 CPPUNIT_ASSERT_EQUAL((StringList{"abc", "de"}), s3.toStringList());
156 CPPUNIT_ASSERT_EQUAL(MP4::AtomDataType::TypeUndefined, s1.atomDataType());
157 s1.setAtomDataType(MP4::AtomDataType::TypeUTF8);
158 CPPUNIT_ASSERT_EQUAL(MP4::AtomDataType::TypeUTF8, s1.atomDataType());
159 s1 = s3;
160 CPPUNIT_ASSERT_EQUAL((StringList{"abc", "de"}), s1.toStringList());
161
162 MP4::ItemMap m1{{"key1", i1}, {"key2", p1}};
163 MP4::ItemMap m2{{"key1", i2}, {"key2", p2}};
164 MP4::ItemMap m3{{"key1", i2}, {"key2", p3}};
165 CPPUNIT_ASSERT(m1 == m2);
166 CPPUNIT_ASSERT(m1 != m3);
167 }
168 };
169
170 CPPUNIT_TEST_SUITE_REGISTRATION(TestMP4Item);