Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ut_settings: add upgrade() test
  • Loading branch information
martyone committed Apr 2, 2013
1 parent d134a5e commit 380cbdb
Show file tree
Hide file tree
Showing 10 changed files with 2,360 additions and 0 deletions.
1 change: 1 addition & 0 deletions buildpath.pri
Expand Up @@ -17,4 +17,5 @@ UI_SOURCES_DIR = $$BUILD
RCC_DIR = $$BUILD

LIBS += -L$$PWD/build/libssu
LD_LIBRARY_PATH = $$PWD/build/libssu
INCLUDEPATH += $$PWD/libssu
6 changes: 6 additions & 0 deletions libssu/ssusettings.cpp
Expand Up @@ -97,6 +97,12 @@ void SsuSettings::merge(QSettings *masterSettings, const QStringList &settingsFi
}
}

/*
* If you change anything here, run `make update-upgrade-test-recipe` inside
* tests/ut_settings/ and check the impact of your changes with
* `git diff testdata/upgrade/recipe`. See ut_settings/upgradetesthelper.cpp for
* more details.
*/
void SsuSettings::upgrade(){
int configVersion=0;
int defaultConfigVersion=0;
Expand Down
9 changes: 9 additions & 0 deletions tests/ut_settings/main.cpp
Expand Up @@ -5,11 +5,20 @@
* @date 2012
*/

#include <QtCore/QCoreApplication>
#include <QtTest/QtTest>

#include "settingstest.h"
#include "upgradetesthelper.h"

int main(int argc, char **argv){
QCoreApplication app(argc, argv);

if (app.arguments().contains("-generate-upgrade-test-recipe")){
QTextStream out(stdout);
return UpgradeTestHelper::generateSnapshotRecipe(&out) ? 0 : 1;
}

SettingsTest settingsTest;

if (QTest::qExec(&settingsTest, argc, argv))
Expand Down
74 changes: 74 additions & 0 deletions tests/ut_settings/settingstest.cpp
Expand Up @@ -11,6 +11,8 @@

#include <ssusettings.h>

#include "upgradetesthelper.h"

void SettingsTest::initTestCase(){

}
Expand Down Expand Up @@ -61,3 +63,75 @@ void SettingsTest::testMerge(){
QCOMPARE(keyIsMerged, keyShouldBeMerged);
QCOMPARE(actualValue, expectedValue);
}

void SettingsTest::testUpgrade_data(){
// Read recipe
QFile recipe(":/testdata/upgrade/recipe");
QVERIFY(recipe.open(QIODevice::ReadOnly));
QList<UpgradeTestHelper::TestCase> testCases = UpgradeTestHelper::readRecipe(&recipe);

// Generate settings file according to recipe
QTemporaryFile settingsFile;
QVERIFY(settingsFile.open() == true);

QSettings settings(settingsFile.fileName(), QSettings::IniFormat);

UpgradeTestHelper::fillSettings(&settings, testCases);

// Generate defaults file according to recipe
QTemporaryFile defaultSettingsFile;
QVERIFY(defaultSettingsFile.open() == true);

QSettings defaultSettings(defaultSettingsFile.fileName(), QSettings::IniFormat);

UpgradeTestHelper::fillDefaultSettings(&defaultSettings, testCases);

// Parse settings -- do upgrade
#if 0
settingsFile.seek(0);
defaultSettingsFile.seek(0);
qDebug() << "SETTINGS {{{\n" << settingsFile.readAll() << "\n}}}";
qDebug() << "DEFAULT SETTINGS {{{\n" << defaultSettingsFile.readAll() << "\n}}}";
#endif

SsuSettings ssuSettings(settingsFile.fileName(), QSettings::IniFormat,
defaultSettingsFile.fileName());

#if 0
settingsFile.seek(0);
qDebug() << "SETTINGS UPGRADED {{{\n" << settingsFile.readAll() << "\n}}}";
#endif

// Record data for verification phase
QTest::addColumn<bool>("keyIsSet");
QTest::addColumn<bool>("keyShouldBeSet");
QTest::addColumn<QString>("actualValue");
QTest::addColumn<QString>("expectedValue");

foreach (const UpgradeTestHelper::TestCase &testCase, testCases){
foreach (const QString &group, UpgradeTestHelper::groups()){
const QString key = group.isEmpty() ? testCase.key() : group + '/' + testCase.key();
QTest::newRow(qPrintable(QString("%1%2:%3:%4")
.arg(group.isEmpty() ? "" : group + "/")
.arg(testCase.history)
.arg(testCase.current)
.arg(testCase.expected)))
<< ssuSettings.contains(key)
<< testCase.keyShouldBeSet()
<< ssuSettings.value(key).toString()
<< testCase.expected;
}
}
}

void SettingsTest::testUpgrade(){
QFETCH(bool, keyIsSet);
QFETCH(bool, keyShouldBeSet);
QFETCH(QString, actualValue);
QFETCH(QString, expectedValue);

QCOMPARE(keyIsSet, keyShouldBeSet);
if (keyIsSet){
QCOMPARE(actualValue, expectedValue);
}
}
2 changes: 2 additions & 0 deletions tests/ut_settings/settingstest.h
Expand Up @@ -18,6 +18,8 @@ class SettingsTest: public QObject {
void cleanupTestCase();
void testMerge_data();
void testMerge();
void testUpgrade_data();
void testUpgrade();

private:
};
Expand Down
1 change: 1 addition & 0 deletions tests/ut_settings/testdata.qrc
Expand Up @@ -5,5 +5,6 @@
<file>testdata/merge/settings.d/foo.ini</file>
<file>testdata/merge/merged.ini</file>
<file>testdata/merge/settings.ini</file>
<file>testdata/upgrade/recipe</file>
</qresource>
</RCC>

0 comments on commit 380cbdb

Please sign in to comment.