summaryrefslogtreecommitdiffstats
path: root/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp')
-rw-r--r--tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp114
1 files changed, 59 insertions, 55 deletions
diff --git a/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp b/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp
index 75b7bf148..ffc5b330a 100644
--- a/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp
+++ b/tests/auto/installer/lib7zfacade/tst_lib7zfacade.cpp
@@ -26,8 +26,10 @@
**
**************************************************************************/
-#include "init.h"
-#include "lib7z_facade.h"
+#include <lib7z_create.h>
+#include <lib7z_extract.h>
+#include <lib7z_facade.h>
+#include <lib7z_list.h>
#include <QDir>
#include <QObject>
@@ -41,7 +43,7 @@ class tst_lib7zfacade : public QObject
private slots:
void initTestCase()
{
- QInstaller::init();
+ Lib7z::initSevenZ();
m_file.path = "valid";
m_file.permissions = 0;
@@ -49,7 +51,7 @@ private slots:
m_file.uncompressedSize = 5242880;
m_file.isDirectory = false;
m_file.archiveIndex = QPoint(0, 0);
- m_file.mtime = QDateTime(QDate::fromJulianDay(2456413), QTime(12, 50, 42));
+ m_file.utcTime = QDateTime(QDate::fromJulianDay(2456413), QTime(10, 50, 42), Qt::UTC);
}
void testIsSupportedArchive()
@@ -57,109 +59,111 @@ private slots:
QCOMPARE(Lib7z::isSupportedArchive(":///data/valid.7z"), true);
QCOMPARE(Lib7z::isSupportedArchive(":///data/invalid.7z"), false);
- {
+ try {
QFile file(":///data/valid.7z");
QVERIFY(file.open(QIODevice::ReadOnly));
QCOMPARE(Lib7z::isSupportedArchive(&file), true);
+ } catch (...) {
+ QFAIL("Unexpected error during Lib7z::isSupportedArchive.");
}
- {
+ try {
QFile file(":///data/invalid.7z");
QVERIFY(file.open(QIODevice::ReadOnly));
QCOMPARE(Lib7z::isSupportedArchive(&file), false);
+ } catch (...) {
+ QFAIL("Unexpected error during Lib7z::isSupportedArchive.");
}
}
void testListArchive()
{
- // TODO: this should work without scope, there's a bug in Lib7z::OpenArchiveInfo
- // caused by the fact that we keep a pointer to the device, not the devices target
- {
+ try {
QFile file(":///data/valid.7z");
QVERIFY(file.open(QIODevice::ReadOnly));
QVector<Lib7z::File> files = Lib7z::listArchive(&file);
QCOMPARE(files.count(), 1);
-#ifdef Q_OS_UNIX
- QSKIP("This test requires the time handling to be repaired first.");
-#endif
QCOMPARE(files.first(), m_file);
+ } catch (...) {
+ QFAIL("Unexpected error during list archive.");
}
- {
- try {
- QFile file(":///data/invalid.7z");
- QVERIFY(file.open(QIODevice::ReadOnly));
- QVector<Lib7z::File> files = Lib7z::listArchive(&file);
- } catch (const Lib7z::SevenZipException& e) {
- QCOMPARE(e.message(), QString("Could not open archive"));
- } catch (...) {
- QFAIL("Unexpected error during list archive!");
- }
+ try {
+ QFile file(":///data/invalid.7z");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVector<Lib7z::File> files = Lib7z::listArchive(&file);
+ } catch (const Lib7z::SevenZipException& e) {
+ QCOMPARE(e.message(), QString("Cannot open archive \":///data/invalid.7z\"."));
+ } catch (...) {
+ QFAIL("Unexpected error during list archive.");
}
}
void testCreateArchive()
{
- QTemporaryFile target;
- QVERIFY(target.open());
-
try {
- // TODO: we do not get any information about success
- Lib7z::createArchive(&target, QStringList() << ":///data/invalid.7z");
+ const QString path = tempSourceFile("Source File 1.");
+ const QString path2 = tempSourceFile("Source File 2.");
+
+ QTemporaryFile target;
+ QVERIFY(target.open());
+ Lib7z::createArchive(&target, QStringList() << path << path2);
+ QCOMPARE(Lib7z::listArchive(&target).count(), 2);
} catch (const Lib7z::SevenZipException& e) {
QFAIL(e.message().toUtf8());
} catch (...) {
- QFAIL("Unexpected error during create archive!");
+ QFAIL("Unexpected error during create archive.");
}
- }
-
- void testExtractArchive()
- {
- QFile source(":///data/valid.7z");
- QVERIFY(source.open(QIODevice::ReadOnly));
try {
- // TODO: we do not get any information about success
- Lib7z::extractArchive(&source, QDir::tempPath());
+ const QString path1 = tempSourceFile(
+ "Source File 1.",
+ QDir::tempPath() + "/temp file with spaces.XXXXXX"
+ );
+ const QString path2 = tempSourceFile(
+ "Source File 2.",
+ QDir::tempPath() + "/temp file with spaces.XXXXXX"
+ );
+
+ QTemporaryFile target(QDir::tempPath() + "/target file with spaces.XXXXXX");
+ QVERIFY(target.open());
+ Lib7z::createArchive(&target, QStringList() << path1 << path2);
+ QCOMPARE(Lib7z::listArchive(&target).count(), 2);
} catch (const Lib7z::SevenZipException& e) {
QFAIL(e.message().toUtf8());
} catch (...) {
- QFAIL("Unexpected error during extract archive!");
+ QFAIL("Unexpected error during create archive.");
}
+
}
- void testExtractFileFromArchive()
+ void testExtractArchive()
{
QFile source(":///data/valid.7z");
QVERIFY(source.open(QIODevice::ReadOnly));
- QTemporaryFile target;
- QVERIFY(target.open());
-
try {
- // TODO: we do not get any information about success
- Lib7z::extractFileFromArchive(&source, m_file, &target);
+ Lib7z::extractArchive(&source, QDir::tempPath());
+ QCOMPARE(QFile::exists(QDir::tempPath() + QString("/valid")), true);
} catch (const Lib7z::SevenZipException& e) {
QFAIL(e.message().toUtf8());
} catch (...) {
- QFAIL("Unexpected error during extract file from archive!");
+ QFAIL("Unexpected error during extract archive.");
}
}
- void testExtractFileFromArchive2()
+private:
+ QString tempSourceFile(const QByteArray &data, const QString &templateName = QString())
{
- QFile source(":///data/valid.7z");
- QVERIFY(source.open(QIODevice::ReadOnly));
-
- try {
- // TODO: we do not get any information about success
- Lib7z::extractFileFromArchive(&source, m_file, QDir::tempPath());
- } catch (const Lib7z::SevenZipException& e) {
- QFAIL(e.message().toUtf8());
- } catch (...) {
- QFAIL("Unexpected error during extract file from archive!");
+ QTemporaryFile source;
+ if (!templateName.isEmpty()) {
+ source.setFileTemplate(templateName);
}
+ source.open();
+ source.write(data);
+ source.setAutoRemove(false);
+ return source.fileName();
}
private: