Commit d134a5ef authored by Martin Kampas's avatar Martin Kampas

ut_settings: initial commit. test merge()

parent e05b5d8b
......@@ -13,6 +13,8 @@
class SsuSettings: public QSettings {
Q_OBJECT
friend class SettingsTest;
public:
SsuSettings();
SsuSettings(const QString &fileName, Format format, QObject *parent=0);
......
TEMPLATE = subdirs
CONFIG += qt ordered coverage debug
SUBDIRS = ut_urlresolver ut_variables
SUBDIRS = \
ut_settings \
ut_urlresolver \
ut_variables \
!include( tests.pri ) { error("Unable to find tests include") }
......
......@@ -3,6 +3,11 @@
<!-- Test suite, name mandatory - the same as test package name -->
<suite name="sync-app-tests" domain="ssu">
<!-- At least one set per suite, name and description mandatory -->
<set name="settings" description="Test to determine if configuration files processing works properly" feature="settings">
<case name="ut_settings" type="Functional" description="Settings processing test" timeout="1000" subfeature="">
<step expected_result="0">/opt/tests/ssu/ut_settings</step>
</case>
</set>
<set name="urlresolver" description="Test to determine if URL resolving works properly" feature="urlresolver">
<case name="ut_urlresolver" type="Functional" description="URL resolver tests" timeout="1000" subfeature="">
<step expected_result="0">/opt/tests/ssu/ut_urlresolver</step>
......
/**
* @file main.cpp
* @copyright 2012 Jolla Ltd.
* @author Martin Kampas <martin.kampas@tieto.com>
* @date 2012
*/
#include <QtTest/QtTest>
#include "settingstest.h"
int main(int argc, char **argv){
SettingsTest settingsTest;
if (QTest::qExec(&settingsTest, argc, argv))
return 1;
return 0;
}
/**
* @file settingstest.cpp
* @copyright 2013 Jolla Ltd.
* @author Martin Kampas <martin.kampas@tieto.com>
* @date 2013
*/
#include "settingstest.h"
#include <QtTest/QtTest>
#include <ssusettings.h>
void SettingsTest::initTestCase(){
}
void SettingsTest::cleanupTestCase(){
}
void SettingsTest::testMerge_data(){
// Key names state which file(s) a key is set in (master, foo or bar). Value
// is always in form "<file>-value" based on which file it is taken from.
const QScopedPointer<QTemporaryFile> masterFile(
QTemporaryFile::createLocalFile(":/testdata/merge/settings.ini"));
QSettings master(masterFile->fileName(), QSettings::IniFormat);
const QStringList settingsFiles = QStringList()
<< ":/testdata/merge/settings.d/bar.ini"
<< ":/testdata/merge/settings.d/foo.ini";
SsuSettings::merge(&master, settingsFiles);
QSettings expected(":/testdata/merge/merged.ini", QSettings::IniFormat);
const QSet<QString> masterKeys = master.allKeys().toSet();
const QSet<QString> expectedKeys = expected.allKeys().toSet();
QTest::addColumn<bool>("keyIsMerged");
QTest::addColumn<bool>("keyShouldBeMerged");
QTest::addColumn<QString>("actualValue");
QTest::addColumn<QString>("expectedValue");
foreach (const QString &key, masterKeys + expectedKeys){
QTest::newRow(qPrintable(key))
<< masterKeys.contains(key)
<< expectedKeys.contains(key)
<< master.value(key).toString()
<< expected.value(key).toString();
}
}
void SettingsTest::testMerge(){
QFETCH(bool, keyIsMerged);
QFETCH(bool, keyShouldBeMerged);
QFETCH(QString, actualValue);
QFETCH(QString, expectedValue);
QCOMPARE(keyIsMerged, keyShouldBeMerged);
QCOMPARE(actualValue, expectedValue);
}
/**
* @file settingstest.h
* @copyright 2013 Jolla Ltd.
* @author Martin Kampas <martin.kampas@tieto.com>
* @date 2013
*/
#ifndef _SETTINGSTEST_H
#define _SETTINGSTEST_H
#include <QObject>
class SettingsTest: public QObject {
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
void testMerge_data();
void testMerge();
private:
};
#endif
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file>testdata/merge/settings.d/bar.ini</file>
<file>testdata/merge/settings.d/foo.ini</file>
<file>testdata/merge/merged.ini</file>
<file>testdata/merge/settings.ini</file>
</qresource>
</RCC>
# Global values do not get overridden
global-master-only = master-value
global-master-foo = master-value
global-master-bar = master-value
global-master-foo-bar = master-value
[groupA]
master-only = master-value
foo-only = foo-value
bar-only = bar-value
master-foo = foo-value
master-bar = bar-value
master-foo-bar = foo-value
foo-bar = foo-value
global-bar-only = bar-value
global-master-bar = bar-value
global-master-foo-bar = bar-value
global-foo-bar = bar-value
[groupA]
bar-only = bar-value
master-bar = bar-value
master-foo-bar = bar-value
foo-bar = bar-value
global-foo-only = foo-value
global-master-foo = foo-value
global-master-foo-bar = foo-value
global-foo-bar = foo-value
[groupA]
foo-only = foo-value
master-foo = foo-value
master-foo-bar = foo-value
foo-bar = foo-value
global-master-only = master-value
global-master-foo = master-value
global-master-bar = master-value
global-master-foo-bar = master-value
[groupA]
master-only = master-value
master-foo = master-value
master-bar = master-value
master-foo-bar = master-value
HEADERS = \
settingstest.h \
SOURCES = \
main.cpp \
settingstest.cpp \
RESOURCES = testdata.qrc
TEMPLATE = app
TARGET = ut_settings
LIBS += -lssu
CONFIG -= app_bundle
CONFIG += console qtestlib
QT -= gui
QT += network testlib
!include( ../tests.pri ) { error("Unable to find tests include") }
unix:target.path = $${PREFIX}/$$TESTS_PATH
INSTALLS += target
!include( ../../buildpath.pri ) { error("Unable to find build path specification") }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment