source: Vago/Libs/quazip-0.7.2/qztest/testquazipfileinfo.cpp@ 1089

Last change on this file since 1089 was 1050, checked in by s10k, 8 years ago
File size: 3.7 KB
Line 
1#include "testquazipfileinfo.h"
2
3#include "qztest.h"
4
5#include <QByteArray>
6#include <QDir>
7#include <QFileInfo>
8
9#include <QtTest/QtTest>
10
11#include "quazip/quazip.h"
12#include "quazip/quazipfile.h"
13#include "quazip/quazipfileinfo.h"
14#include "quazip/quazipnewinfo.h"
15
16TestQuaZipFileInfo::TestQuaZipFileInfo(QObject *parent) :
17 QObject(parent)
18{
19}
20
21void TestQuaZipFileInfo::getNTFSTime()
22{
23 QString zipName = "newtimes.zip";
24 QStringList testFiles;
25 testFiles << "test.txt";
26 QDir curDir;
27 if (curDir.exists(zipName)) {
28 if (!curDir.remove(zipName))
29 QFAIL("Can't remove zip file");
30 }
31 if (!createTestFiles(testFiles)) {
32 QFAIL("Can't create test file");
33 }
34 QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
35 quint64 mTicks, aTicks, cTicks;
36 QFileInfo fileInfo("tmp/test.txt");
37 {
38 // create
39 QuaZip zip(zipName);
40 QVERIFY(zip.open(QuaZip::mdCreate));
41 QuaZipFile zipFile(&zip);
42 QDateTime lm = fileInfo.lastModified().toUTC();
43 QDateTime lr = fileInfo.lastRead().toUTC();
44 QDateTime cr = fileInfo.created().toUTC();
45 mTicks = (static_cast<qint64>(base.date().daysTo(lm.date()))
46 * Q_UINT64_C(86400000)
47 + static_cast<qint64>(base.time().msecsTo(lm.time())))
48 * Q_UINT64_C(10000);
49 aTicks = (static_cast<qint64>(base.date().daysTo(lr.date()))
50 * Q_UINT64_C(86400000)
51 + static_cast<qint64>(base.time().msecsTo(lr.time())))
52 * Q_UINT64_C(10000);
53 cTicks = (static_cast<qint64>(base.date().daysTo(cr.date()))
54 * Q_UINT64_C(86400000)
55 + static_cast<qint64>(base.time().msecsTo(cr.time())))
56 * Q_UINT64_C(10000);
57 QuaZipNewInfo newInfo("test.txt", "tmp/test.txt");
58 QByteArray extra(36, 0);
59 extra[0] = 0x0A; // magic
60 extra[1] = 0x00;
61 extra[2] = 32; // size
62 extra[3] = 0;
63 extra[4] = extra[5] = extra[6] = extra[7] = 0; // reserved
64 extra[8] = 0x01; // time tag
65 extra[9] = 0x00;
66 extra[10] = 24; // time tag size
67 extra[11] = 0;
68 for (int i = 12; i < 36; i += 8) {
69 quint64 ticks;
70 if (i == 12) {
71 ticks = mTicks;
72 } else if (i == 20) {
73 ticks = aTicks;
74 } else if (i == 28) {
75 ticks = cTicks;
76 } else {
77 QFAIL("Stupid programming bug here");
78 }
79 extra[i] = static_cast<char>(ticks);
80 extra[i + 1] = static_cast<char>(ticks >> 8);
81 extra[i + 2] = static_cast<char>(ticks >> 16);
82 extra[i + 3] = static_cast<char>(ticks >> 24);
83 extra[i + 4] = static_cast<char>(ticks >> 32);
84 extra[i + 5] = static_cast<char>(ticks >> 40);
85 extra[i + 6] = static_cast<char>(ticks >> 48);
86 extra[i + 7] = static_cast<char>(ticks >> 56);
87 }
88 newInfo.extraLocal = extra;
89 newInfo.extraGlobal = extra;
90 QVERIFY(zipFile.open(QIODevice::WriteOnly, newInfo));
91 zipFile.close();
92 zip.close();
93 }
94 {
95 // check
96 QuaZip zip(zipName);
97 QVERIFY(zip.open(QuaZip::mdUnzip));
98 zip.goToFirstFile();
99 QuaZipFileInfo64 zipFileInfo;
100 QVERIFY(zip.getCurrentFileInfo(&zipFileInfo));
101 zip.close();
102 QCOMPARE(zipFileInfo.getNTFSmTime(), fileInfo.lastModified());
103 QCOMPARE(zipFileInfo.getNTFSaTime(), fileInfo.lastRead());
104 QCOMPARE(zipFileInfo.getNTFScTime(), fileInfo.created());
105 }
106 removeTestFiles(testFiles);
107 curDir.remove(zipName);
108}
Note: See TracBrowser for help on using the repository browser.