Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ut_settings: initial commit. test merge()
- Loading branch information
Showing
12 changed files
with
193 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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") } |