Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test case for mythbinaryplist.
- Loading branch information
1 parent
e3a1bd6
commit 66a9d94
Showing
9 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test_mythbinaryplist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Example plist from: | ||
|
||
https://doc.qt.io/archives/qt-5.5/qtwebkitexamples-webkitwidgets-browser-info-mac-plist.html | ||
|
||
Converted to binary on a Mac Mini. |
Binary file not shown.
43 changes: 43 additions & 0 deletions
43
mythtv/libs/libmythbase/test/test_mythbinaryplist/info_mac.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> | ||
<plist version="0.9"> | ||
<dict> | ||
<key>CFBundleIconFile</key> | ||
<string>@ICON@</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleGetInfoString</key> | ||
<string>Created by Qt/QMake</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.trolltech.DemoBrowser</string> | ||
<key>CFBundleSignature</key> | ||
<string>ttxt</string> | ||
<key>CFBundleExecutable</key> | ||
<string>@EXECUTABLE@</string> | ||
<key>CFBundleDocumentTypes</key> | ||
<array> | ||
<dict> | ||
<key>CFBundleTypeExtensions</key> | ||
<array> | ||
<string>html</string> | ||
<string>htm</string> | ||
<string>shtml</string> | ||
<string>xht</string> | ||
<string>xhtml</string> | ||
</array> | ||
<key>CFBundleTypeIconFile</key> | ||
<string>@ICON@</string> | ||
<key>CFBundleTypeName</key> | ||
<string>HTML Document</string> | ||
<key>CFBundleTypeOSTypes</key> | ||
<array> | ||
<string>HTML</string> | ||
</array> | ||
<key>CFBundleTypeRole</key> | ||
<string>Viewer</string> | ||
</dict> | ||
</array> | ||
<key>NOTE</key> | ||
<string>DemoBrowser by The Qt Company Ltd.</string> | ||
</dict> | ||
</plist> |
Binary file added
BIN
+665 Bytes
mythtv/libs/libmythbase/test/test_mythbinaryplist/info_mac_addl.bplist
Binary file not shown.
51 changes: 51 additions & 0 deletions
51
mythtv/libs/libmythbase/test/test_mythbinaryplist/info_mac_addl.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> | ||
<plist version="0.9"> | ||
<dict> | ||
<key>CFBundleIconFile</key> | ||
<string>@ICON@</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleGetInfoString</key> | ||
<string>Created by Qt/QMake</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.trolltech.DemoBrowser</string> | ||
<key>CFBundleSignature</key> | ||
<string>ttxt</string> | ||
<key>CFBundleExecutable</key> | ||
<string>@EXECUTABLE@</string> | ||
<key>CFBundleDocumentTypes</key> | ||
<array> | ||
<dict> | ||
<key>CFBundleTypeExtensions</key> | ||
<array> | ||
<string>html</string> | ||
<string>htm</string> | ||
<string>shtml</string> | ||
<string>xht</string> | ||
<string>xhtml</string> | ||
</array> | ||
<key>CFBundleTypeIconFile</key> | ||
<string>@ICON@</string> | ||
<key>CFBundleTypeName</key> | ||
<string>HTML Document</string> | ||
<key>CFBundleTypeOSTypes</key> | ||
<array> | ||
<string>HTML</string> | ||
</array> | ||
<key>CFBundleTypeRole</key> | ||
<string>Viewer</string> | ||
</dict> | ||
</array> | ||
<key>NOTE</key> | ||
<string>DemoBrowser by The Qt Company Ltd.</string> | ||
<key>TestFloat</key> | ||
<real>3.1415926545897932</real> | ||
<key>TestFloat2</key> | ||
<real>3.1415926545897932</real> | ||
<key>TestDate</key> | ||
<date>2021-04-21T13:26:03Z</date> | ||
<key>TestDate2</key> | ||
<date>2021-04-21T13:26:03Z</date> | ||
</dict> | ||
</plist> |
136 changes: 136 additions & 0 deletions
136
mythtv/libs/libmythbase/test/test_mythbinaryplist/test_mythbinaryplist.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* Class TestMythBinaryPList | ||
* | ||
* Copyright (C) David Hampton 2021 | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
#include <iostream> | ||
#include "mythbinaryplist.h" | ||
#include "test_mythbinaryplist.h" | ||
|
||
static QDateTime test_datetime; | ||
|
||
// called at the beginning of these sets of tests | ||
void TestMythBinaryPList::initTestCase(void) | ||
{ | ||
QDir::setCurrent("libmythbase/test/test_mythbinaryplist"); | ||
|
||
auto date = QDate(2021, 4, 21); | ||
auto time = QTime(13, 26, 03); | ||
test_datetime = QDateTime(date, time, Qt::UTC); | ||
} | ||
|
||
// called at the end of these sets of tests | ||
void TestMythBinaryPList::cleanupTestCase(void) | ||
{ | ||
} | ||
|
||
// called before each test case | ||
void TestMythBinaryPList::init(void) | ||
{ | ||
} | ||
|
||
// called after each test case | ||
void TestMythBinaryPList::cleanup(void) | ||
{ | ||
} | ||
|
||
void TestMythBinaryPList::plist_read(void) | ||
{ | ||
// Read the file | ||
QFile file("info_mac_addl.bplist"); | ||
QCOMPARE(file.exists(), true); | ||
QCOMPARE(file.open(QIODevice::ReadOnly), true); | ||
QByteArray file_data = file.readAll(); | ||
//std::cerr << "file_data: " << file_data.constData() << std::endl; | ||
file.close(); | ||
|
||
// Parse it | ||
MythBinaryPList plist(file_data); | ||
//std::cerr << "plist: " << qPrintable(plist.ToString()) << std::endl; | ||
|
||
// Check values | ||
QVariant variant = plist.GetValue("CFBundleIconFile"); | ||
QVERIFY(variant.isValid()); | ||
QCOMPARE(variant.type(), QVariant::String); | ||
auto icon_name = variant.value<QString>(); | ||
QCOMPARE(icon_name, QString("@ICON@")); | ||
|
||
variant = plist.GetValue("CFBundleDocumentTypes"); | ||
QVERIFY(variant.isValid()); | ||
QCOMPARE(variant.type(), QVariant::List); | ||
auto list = variant.value<QVariantList>(); | ||
QCOMPARE(list.size(), 1); | ||
|
||
variant = list[0]; | ||
QVERIFY(variant.isValid()); | ||
QCOMPARE(variant.type(), QVariant::Map); | ||
auto map = variant.value<QVariantMap>(); | ||
QCOMPARE(map.size(), 5); | ||
|
||
QVERIFY(map.contains("CFBundleTypeExtensions")); | ||
QVariant variant2 = map["CFBundleTypeExtensions"]; | ||
QVERIFY(variant2.isValid()); | ||
QCOMPARE(variant2.type(), QVariant::List); | ||
auto list2 = variant2.value<QVariantList>(); | ||
QCOMPARE(list2.size(), 5); | ||
QVariant variant3 = list2[4]; | ||
QVERIFY(variant3.isValid()); | ||
QCOMPARE(variant3.type(), QVariant::String); | ||
auto ext_name = variant3.value<QString>(); | ||
QCOMPARE(ext_name, QString("xhtml")); | ||
|
||
QVERIFY(map.contains("CFBundleTypeRole")); | ||
auto role_name = map["CFBundleTypeRole"].value<QString>(); | ||
QCOMPARE(role_name, QString("Viewer")); | ||
|
||
// Test float twice. Catch conversion in place. | ||
variant = plist.GetValue("TestFloat"); | ||
QVERIFY(variant.isValid()); | ||
QCOMPARE(variant.type(), QVariant::Double); | ||
auto pi = variant.value<double>(); | ||
QCOMPARE(pi, 3.1415926545897932); | ||
variant = plist.GetValue("TestFloat"); | ||
QVERIFY(variant.isValid()); | ||
QCOMPARE(variant.type(), QVariant::Double); | ||
pi = variant.value<double>(); | ||
QCOMPARE(pi, 3.1415926545897932); | ||
variant = plist.GetValue("TestFloat2"); | ||
QVERIFY(variant.isValid()); | ||
QCOMPARE(variant.type(), QVariant::Double); | ||
pi = variant.value<double>(); | ||
QCOMPARE(pi, 3.1415926545897932); | ||
|
||
// Check dates | ||
variant = plist.GetValue("TestDate"); | ||
QVERIFY(variant.isValid()); | ||
QCOMPARE(variant.type(), QVariant::DateTime); | ||
auto when = variant.value<QDateTime>(); | ||
QCOMPARE(when, test_datetime); | ||
variant = plist.GetValue("TestDate"); | ||
QVERIFY(variant.isValid()); | ||
QCOMPARE(variant.type(), QVariant::DateTime); | ||
when = variant.value<QDateTime>(); | ||
QCOMPARE(when, test_datetime); | ||
variant = plist.GetValue("TestDate2"); | ||
QVERIFY(variant.isValid()); | ||
QCOMPARE(variant.type(), QVariant::DateTime); | ||
when = variant.value<QDateTime>(); | ||
QCOMPARE(when, test_datetime); | ||
} | ||
|
||
|
||
QTEST_APPLESS_MAIN(TestMythBinaryPList) |
36 changes: 36 additions & 0 deletions
36
mythtv/libs/libmythbase/test/test_mythbinaryplist/test_mythbinaryplist.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Class TestMythBinaryPList | ||
* | ||
* Copyright (C) David Hampton 2021 | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include <QtTest/QtTest> | ||
|
||
class TestMythBinaryPList: public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
private slots: | ||
// Functions to setup/cleanup or reset between tests | ||
static void initTestCase(void); | ||
static void cleanupTestCase(void); | ||
static void init(void); | ||
static void cleanup(void); | ||
|
||
// Individual function tests | ||
static void plist_read(void); | ||
}; |
19 changes: 19 additions & 0 deletions
19
mythtv/libs/libmythbase/test/test_mythbinaryplist/test_mythbinaryplist.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
include ( ../../../../settings.pro ) | ||
include ( ../../../../test.pro ) | ||
|
||
QT += xml sql network testlib | ||
|
||
TEMPLATE = app | ||
TARGET = test_mythbinaryplist | ||
DEPENDPATH += . ../.. | ||
INCLUDEPATH += . ../.. | ||
LIBS += -L../.. -lmythbase-$$LIBVERSION | ||
|
||
# Input | ||
HEADERS += test_mythbinaryplist.h | ||
SOURCES += test_mythbinaryplist.cpp | ||
|
||
QMAKE_CLEAN += $(TARGET) $(TARGETA) $(TARGETD) $(TARGET0) $(TARGET1) $(TARGET2) | ||
QMAKE_CLEAN += ; ( cd $(OBJECTS_DIR) && rm -f *.gcov *.gcda *.gcno ) | ||
|
||
LIBS += $$EXTRA_LIBS $$LATE_LIBS |