Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic variable resolver and unit tests
- Loading branch information
Bernd Wachter
committed
Mar 22, 2013
1 parent
d218838
commit 4e581b3
Showing
8 changed files
with
225 additions
and
3 deletions.
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
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 Bernd Wachter <bernd.wachter@jollamobile.com> | ||
* @date 2012 | ||
*/ | ||
|
||
#include <QtTest/QtTest> | ||
|
||
#include "variablestest.h" | ||
|
||
int main(int argc, char **argv){ | ||
VariablesTest variablesTest; | ||
|
||
if (QTest::qExec(&variablesTest, 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,17 @@ | ||
HEADERS = variablestest.h | ||
SOURCES = main.cpp \ | ||
variablestest.cpp | ||
TEMPLATE = app | ||
TARGET = ut_variables | ||
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") } |
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 variablestest.cpp | ||
* @copyright 2013 Jolla Ltd. | ||
* @author Bernd Wachter <bwachter@lart.info> | ||
* @date 2013 | ||
*/ | ||
|
||
#include "variablestest.h" | ||
|
||
void VariablesTest::initTestCase(){ | ||
variables.insert("packagesDomain", "packages.example.com"); | ||
variables.insert("releaseDomain", "releases.example.com"); | ||
variables.insert("rndProtocol", "https"); | ||
variables.insert("release", "devel"); | ||
variables.insert("arch", "armv8"); | ||
variables.insert("flavourName", "flavour"); | ||
|
||
urls.insert("http://%(packagesDomain)/releases/%(release)/jolla/%(arch)/", | ||
"http://packages.example.com/releases/devel/jolla/armv8/"); | ||
urls.insert("%(rndProtocol)://%(releaseDomain)/nemo/%(release)-%(flavourName)/platform/%(arch)/", | ||
"https://releases.example.com/nemo/devel-flavour/platform/armv8/"); | ||
// test missing operator, which should fall back to just variable value | ||
urls.insert("%(rndProtocol)://%(unsetDomain:)/nemo/%(release)-%(flavourName)/platform/%(arch)/", | ||
"https:///nemo/devel-flavour/platform/armv8/"); | ||
urls.insert("%(rndProtocol)://%(releaseDomain:)/nemo/%(release)-%(flavourName)/platform/%(arch)/", | ||
"https://releases.example.com/nemo/devel-flavour/platform/armv8/"); | ||
urls.insert("%(rndProtocol)://%(releaseDomain:unset.example.com)/nemo/%(release)-%(flavourName)/platform/%(arch)/", | ||
"https://releases.example.com/nemo/devel-flavour/platform/armv8/"); | ||
// check if :- works | ||
urls.insert("%(rndProtocol)://%(releaseDomain:-unset.example.com)/nemo/%(release)-%(flavourName)/platform/%(arch)/", | ||
"https://releases.example.com/nemo/devel-flavour/platform/armv8/"); | ||
urls.insert("%(rndProtocol)://%(unsetDomain:-unset.example.com)/nemo/%(release)-%(flavourName)/platform/%(arch)/", | ||
"https://unset.example.com/nemo/devel-flavour/platform/armv8/"); | ||
// test with empty replacement pattern | ||
urls.insert("%(rndProtocol)://%(unsetDomain:-)/nemo/%(release)-%(flavourName)/platform/%(arch)/", | ||
"https:///nemo/devel-flavour/platform/armv8/"); | ||
// check if :+ works | ||
// substitution of variable with set.example.com | ||
urls.insert("%(rndProtocol)://%(releaseDomain:+set.example.com)/nemo/%(release)-%(flavourName)/platform/%(arch)/", | ||
"https://set.example.com/nemo/devel-flavour/platform/armv8/"); | ||
// substitution of variable with variable + /set | ||
urls.insert("%(rndProtocol)://%(releaseDomain:+%(releaseDomain)/set)/nemo/%(release)-%(flavourName)/platform/%(arch)/", | ||
"https://releases.example.com/set/nemo/devel-flavour/platform/armv8/"); | ||
// substitution of variable with empty variable + /set -- should substitute to "" | ||
urls.insert("%(rndProtocol)://%(unsetDomain:+%(unsetDomain)/set)/nemo/%(release)-%(flavourName)/platform/%(arch)/", | ||
"https:///nemo/devel-flavour/platform/armv8/"); | ||
|
||
} | ||
|
||
void VariablesTest::cleanupTestCase(){ | ||
|
||
} | ||
|
||
void VariablesTest::checkResolveString(){ | ||
QHashIterator<QString, QString> i(urls); | ||
|
||
while (i.hasNext()){ | ||
i.next(); | ||
QString result = var.resolveString(i.key(), &variables); | ||
qDebug() << i.key() << " resolved to " << result; | ||
QCOMPARE(result, i.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,33 @@ | ||
/** | ||
* @file variablestest.h | ||
* @copyright 2013 Jolla Ltd. | ||
* @author Bernd Wachter <bwachter@lart.info> | ||
* @date 2013 | ||
*/ | ||
|
||
#ifndef _VARIABLESTEST_H | ||
#define _VARIABLESTEST_H | ||
|
||
#include <QObject> | ||
#include <QtTest/QtTest> | ||
#include <QHash> | ||
|
||
#include <ssu.h> | ||
#include <ssuvariables.h> | ||
|
||
class VariablesTest: public QObject { | ||
Q_OBJECT | ||
|
||
private slots: | ||
void initTestCase(); | ||
void cleanupTestCase(); | ||
void checkResolveString(); | ||
|
||
|
||
private: | ||
Ssu ssu; | ||
SsuVariables var; | ||
QHash <QString, QString> variables, urls; | ||
}; | ||
|
||
#endif |