summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@digia.com>2014-01-17 14:34:57 +0100
committerTim Jenssen <tim.jenssen@digia.com>2014-01-17 14:36:23 +0100
commitfe92a09482c5abf7f2c56901f2d60e287282f939 (patch)
treefbfcefcc6f86dd2980b6b5816dece03664c57a76 /tests
parent0b5241a696cf05612dae2c8810022f5e205d42df (diff)
parentfaa8f39bdd8c13b21c19bec1592f18e710c56206 (diff)
Merge remote-tracking branch 'origin/1.5'
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/installer/binaryformat/binaryformat.pro5
-rw-r--r--tests/auto/installer/binaryformat/tst_binaryformat.cpp115
-rw-r--r--tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp6
-rw-r--r--tests/auto/installer/installer.pro6
-rw-r--r--tests/auto/installer/packagemanagercore/installer-config/config.xml5
-rw-r--r--tests/auto/installer/packagemanagercore/packagemanagercore.pro10
-rw-r--r--tests/auto/installer/packagemanagercore/settings.qrc5
-rw-r--r--tests/auto/installer/packagemanagercore/tst_packagemanagercore.cpp153
-rw-r--r--tests/auto/installer/scriptengine/tst_scriptengine.cpp14
-rw-r--r--tests/auto/installer/settingsoperation/settingsoperation.pro6
-rw-r--r--tests/auto/installer/settingsoperation/tst_settingsoperation.cpp328
-rw-r--r--tests/downloadspeed/main.cpp1
12 files changed, 641 insertions, 13 deletions
diff --git a/tests/auto/installer/binaryformat/binaryformat.pro b/tests/auto/installer/binaryformat/binaryformat.pro
new file mode 100644
index 000000000..24a7899ce
--- /dev/null
+++ b/tests/auto/installer/binaryformat/binaryformat.pro
@@ -0,0 +1,5 @@
+include(../../qttest.pri)
+
+QT -= gui
+
+SOURCES += tst_binaryformat.cpp
diff --git a/tests/auto/installer/binaryformat/tst_binaryformat.cpp b/tests/auto/installer/binaryformat/tst_binaryformat.cpp
new file mode 100644
index 000000000..59f0e8e03
--- /dev/null
+++ b/tests/auto/installer/binaryformat/tst_binaryformat.cpp
@@ -0,0 +1,115 @@
+/**************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+**************************************************************************/
+
+#include <binaryformat.h>
+#include <errors.h>
+#include <fileutils.h>
+
+#include <QTest>
+#include <QTemporaryFile>
+
+static const qint64 scTinySize = 72704LL;
+static const qint64 scSmallSize = 524288LL;
+static const qint64 scLargeSize = 2097152LL;
+
+class tst_BinaryFormat : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void findMagicCookieSmallFile()
+ {
+ QTemporaryFile file;
+ file.open();
+
+ try {
+ QInstaller::blockingWrite(&file, QByteArray(scSmallSize, '1'));
+ QInstaller::appendInt64(&file, QInstaller::MagicCookie);
+
+ QCOMPARE(QInstaller::findMagicCookie(&file, QInstaller::MagicCookie), scSmallSize);
+ } catch (const QInstaller::Error &error) {
+ QFAIL(qPrintable(error.message()));
+ } catch (...) {
+ QFAIL("Unexpected error.");
+ }
+ }
+
+ void findMagicCookieLargeFile()
+ {
+ QTemporaryFile file;
+ file.open();
+
+ try {
+ QInstaller::blockingWrite(&file, QByteArray(scLargeSize, '1'));
+ QInstaller::appendInt64(&file, QInstaller::MagicCookie);
+ QInstaller::blockingWrite(&file, QByteArray(scTinySize, '2'));
+
+ QCOMPARE(QInstaller::findMagicCookie(&file, QInstaller::MagicCookie), scLargeSize);
+ } catch (const QInstaller::Error &error) {
+ QFAIL(qPrintable(error.message()));
+ } catch (...) {
+ QFAIL("Unexpected error.");
+ }
+ }
+
+ void testFindMagicCookieWithError()
+ {
+ QTest::ignoreMessage(QtDebugMsg, "create Error-Exception: \"No marker found, stopped after 71.00 KiB.\" ");
+
+ QTemporaryFile file;
+ file.open();
+
+ try {
+ QInstaller::blockingWrite(&file, QByteArray(scTinySize, '1'));
+
+ // throws
+ QInstaller::findMagicCookie(&file, QInstaller::MagicCookie);
+ } catch (const QInstaller::Error &error) {
+ QCOMPARE(qPrintable(error.message()), "No marker found, stopped after 71.00 KiB.");
+ } catch (...) {
+ QFAIL("Unexpected error.");
+ }
+ }
+};
+
+QTEST_MAIN(tst_BinaryFormat)
+
+#include "tst_binaryformat.moc"
diff --git a/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp b/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp
index 61d24a2ad..505d00c53 100644
--- a/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp
+++ b/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp
@@ -39,9 +39,9 @@
**
**************************************************************************/
-#include "init.h"
-#include "kdupdaterupdateoperations.h"
-#include "utils.h"
+#include <init.h>
+#include <kdupdaterupdateoperations.h>
+#include <utils.h>
#include <QDir>
#include <QObject>
diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro
index 5873a8db8..f4c4bbaf4 100644
--- a/tests/auto/installer/installer.pro
+++ b/tests/auto/installer/installer.pro
@@ -12,5 +12,7 @@ SUBDIRS += \
consumeoutputoperationtest \
mkdiroperationtest \
copyoperationtest \
- solver
-
+ solver \
+ binaryformat \
+ packagemanagercore \
+ settingsoperation
diff --git a/tests/auto/installer/packagemanagercore/installer-config/config.xml b/tests/auto/installer/packagemanagercore/installer-config/config.xml
new file mode 100644
index 000000000..adc24631b
--- /dev/null
+++ b/tests/auto/installer/packagemanagercore/installer-config/config.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Installer>
+ <Name>test</Name>
+ <Version>1.0.0</Version>
+</Installer>
diff --git a/tests/auto/installer/packagemanagercore/packagemanagercore.pro b/tests/auto/installer/packagemanagercore/packagemanagercore.pro
new file mode 100644
index 000000000..c78393540
--- /dev/null
+++ b/tests/auto/installer/packagemanagercore/packagemanagercore.pro
@@ -0,0 +1,10 @@
+include(../../qttest.pri)
+
+QT += script
+lessThan(QT_MAJOR_VERSION, 5) {
+ QT -= gui
+}
+SOURCES += tst_packagemanagercore.cpp
+
+RESOURCES += \
+ settings.qrc
diff --git a/tests/auto/installer/packagemanagercore/settings.qrc b/tests/auto/installer/packagemanagercore/settings.qrc
new file mode 100644
index 000000000..b25a589a3
--- /dev/null
+++ b/tests/auto/installer/packagemanagercore/settings.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/metadata">
+ <file>installer-config/config.xml</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/installer/packagemanagercore/tst_packagemanagercore.cpp b/tests/auto/installer/packagemanagercore/tst_packagemanagercore.cpp
new file mode 100644
index 000000000..8a7af4a0b
--- /dev/null
+++ b/tests/auto/installer/packagemanagercore/tst_packagemanagercore.cpp
@@ -0,0 +1,153 @@
+/**************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+**************************************************************************/
+
+#include <binaryformat.h>
+#include <component.h>
+#include <errors.h>
+#include <fileutils.h>
+#include <packagemanagercore.h>
+#include <progresscoordinator.h>
+
+#include <QDir>
+#include <QTemporaryFile>
+#include <QTest>
+
+using namespace QInstaller;
+
+class DummyComponent : public Component
+{
+public:
+ DummyComponent(PackageManagerCore *core)
+ : Component(core)
+ {
+ setCheckState(Qt::Checked);
+ }
+
+ void beginInstallation()
+ {
+ throw Error(tr("Force crash to test rollback!"));
+ }
+
+ ~DummyComponent()
+ {
+ }
+};
+
+class tst_PackageManagerCore : public QObject
+{
+ Q_OBJECT
+
+private:
+ void setIgnoreMessage(const QString &testDirectory)
+ {
+ const QString message = "\"\t- arguments: %1\" ";
+ QTest::ignoreMessage(QtDebugMsg, "\"backup operation: Mkdir\" ");
+ QTest::ignoreMessage(QtDebugMsg, qPrintable(message.arg(testDirectory)));
+ QTest::ignoreMessage(QtDebugMsg, qPrintable(message.arg(testDirectory)));
+ QTest::ignoreMessage(QtDebugMsg, qPrintable(message.arg(testDirectory)));
+ QTest::ignoreMessage(QtDebugMsg, "\"perform operation: Mkdir\" ");
+ QTest::ignoreMessage(QtDebugMsg, "Install size: 1 components ");
+ QTest::ignoreMessage(QtDebugMsg, "create Error-Exception: \"Force crash to test rollback!\" ");
+ QTest::ignoreMessage(QtDebugMsg, "\"created critical message box installationError: 'Error"
+ "', Force crash to test rollback!\" ");
+ QTest::ignoreMessage(QtDebugMsg, "ROLLING BACK operations= 1 ");
+ QTest::ignoreMessage(QtDebugMsg, "\"undo operation: Mkdir\" ");
+ QTest::ignoreMessage(QtDebugMsg, "Done ");
+ QTest::ignoreMessage(QtDebugMsg, "Done ");
+ QTest::ignoreMessage(QtDebugMsg, "Done ");
+ }
+
+private slots:
+ void testRollBackInstallationKeepTarget()
+ {
+
+ const QString testDirectory = QInstaller::generateTemporaryFileName();
+ QVERIFY(QDir().mkpath(testDirectory));
+
+ setIgnoreMessage(testDirectory);
+
+ PackageManagerCore core(MagicInstallerMarker);
+ // cancel the installer in error case
+ core.autoRejectMessageBoxes();
+ core.appendRootComponent(new DummyComponent(&core));
+ core.setValue(QLatin1String("TargetDir"), testDirectory);
+ core.setValue(QLatin1String("RemoveTargetDir"), QLatin1String("true"));
+
+ QVERIFY(core.calculateComponentsToInstall());
+ {
+ QTemporaryFile dummy(testDirectory + QLatin1String("/dummy"));
+ dummy.open();
+
+ core.runInstaller();
+
+ QVERIFY(QDir(testDirectory).exists());
+ QVERIFY(QFileInfo(dummy.fileName()).exists());
+ }
+ QDir().rmdir(testDirectory);
+ ProgressCoordinator::instance()->reset();
+ }
+
+ void testRollBackInstallationRemoveTarget()
+ {
+ const QString testDirectory = QInstaller::generateTemporaryFileName();
+ QVERIFY(QDir().mkpath(testDirectory));
+
+ setIgnoreMessage(testDirectory);
+
+ PackageManagerCore core(MagicInstallerMarker);
+ // cancel the installer in error case
+ core.autoRejectMessageBoxes();
+ core.appendRootComponent(new DummyComponent(&core));
+ core.setValue(QLatin1String("TargetDir"), testDirectory);
+ core.setValue(QLatin1String("RemoveTargetDir"), QLatin1String("true"));
+
+ QVERIFY(core.calculateComponentsToInstall());
+
+ core.runInstaller();
+ QVERIFY(!QDir(testDirectory).exists());
+ ProgressCoordinator::instance()->reset();
+ }
+};
+
+
+QTEST_MAIN(tst_PackageManagerCore)
+
+#include "tst_packagemanagercore.moc"
diff --git a/tests/auto/installer/scriptengine/tst_scriptengine.cpp b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
index 283d7bdad..5c67afd0c 100644
--- a/tests/auto/installer/scriptengine/tst_scriptengine.cpp
+++ b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
@@ -26,9 +26,9 @@ public:
virtual void init() {}
- void callProtectedDelayedControlScriptExecution(int id)
+ void callProtectedDelayedExecuteControlScript(int id)
{
- delayedControlScriptExecution(id);
+ executeControlScript(id);
}
};
@@ -61,7 +61,7 @@ private slots:
m_component->setValue("Default", "Script");
m_component->setValue(scName, "component.test.name");
- m_scriptEngine = m_core.scriptEngine();
+ m_scriptEngine = m_core.componentScriptEngine();
}
void testBrokenJSMethodConnect()
@@ -218,18 +218,16 @@ private slots:
testGui.loadControlScript(":///data/auto-install.qs");
QCOMPARE(m_core.value("GuiTestValue"), QString("hello"));
- testGui.show();
// show event calls automatically the first callback which does not exist
setExpectedScriptOutput("Control script callback \"IntroductionPageCallback\" does not exist. ");
- // give some time to the event triggering mechanism
- qApp->processEvents();
+ testGui.show();
// inside the auto-install script we are clicking the next button, with a not existing button
QTest::ignoreMessage(QtWarningMsg, "Button with type: \"unknown button\" not found! ");
- testGui.callProtectedDelayedControlScriptExecution(PackageManagerCore::ComponentSelection);
+ testGui.callProtectedDelayedExecuteControlScript(PackageManagerCore::ComponentSelection);
setExpectedScriptOutput("FinishedPageCallback - OK");
- testGui.callProtectedDelayedControlScriptExecution(PackageManagerCore::InstallationFinished);
+ testGui.callProtectedDelayedExecuteControlScript(PackageManagerCore::InstallationFinished);
} catch (const Error &error) {
QFAIL(qPrintable(error.message()));
}
diff --git a/tests/auto/installer/settingsoperation/settingsoperation.pro b/tests/auto/installer/settingsoperation/settingsoperation.pro
new file mode 100644
index 000000000..60ddd329b
--- /dev/null
+++ b/tests/auto/installer/settingsoperation/settingsoperation.pro
@@ -0,0 +1,6 @@
+include(../../qttest.pri)
+
+QT -= gui
+QT += testlib
+
+SOURCES += tst_settingsoperation.cpp
diff --git a/tests/auto/installer/settingsoperation/tst_settingsoperation.cpp b/tests/auto/installer/settingsoperation/tst_settingsoperation.cpp
new file mode 100644
index 000000000..f663297ec
--- /dev/null
+++ b/tests/auto/installer/settingsoperation/tst_settingsoperation.cpp
@@ -0,0 +1,328 @@
+/**************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+**************************************************************************/
+#include <utils.h>
+#include <settingsoperation.h>
+#include <qinstallerglobal.h>
+
+#include <QObject>
+#include <QTest>
+#include <QSettings>
+#include <QDir>
+
+using namespace KDUpdater;
+using namespace QInstaller;
+
+class tst_settingsoperation : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ // called before all tests
+ void initTestCase()
+ {
+ m_testSettingsDirPath = qApp->applicationDirPath();
+ m_testSettingsFilename = "test.ini";
+ QSettings testSettings(QDir(m_testSettingsDirPath).filePath(m_testSettingsFilename),
+ QSettings::IniFormat);
+ m_cleanupFilePathes << QDir(m_testSettingsDirPath).filePath(m_testSettingsFilename);
+ testSettings.setValue("testkey", "testvalue");
+ testSettings.setValue("testcategory/categorytestkey", "categorytestvalue");
+ testSettings.setValue("testcategory/categoryarrayvalue1", QStringList() << "value1" <<
+ "value2" << "value3");
+ testSettings.setValue("testcategory/categoryarrayvalue2", "value1,value2,value3");
+ testSettings.setValue("testcategory/categoryarrayvalue3", "value1 ,value2, value3");
+ }
+
+ void testWrongArguments()
+ {
+ SettingsOperation noArgumentsOperation;
+
+ QVERIFY(noArgumentsOperation.testOperation());
+
+ // operation should do nothing if there are no arguments
+ QCOMPARE(noArgumentsOperation.performOperation(), false);
+
+ QCOMPARE(UpdateOperation::Error(noArgumentsOperation.error()),
+ UpdateOperation::InvalidArguments);
+ QString compareString("Missing argument(s) 'path; method; key; value' calling 'Settings' "
+ "with arguments ''.");
+ QCOMPARE(noArgumentsOperation.errorString(), compareString);
+
+ // same for undo
+ QCOMPARE(noArgumentsOperation.undoOperation(), false);
+
+ SettingsOperation wrongMethodArgumentOperation;
+ wrongMethodArgumentOperation.setArguments(QStringList() << "path=first" << "method=second"
+ << "key=third" << "value=fourth");
+
+ QVERIFY(wrongMethodArgumentOperation.testOperation());
+
+ // operation should do nothing if there are no arguments
+ QCOMPARE(wrongMethodArgumentOperation.performOperation(), false);
+
+ QCOMPARE(UpdateOperation::Error(wrongMethodArgumentOperation.error()),
+ UpdateOperation::InvalidArguments);
+ compareString = "Current method argument calling 'Settings' with arguments 'path=first; "
+ "method=second; key=third; value=fourth' is not supported. Please use set, remove, "
+ "add_array_value or remove_array_value.";
+ QCOMPARE(wrongMethodArgumentOperation.errorString(), compareString);
+
+ // same for undo
+ QCOMPARE(wrongMethodArgumentOperation.undoOperation(), false);
+ }
+
+ void setSettingsValue()
+ {
+ const QString verifyFilePath = createFilePath(QTest::currentTestFunction());
+ const QString testFilePath = createFilePath(QString("_") + QTest::currentTestFunction());
+ m_cleanupFilePathes << verifyFilePath << testFilePath;
+
+ const QString key = "category/key";
+ const QString value = "value";
+ {
+ QSettings testSettings(verifyFilePath, QSettings::IniFormat);
+ testSettings.setValue(key, value);
+ }
+
+ SettingsOperation settingsOperation;
+ settingsOperation.setArguments(QStringList() << QString("path=%1").arg(testFilePath) <<
+ "method=set" << QString("key=%1").arg(key) << QString("value=%1").arg(value));
+ settingsOperation.backup();
+
+ QVERIFY2(settingsOperation.performOperation(), settingsOperation.errorString().toLatin1());
+
+ QVERIFY2(compareFiles(verifyFilePath, testFilePath), QString("'%1' and '%2' are different")
+ .arg(verifyFilePath, testFilePath).toLatin1());
+ }
+
+ void undoSettingsValueInCreatedSubDirectories()
+ {
+ const QString testFilePath = createFilePath(QString("sub/directory/") +
+ QTest::currentTestFunction());
+ const QString key = "key";
+ const QString value = "value";
+
+ SettingsOperation settingsOperation;
+ settingsOperation.setArguments(QStringList() << QString("path=%1").arg(testFilePath) <<
+ "method=set" << QString("key=%1").arg(key) << QString("value=%1").arg(value));
+ settingsOperation.backup();
+
+ QVERIFY2(settingsOperation.performOperation(), settingsOperation.errorString().toLatin1());
+ QCOMPARE(QFile(testFilePath).exists(), true);
+ QVERIFY2(settingsOperation.undoOperation(), settingsOperation.errorString().toLatin1());
+ QCOMPARE(QFile(testFilePath).exists(), false);
+ QCOMPARE(QDir(QFileInfo(testFilePath).absolutePath()).exists(), false);
+ }
+
+ void removeSettingsValue()
+ {
+ const QString testFilePath = createFilePath(QTest::currentTestFunction());
+ QFile testFile(QDir(m_testSettingsDirPath).filePath(m_testSettingsFilename));
+ QVERIFY2(testFile.copy(testFilePath), testFile.errorString().toLatin1());
+ m_cleanupFilePathes << testFilePath;
+
+ const QString key = "testkey";
+ QString testValueString;
+ {
+ QSettings testSettings(testFilePath, QSettings::IniFormat);
+ testValueString = testSettings.value(key).toString();
+ }
+ QCOMPARE(testValueString.isEmpty(), false);
+
+ SettingsOperation settingsOperation;
+ settingsOperation.setArguments(QStringList() << QString("path=%1").arg(testFilePath) <<
+ "method=remove" << QString("key=%1").arg(key));
+ settingsOperation.backup();
+ QVERIFY2(settingsOperation.performOperation(), settingsOperation.errorString().toLatin1());
+
+ QVariant testValueVariant;
+ {
+ QSettings testSettings(testFilePath, QSettings::IniFormat);
+ testValueVariant = testSettings.value(key);
+ }
+ QVERIFY(testValueVariant.isNull());
+ }
+
+ void addSettingsArrayValue()
+ {
+ const QString testFilePath = createFilePath(QTest::currentTestFunction());
+ QFile contentFile(QDir(m_testSettingsDirPath).filePath(m_testSettingsFilename));
+ QVERIFY2(contentFile.open(QIODevice::ReadOnly | QIODevice::Text), contentFile.errorString().toLatin1());
+
+ QFile testFile(testFilePath);
+ QVERIFY2(testFile.open(QIODevice::WriteOnly | QIODevice::Text), contentFile.errorString().toLatin1());
+
+ QTextStream out(&testFile);
+
+ QTextStream in(&contentFile);
+ QString line = in.readLine();
+ while (!line.isNull()) {
+ // remove the " to have some maybe invalid data
+ out << line.replace("\"", QLatin1String("")) << QLatin1String("\n");
+ line = in.readLine();
+ }
+ testFile.close();
+
+ QMap<QString, SettingsOperation*> testSettingsOperationMap;
+ testSettingsOperationMap["testcategory/categoryarrayvalue1"] = new SettingsOperation;
+ testSettingsOperationMap["testcategory/categoryarrayvalue2"] = new SettingsOperation;
+ testSettingsOperationMap["testcategory/categoryarrayvalue3"] = new SettingsOperation;
+ testSettingsOperationMap["testcategory/categoryarrayvalue4"] = new SettingsOperation;
+
+ QMap<QString, SettingsOperation*>::iterator i = testSettingsOperationMap.begin();
+ while (i != testSettingsOperationMap.end()) {
+ i.value()->setArguments(QStringList() << QString("path=%1").arg(testFilePath) <<
+ "method=add_array_value" << QString("key=%1").arg(i.key()) << "value=value4");
+ i.value()->backup();
+ QVERIFY2(i.value()->performOperation(), i.value()->errorString().toLatin1());
+ ++i;
+ }
+ QStringList testKeys(testSettingsOperationMap.keys());
+ {
+ QSettings verifySettings(testFilePath, QSettings::IniFormat);
+ QCOMPARE(verifySettings.value(testKeys.at(0)).isNull(), false);
+ QCOMPARE(verifySettings.value(testKeys.at(0)), verifySettings.value(testKeys.at(1)));
+ QCOMPARE(verifySettings.value(testKeys.at(1)), verifySettings.value(testKeys.at(2)));
+ QCOMPARE(verifySettings.value(testKeys.at(3)).toString(), QLatin1String("value4"));
+ }
+
+ i = testSettingsOperationMap.begin();
+ while (i != testSettingsOperationMap.end()) {
+ i.value()->setArguments(QStringList() << QString("path=%1").arg(testFilePath) <<
+ "method=add_array_value" << QString("key=%1").arg(i.key()) << "value=value4");
+ QVERIFY2(i.value()->undoOperation(), i.value()->errorString().toLatin1());
+ ++i;
+ }
+
+ {
+ QStringList verifyStringList;
+ verifyStringList << "value1" << "value2" << "value3";
+ QVariant verifyUndoValue = verifyStringList;
+ QSettings verifySettings(testFilePath, QSettings::IniFormat);
+ QCOMPARE(verifySettings.value(testKeys.at(0)), verifyUndoValue);
+ QCOMPARE(verifySettings.value(testKeys.at(1)), verifyUndoValue);
+ QCOMPARE(verifySettings.value(testKeys.at(2)), verifyUndoValue);
+ // checking the none array value is removed
+ QVERIFY(verifySettings.value(testKeys.at(3)).isNull());
+ }
+
+ }
+
+ void removeSettingsArrayValue()
+ {
+ const QString testFilePath = createFilePath(QTest::currentTestFunction());
+ QFile contentFile(QDir(m_testSettingsDirPath).filePath(m_testSettingsFilename));
+ QVERIFY2(contentFile.open(QIODevice::ReadOnly | QIODevice::Text), contentFile.errorString()
+ .toLatin1());
+
+ QFile testFile(testFilePath);
+ QVERIFY2(testFile.open(QIODevice::WriteOnly | QIODevice::Text), contentFile.errorString()
+ .toLatin1());
+
+ QTextStream out(&testFile);
+
+ QTextStream in(&contentFile);
+ QString line = in.readLine();
+ while (!line.isNull()) {
+ // remove the " to have some maybe invalid data
+ out << line.replace("\"", QLatin1String("")) << QLatin1String("\n");
+ line = in.readLine();
+ }
+ testFile.close();
+
+ QMap<QString, SettingsOperation*> testSettingsOperationMap;
+ testSettingsOperationMap["testcategory/categoryarrayvalue1"] = new SettingsOperation;
+ testSettingsOperationMap["testcategory/categoryarrayvalue2"] = new SettingsOperation;
+ testSettingsOperationMap["testcategory/categoryarrayvalue3"] = new SettingsOperation;
+
+ QMap<QString, SettingsOperation*>::iterator i = testSettingsOperationMap.begin();
+ while (i != testSettingsOperationMap.end()) {
+ i.value()->setArguments(QStringList() << QString("path=%1").arg(testFilePath) <<
+ "method=remove_array_value" << QString("key=%1").arg(i.key()) << "value=value3");
+ i.value()->backup();
+ QVERIFY2(i.value()->performOperation(), i.value()->errorString().toLatin1());
+ ++i;
+ }
+ QStringList testKeys(testSettingsOperationMap.keys());
+ {
+ QSettings verifySettings(testFilePath, QSettings::IniFormat);
+ QCOMPARE(verifySettings.value(testKeys.at(0)).isNull(), false);
+
+ QStringList verifyFirstValue = verifySettings.value(testKeys.at(0)).toStringList();
+#if QT_VERSION < 0x050000
+ QCOMPARE(verifyFirstValue.contains(QLatin1String("value3")), QBool(false));
+#else
+ QCOMPARE(verifyFirstValue.contains(QLatin1String("value3")), false);
+#endif
+ QCOMPARE(verifySettings.value(testKeys.at(0)), verifySettings.value(testKeys.at(1)));
+ QCOMPARE(verifySettings.value(testKeys.at(1)), verifySettings.value(testKeys.at(2)));
+ }
+ }
+
+ // called after all tests
+ void cleanupTestCase()
+ {
+ foreach (const QString &filePath, m_cleanupFilePathes)
+ QFile(filePath).remove();
+ }
+private:
+ QString createFilePath(const QString &fileNamePrependix)
+ {
+ return QDir(m_testSettingsDirPath).filePath(QString(fileNamePrependix) + m_testSettingsFilename);
+ }
+
+ bool compareFiles(const QString &filePath1, const QString &filePath2)
+ {
+ if (!QFile::exists(filePath1) || !QFile::exists(filePath2))
+ return false;
+ const QByteArray fileHash1 = QInstaller::calculateHash(filePath1, QCryptographicHash::Sha1);
+ const QByteArray fileHash2 = QInstaller::calculateHash(filePath2, QCryptographicHash::Sha1);
+ return fileHash1 == fileHash2;
+ }
+
+ QString m_testSettingsFilename;
+ QString m_testSettingsDirPath;
+ QStringList m_cleanupFilePathes;
+};
+
+QTEST_MAIN(tst_settingsoperation)
+
+#include "tst_settingsoperation.moc"
diff --git a/tests/downloadspeed/main.cpp b/tests/downloadspeed/main.cpp
index 5a5b685aa..4edc0d8b6 100644
--- a/tests/downloadspeed/main.cpp
+++ b/tests/downloadspeed/main.cpp
@@ -164,6 +164,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
const QUrl url(a.arguments().value(1));
+ KDUpdater::FileDownloaderFactory::setFollowRedirects(true);
qDebug() << url.toString();
KDUpdater::FileDownloader *loader = KDUpdater::FileDownloaderFactory::instance().create(url.scheme(), 0);
if (loader) {