4 #include "../statusprovider.h" 5 #include "../tagtarget.h" 6 #include "../signature.h" 8 #include "../aspectratio.h" 9 #include "../mediaformat.h" 10 #include "../mediafileinfo.h" 11 #include "../exceptions.h" 12 #include "../backuphelper.h" 14 #include <c++utilities/io/catchiofailure.h> 15 #include <c++utilities/tests/testutils.h> 18 #include <cppunit/TestFixture.h> 19 #include <cppunit/extensions/HelperMacros.h> 24 using namespace Media;
48 CPPUNIT_TEST(testSize);
49 CPPUNIT_TEST(testStatusProvider);
50 CPPUNIT_TEST(testTagTarget);
51 CPPUNIT_TEST(testSignature);
52 CPPUNIT_TEST(testMargin);
53 CPPUNIT_TEST(testAspectRatio);
54 CPPUNIT_TEST(testMediaFormat);
56 CPPUNIT_TEST(testBackupFile);
58 CPPUNIT_TEST_SUITE_END();
65 void testStatusProvider();
69 void testAspectRatio();
70 void testMediaFormat();
72 void testBackupFile();
88 static_assert(
Size().isNull(),
"Size::isNull()");
89 static_assert(!
Size(3, 4).isNull(),
"Size::isNull()");
90 static_assert(
Size(3, 4).resolution() == 12,
"Size::resolution");
92 Size size(1920, 1080);
93 CPPUNIT_ASSERT_EQUAL(
"width: 1920, height: 1080"s, size.
toString());
94 CPPUNIT_ASSERT_EQUAL(
"1080p"s,
string(size.
abbreviation()));
97 CPPUNIT_ASSERT_EQUAL(
"720p"s,
string(size.
abbreviation()));
102 const string context(
"unit tests");
108 status.
addNotification(NotificationType::Debug,
"debug notification", context);
113 CPPUNIT_ASSERT_EQUAL(
"warning"s, status.
notifications().back().message());
132 bool statusUpdateReceived =
false, firstStatusUpdate =
true;
134 CPPUNIT_ASSERT(&status == &sender);
135 if(firstStatusUpdate) {
138 firstStatusUpdate =
false;
141 statusUpdateReceived =
true;
144 CPPUNIT_ASSERT_MESSAGE(
"status update for updated status received", statusUpdateReceived);
146 statusUpdateReceived =
false;
148 CPPUNIT_ASSERT_MESSAGE(
"status update for updated percentage received", statusUpdateReceived);
149 statusUpdateReceived =
false;
151 CPPUNIT_ASSERT_MESSAGE(
"status update for new notification received", statusUpdateReceived);
152 statusUpdateReceived =
false;
155 CPPUNIT_ASSERT_MESSAGE(
"no status update received after callback unregistered", !statusUpdateReceived);
160 statusUpdateReceived =
false;
162 CPPUNIT_ASSERT(&status == &sender);
165 statusUpdateReceived =
true;
168 CPPUNIT_ASSERT(statusUpdateReceived);
174 CPPUNIT_ASSERT(target.
isEmpty());
175 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"default level is 50", 50ul, target.
level());
176 CPPUNIT_ASSERT_EQUAL(
"level 50"s, target.
toString(TagTargetLevel::Unspecified));
177 target =
TagTarget(30, {1, 2, 3}, {4}, {5, 6}, {7, 8, 9});
178 CPPUNIT_ASSERT(!target.isEmpty());
179 const auto mapping = [] (uint64 level) {
182 CPPUNIT_ASSERT_EQUAL(
"level 30 'track, song, chapter', track 1, track 2, track 3, chapter 4, edition 5, edition 6, attachment 7, attachment 8, attachment 9"s, target.toString(mapping));
184 CPPUNIT_ASSERT_EQUAL(
"level 40, track 1, track 2, track 3, chapter 4, edition 5, edition 6, attachment 7, attachment 8, attachment 9"s, target.toString(mapping));
185 target.setLevelName(
"test");
186 CPPUNIT_ASSERT_EQUAL(
"level 40 'test', track 1, track 2, track 3, chapter 4, edition 5, edition 6, attachment 7, attachment 8, attachment 9"s, target.toString(mapping));
187 CPPUNIT_ASSERT(target ==
TagTarget(40, {1, 2, 3}, {4}, {5, 6}, {7, 8, 9}));
189 CPPUNIT_ASSERT(target.isEmpty());
195 const unsigned char xzHead[12] = {
196 0xfd, 0x37, 0x7a, 0x58,
197 0x5a, 0x00, 0x00, 0x04,
198 0xe6, 0xd6, 0xb4, 0x46
202 CPPUNIT_ASSERT_EQUAL(ContainerFormat::Unknown,
parseSignature(reinterpret_cast<const char *>(xzHead), 3));
203 CPPUNIT_ASSERT_EQUAL(ContainerFormat::Unknown,
parseSignature(reinterpret_cast<const char *>(xzHead), 2));
204 CPPUNIT_ASSERT_EQUAL(ContainerFormat::Unknown,
parseSignature(reinterpret_cast<const char *>(xzHead), 0));
206 const auto containerFormat =
parseSignature(reinterpret_cast<const char *>(xzHead),
sizeof(xzHead));
215 static_assert(
Margin().isNull(),
"empty margin");
216 static_assert(!
Margin(0, 2).isNull(),
"non-empty margin");
218 CPPUNIT_ASSERT_EQUAL(
"top: 1; left: 2; bottom: 3; right: 4"s,
Margin(1, 2, 3, 4).toString());
223 static_assert(!
AspectRatio().isValid(),
"invalid aspect ratio");
224 static_assert(
AspectRatio(16, 9).isValid(),
"valid aspect ratio");
225 static_assert(
AspectRatio(16, 9).isExtended(),
"extended aspect ratio");
228 CPPUNIT_ASSERT_EQUAL(static_cast<uint16>(16), ratio.
numerator);
229 CPPUNIT_ASSERT_EQUAL(static_cast<uint16>(11), ratio.
denominator);
231 CPPUNIT_ASSERT_EQUAL(static_cast<uint16>(0), ratio2.
numerator);
232 CPPUNIT_ASSERT_EQUAL(static_cast<uint16>(0), ratio2.
denominator);
239 CPPUNIT_ASSERT_EQUAL(
"Advanced Audio Coding"s,
string(aac.
name()));
240 CPPUNIT_ASSERT_EQUAL(
"AAC"s,
string(aac.
abbreviation()));
247 CPPUNIT_ASSERT_EQUAL(
"Advanced Audio Coding Low Complexity Profile"s,
string(aac.
name()));
248 CPPUNIT_ASSERT_EQUAL(
"MPEG-4 AAC-LC"s,
string(aac.
abbreviation()));
250 CPPUNIT_ASSERT_EQUAL(
"Spectral Band Replication / HE-AAC"s,
string(aac.
extensionName()));
254 void UtilitiesTests::testBackupFile()
256 using namespace BackupHelper;
268 string backupPath1, backupPath2;
269 NativeFileStream backupStream1, backupStream2;
271 CPPUNIT_ASSERT_EQUAL(workingDir +
"/unsupported.bin.bak", backupPath1);
274 file.
stream().open(file.
path(), ios_base::out);
275 file.
stream() <<
"test1" << endl;
279 CPPUNIT_ASSERT_EQUAL(workingDir +
"/unsupported.bin.1.bak", backupPath2);
282 backupStream2.close();
283 remove(backupPath2.data());
284 file.
stream().open(file.
path(), ios_base::out);
285 file.
stream() <<
"test2" << endl;
291 CPPUNIT_FAIL(
"renaming failed because backup dir does not exist");
293 const char *what = catchIoFailure();
294 CPPUNIT_ASSERT(strstr(what,
"Unable to rename original file before rewriting it."));
296 backupStream2.clear();
297 workingCopyPathMode(
"bak/unsupported.bin", WorkingCopyMode::NoCopy);
299 CPPUNIT_ASSERT_EQUAL(workingDir +
"/bak/unsupported.bin", backupPath2);
302 backupStream2.close();
303 remove(backupPath2.data());
307 backupStream1.seekg(0, ios_base::end);
308 CPPUNIT_ASSERT_EQUAL(41_st, static_cast<size_t>(backupStream1.tellg()));
315 file.
stream().seekg(0x1D);
316 CPPUNIT_ASSERT_EQUAL(static_cast<ios::int_type>(0x34), file.
stream().get());
333 CPPUNIT_ASSERT_EQUAL(
"Rewriting the file to apply changed tag information has been aborted."s, file.
notifications().front().message());
334 CPPUNIT_ASSERT_EQUAL(
"The original file has been restored."s, file.
notifications().back().message());
345 CPPUNIT_ASSERT_EQUAL(
"Rewriting the file to apply changed tag information failed."s, file.
notifications().front().message());
346 CPPUNIT_ASSERT_EQUAL(
"The original file has been restored."s, file.
notifications().back().message());
352 throwIoFailure(
"simulated IO failure");
356 CPPUNIT_FAIL(
"IO failure rethrown");
362 CPPUNIT_ASSERT_EQUAL(
"An IO error occured when rewriting the file to apply changed tag information."s, file.
notifications().front().message());
363 CPPUNIT_ASSERT_EQUAL(
"The original file has been restored."s, file.
notifications().back().message());
366 remove(file.
path().data());
The UtilitiesTests class tests various utility classes and functions of the tagparser library...
Contains utility classes helping to read and write streams.
CPPUNIT_TEST_SUITE_REGISTRATION(UtilitiesTests)
The TestStatusProvider class helps testing the StatusProvider class.
void testStatusProvider()