swift
testcompress.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
11 #include <QFileInfo>
12 #include <QObject>
13 #include <QTemporaryDir>
14 #include <QTest>
15 
16 #include "test.h"
17 
18 #include "config/buildconfig.h"
19 #include "misc/compressutils.h"
20 #include "misc/directoryutils.h"
21 #include "misc/fileutils.h"
22 #include "misc/swiftdirectories.h"
23 
24 using namespace swift::misc;
25 using namespace swift::config;
26 
27 namespace MiscTest
28 {
30  class CTestCompress : public QObject
31  {
32  Q_OBJECT
33 
34  public:
36  explicit CTestCompress(QObject *parent = nullptr) : QObject(parent) {}
37 
39  virtual ~CTestCompress() {}
40 
41  private slots:
43  void uncompressFile();
44  };
45 
46  void CTestCompress::uncompressFile()
47  {
48  QTemporaryDir tempDir;
49  tempDir.setAutoRemove(true);
50  QVERIFY2(tempDir.isValid(), "Invalid directory");
51 
52  const bool win = CBuildConfig::isRunningOnWindowsNtPlatform();
53  const bool zip7Exists = CCompressUtils::hasZip7();
54  if (!win && !zip7Exists)
55  {
56  QSKIP("No 7zip, skipping");
57  return;
58  }
59 
60  QVERIFY2(zip7Exists, "No 7zip");
61 
62  const QString td = tempDir.path();
63  const QString compressedFile(
65  const QString unCompressedFile(CFileUtils::appendFilePaths(td, "countries.json"));
66  const bool c = CCompressUtils::zip7Uncompress(compressedFile, td);
67 
68  QVERIFY2(c, "Uncompressing failed");
69 
70  const QFileInfo check(unCompressedFile);
71  QVERIFY2(check.size() > 1000, "Uncompressing yielded not data");
72  QVERIFY2(check.exists(), "Uncompressed file does not exist");
73  QVERIFY2(check.isReadable(), "Not readable");
74 
75  qDebug() << "Uncompressed" << compressedFile << "to" << unCompressedFile << "with size" << check.size();
76  }
77 } // namespace MiscTest
78 
81 
82 #include "testcompress.moc"
83 
Testing process tools.
virtual ~CTestCompress()
Destructor.
CTestCompress(QObject *parent=nullptr)
Constructor.
static bool zip7Uncompress(const QString &file, const QString &directory, QStringList *stdOutAndError=nullptr)
Unzip my using 7zip.
static bool hasZip7(QStringList *stdOutAndError=nullptr)
External program existing?
static QString appendFilePaths(const QString &path1, const QString &path2)
Append file paths.
Definition: fileutils.cpp:95
static const QString & shareTestDirectory()
The test data directory.
Free functions in swift::misc.
SWIFTTEST_MAIN(MiscTest::CTestCompress)
main