Changeset View
Changeset View
Standalone View
Standalone View
autotests/rccpackagetest.cpp
- This file was added.
1 | /****************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright 2007 by Aaron Seigo <aseigo@kde.org> * | ||||
3 | * Copyright 2014 Marco Martin <mart@kde.org> * | ||||
4 | * * | ||||
5 | * This library is free software; you can redistribute it and/or * | ||||
6 | * modify it under the terms of the GNU Library General Public * | ||||
7 | * License as published by the Free Software Foundation; either * | ||||
8 | * version 2 of the License, or (at your option) any later version. * | ||||
9 | * * | ||||
10 | * This library is distributed in the hope that it will be useful, * | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * | ||||
13 | * Library General Public License for more details. * | ||||
14 | * * | ||||
15 | * You should have received a copy of the GNU Library General Public License * | ||||
16 | * along with this library; see the file COPYING.LIB. If not, write to * | ||||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * | ||||
18 | * Boston, MA 02110-1301, USA. * | ||||
19 | *******************************************************************************/ | ||||
20 | | ||||
21 | #include "rccpackagetest.h" | ||||
22 | | ||||
23 | | ||||
24 | #include <QDebug> | ||||
25 | | ||||
26 | #include <klocalizedstring.h> | ||||
27 | #include "packagestructure.h" | ||||
28 | #include "plasmoidstructure.h" | ||||
29 | #include "packageloader.h" | ||||
30 | | ||||
31 | void RccPackageTest::initTestCase() | ||||
32 | { | ||||
33 | QStandardPaths::enableTestMode(true); | ||||
34 | | ||||
35 | QString destination = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/plasma/plasmoids/testpackage-rcc/"); | ||||
36 | QDir dir; | ||||
37 | dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); | ||||
38 | dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/plasma/")); | ||||
39 | dir.mkpath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/plasma/plasmoids/")); | ||||
40 | dir.mkpath(destination); | ||||
41 | QVERIFY(dir.exists(destination)); | ||||
42 | | ||||
43 | //verify the source files exist | ||||
44 | QVERIFY(QFile::exists(QStringLiteral("./autotests/testpackage-rcc/metadata.json"))); | ||||
45 | QVERIFY(QFile::exists(QStringLiteral("./autotests/testpackage-rcc/contents.rcc"))); | ||||
46 | | ||||
47 | QFile::copy(QStringLiteral("./autotests/testpackage-rcc/metadata.json"), destination + QStringLiteral("metadata.json")); | ||||
48 | QFile::copy(QStringLiteral("./autotests/testpackage-rcc/contents.rcc"), destination + QStringLiteral("contents.rcc")); | ||||
49 | | ||||
50 | //verify they have been copied correctly | ||||
51 | QVERIFY(QFile::exists(destination + QStringLiteral("metadata.json"))); | ||||
52 | QVERIFY(QFile::exists(destination + QStringLiteral("contents.rcc"))); | ||||
53 | | ||||
54 | m_packagePath = "testpackage-rcc"; | ||||
55 | m_pkg = new KPackage::Package(new KPackage::PlasmoidPackage); | ||||
56 | m_pkg->setPath(m_packagePath); | ||||
57 | //Two package instances with the same resource | ||||
58 | m_pkg2 = new KPackage::Package(new KPackage::PlasmoidPackage); | ||||
59 | m_pkg2->setPath(m_packagePath); | ||||
60 | } | ||||
61 | | ||||
62 | void RccPackageTest::cleanupTestCase() | ||||
63 | { | ||||
64 | qDebug() << "cleaning up"; | ||||
65 | // Clean things up. | ||||
66 | QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).removeRecursively(); | ||||
67 | } | ||||
68 | | ||||
69 | void RccPackageTest::accessFiles() | ||||
70 | { | ||||
71 | QVERIFY(m_pkg->hasValidStructure()); | ||||
72 | QVERIFY(m_pkg->hasValidStructure()); | ||||
73 | | ||||
74 | //check for existence of all files | ||||
75 | QVERIFY(!m_pkg->filePath("ui", QStringLiteral("main.qml")).isEmpty()); | ||||
76 | QVERIFY(!m_pkg->filePath("ui", QStringLiteral("otherfile.qml")).isEmpty()); | ||||
77 | QVERIFY(!m_pkg->filePath("images", QStringLiteral("empty.png")).isEmpty()); | ||||
78 | | ||||
79 | QVERIFY(!m_pkg2->filePath("ui", QStringLiteral("main.qml")).isEmpty()); | ||||
80 | QVERIFY(!m_pkg2->filePath("ui", QStringLiteral("otherfile.qml")).isEmpty()); | ||||
81 | QVERIFY(!m_pkg2->filePath("images", QStringLiteral("empty.png")).isEmpty()); | ||||
82 | } | ||||
83 | | ||||
84 | void RccPackageTest::validate() | ||||
85 | { | ||||
86 | QCOMPARE(m_pkg->cryptographicHash(QCryptographicHash::Sha1), QStringLiteral("ed0959c062b7ef7eaab5243e83e2f9afe5b3b15f")); | ||||
87 | QCOMPARE(m_pkg2->cryptographicHash(QCryptographicHash::Sha1), QStringLiteral("ed0959c062b7ef7eaab5243e83e2f9afe5b3b15f")); | ||||
88 | } | ||||
89 | | ||||
90 | void RccPackageTest::testResourceRefCount() | ||||
91 | { | ||||
92 | delete m_pkg; | ||||
93 | m_pkg = nullptr; | ||||
94 | | ||||
95 | QVERIFY(m_pkg2->isValid()); | ||||
96 | QVERIFY(QFile::exists(QStringLiteral(":/plasma/plasmoids/testpackage-rcc/contents/ui/main.qml"))); | ||||
97 | | ||||
98 | //no reference from this package anymore | ||||
99 | delete m_pkg2; | ||||
100 | m_pkg2 = nullptr; | ||||
101 | QVERIFY(!QFile::exists(QStringLiteral(":/plasma/plasmoids/testpackage-rcc/contents/ui/main.qml"))); | ||||
102 | } | ||||
103 | | ||||
104 | QTEST_MAIN(RccPackageTest) | ||||
105 | |