-
Notifications
You must be signed in to change notification settings - Fork 342
/
test_unzip.cpp
99 lines (85 loc) · 2.95 KB
/
test_unzip.cpp
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
/*
* Class TestUnzip
*
* 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 "unziputil.h"
#include "test_unzip.h"
#include <QTemporaryDir>
QTemporaryDir *gTmpDir {nullptr};
void TestUnzip::initTestCase()
{
QDir::setCurrent("libmythbase/test/test_unzip");
gTmpDir = new QTemporaryDir();
QVERIFY(gTmpDir != nullptr);
gTmpDir->setAutoRemove(true);
}
// After each test case
void TestUnzip::cleanup()
{
QDir dir { gTmpDir->path() };
dir.removeRecursively();
dir.mkpath(dir.absolutePath());
}
// After all test cases
void TestUnzip::cleanupTestCase()
{
delete gTmpDir;
gTmpDir = nullptr;
}
void TestUnzip::test_text_file(void)
{
QString filename { "zipfiles/ipsum_lorem.zip" };
bool result = extractZIP(filename, gTmpDir->path());
QCOMPARE(result, true);
auto fi = QFileInfo(gTmpDir->path() + "/ipsum_lorem_p1.txt");
QCOMPARE(fi.exists(), true);
QCOMPARE(fi.size(), 755);
#if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
auto actualDateTime = QDateTime(QDate(2021,6,24),QTime(9,55,16));
QCOMPARE(fi.lastModified(), actualDateTime);
#endif
auto orig = QFile("data/ipsum_lorem_p1.txt");
orig.open(QIODevice::ReadOnly);
auto origData = orig.readAll();
auto unzipped = QFile(gTmpDir->path() + "/ipsum_lorem_p1.txt");
unzipped.open(QIODevice::ReadOnly);
auto unzippedData = unzipped.readAll();
QCOMPARE(origData, unzippedData);
}
void TestUnzip::test_theme_file(void)
{
QString filename { "zipfiles/themes.zip" };
bool result = extractZIP(filename, gTmpDir->path());
QCOMPARE(result, true);
auto fi = QFileInfo(gTmpDir->path() + "/trunk/Willi/themeinfo.xml");
QCOMPARE(fi.exists(), true);
QCOMPARE(fi.size(), 1461);
#if QT_VERSION >= QT_VERSION_CHECK(5,10,0)
auto actualDateTime = QDateTime(QDate(2013,7,14),QTime(16,00,56));
QCOMPARE(fi.lastModified(), actualDateTime);
#endif
auto orig = QFile("data/willi_themeinfo.xml");
orig.open(QIODevice::ReadOnly);
auto origData = orig.readAll();
auto unzipped = QFile(gTmpDir->path() + "/trunk/Willi/themeinfo.xml");
unzipped.open(QIODevice::ReadOnly);
auto unzippedData = unzipped.readAll();
QCOMPARE(origData, unzippedData);
}
QTEST_APPLESS_MAIN(TestUnzip)