1 /*
2 Copyright (C) 2005-2014 Sergey A. Tachenov
3 
4 This file is part of QuaZIP test suite.
5 
6 QuaZIP is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10 
11 QuaZIP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public License
17 along with QuaZIP.  If not, see <http://www.gnu.org/licenses/>.
18 
19 See COPYING file for the full LGPL text.
20 
21 Original ZIP package is copyrighted by Gilles Vollant and contributors,
22 see (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 <quagzipfile.h>
29 #include <QtTest/QtTest>
30 
read()31 void 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 
write()50 void 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 
constructorDestructor()72 void 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 }
80