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

Last change on this file since 1089 was 1050, checked in by s10k, 8 years ago
File size: 2.5 KB
Line 
1/*
2Copyright (C) 2005-2014 Sergey A. Tachenov
3
4This file is part of QuaZIP test suite.
5
6QuaZIP is free software: you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation, either version 2.1 of the License, or
9(at your option) any later version.
10
11QuaZIP is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
18
19See COPYING file for the full LGPL text.
20
21Original ZIP package is copyrighted by Gilles Vollant and contributors,
22see quazip/(un)zip.h files for details. Basically it's the zlib license.
23*/
24
25#include "testquagzipfile.h"
26#include <zlib.h>
27#include <QDir>
28#include <quazip/quagzipfile.h>
29#include <QtTest/QtTest>
30
31void TestQuaGzipFile::read()
32{
33 QDir curDir;
34 curDir.mkpath("tmp");
35 gzFile file = gzopen("tmp/test.gz", "wb");
36 gzwrite(file, "test", 4);
37 gzclose(file);
38 QuaGzipFile testFile("tmp/test.gz");
39 QVERIFY(testFile.open(QIODevice::ReadOnly));
40 char buf[5];
41 buf[4] = '\0';
42 QCOMPARE(testFile.read(buf, 5), static_cast<qint64>(4));
43 testFile.close();
44 QVERIFY(!testFile.isOpen());
45 QCOMPARE(static_cast<const char*>(buf), "test");
46 curDir.remove("tmp/test.gz");
47 curDir.rmdir("tmp");
48}
49
50void TestQuaGzipFile::write()
51{
52 QDir curDir;
53 curDir.mkpath("tmp");
54 QuaGzipFile testFile;
55 testFile.setFileName("tmp/test.gz");
56 QCOMPARE(testFile.getFileName(), QString::fromLatin1("tmp/test.gz"));
57 QVERIFY(testFile.open(QIODevice::WriteOnly));
58 QCOMPARE(testFile.write("test", 4), static_cast<qint64>(4));
59 QVERIFY(testFile.flush());
60 testFile.close();
61 QVERIFY(!testFile.isOpen());
62 gzFile file = gzopen("tmp/test.gz", "rb");
63 char buf[5];
64 buf[4] = '\0';
65 QCOMPARE(gzread(file, buf, 5), 4);
66 gzclose(file);
67 QCOMPARE(static_cast<const char*>(buf), "test");
68 curDir.remove("tmp/test.gz");
69 curDir.rmdir("tmp");
70}
71
72void TestQuaGzipFile::constructorDestructor()
73{
74 QuaGzipFile *f1 = new QuaGzipFile();
75 delete f1; // D0 destructor
76 QObject parent;
77 QuaGzipFile f2(&parent);
78 QuaGzipFile f3("test.gz", &parent);
79}
Note: See TracBrowser for help on using the repository browser.