Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of https://github.com/martyone/ssu
  • Loading branch information
Bernd Wachter committed Apr 2, 2013
2 parents 6c54d94 + 77b4b2d commit 694b53a
Show file tree
Hide file tree
Showing 31 changed files with 2,905 additions and 8 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
2 changes: 1 addition & 1 deletion libssu/ssu.cpp
Expand Up @@ -119,7 +119,7 @@ void Ssu::setRelease(QString release, bool rnd){

void Ssu::setDomain(QString domain){
SsuCoreConfig *settings = SsuCoreConfig::instance();
setDomain(domain);
settings->setDomain(domain);
}

bool Ssu::useSslVerify(){
Expand Down
23 changes: 18 additions & 5 deletions libssu/ssusettings.cpp
Expand Up @@ -67,30 +67,42 @@ void SsuSettings::merge(bool keepOld){
if (settingsFiles.count() > 0 && !keepOld)
clear();

merge(this, settingsFiles);
sync();
}

void SsuSettings::merge(QSettings *masterSettings, const QStringList &settingsFiles){
SsuLog *ssuLog = SsuLog::instance();

foreach (const QString &settingsFile, settingsFiles){
QSettings settings(settingsFile, QSettings::IniFormat);
QStringList groups = settings.childGroups();

ssuLog->print(LOG_DEBUG, QString("Merging %1 into %2")
.arg(settingsFile)
.arg(fileName()));
.arg(masterSettings->fileName()));

foreach (const QString &group, groups){
beginGroup(group);
masterSettings->beginGroup(group);
settings.beginGroup(group);

QStringList keys = settings.allKeys();
foreach (const QString &key, keys){
setValue(key, settings.value(key));
masterSettings->setValue(key, settings.value(key));
}

settings.endGroup();
endGroup();
masterSettings->endGroup();
}
sync();
}
}

/*
* 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 Expand Up @@ -175,5 +187,6 @@ void SsuSettings::upgrade(){
}
setValue("configVersion", i);
}
sync();
}
}
3 changes: 3 additions & 0 deletions libssu/ssusettings.h
Expand Up @@ -13,6 +13,8 @@
class SsuSettings: public QSettings {
Q_OBJECT

friend class SettingsTest;

public:
SsuSettings();
SsuSettings(const QString &fileName, Format format, QObject *parent=0);
Expand All @@ -30,6 +32,7 @@ class SsuSettings: public QSettings {
private:
QString defaultSettingsFile, settingsd;
void merge(bool keepOld=false);
static void merge(QSettings *masterSettings, const QStringList &settingsFiles);
void upgrade();

};
Expand Down
15 changes: 15 additions & 0 deletions tests/sandbox/sandbox.pro
@@ -0,0 +1,15 @@
SOURCES = sandboxhook.cpp

TEMPLATE = lib
TARGET = sandboxhook
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") }
90 changes: 90 additions & 0 deletions tests/sandbox/sandboxfileenginehandler.h
@@ -0,0 +1,90 @@
/**
* @file sandboxfileenginehandler.h
* @copyright 2013 Jolla Ltd.
* @author Martin Kampas <martin.kampas@tieto.com>
* @date 2013
*/

#ifndef _SANDBOXINGFILEENGINEHANDLER_H
#define _SANDBOXINGFILEENGINEHANDLER_H

#include <QtCore/QAbstractFileEngineHandler>
#include <QtCore/QDir>
#include <QtCore/QFSFileEngine>
#include <QtCore/QFileInfo>
#include <QtCore/QProcessEnvironment>
#include <QtCore/QSet>

#include <ssucoreconfig.h>
#include "../../constants.h"

/**
* Redirects all file operations on system configuration files to files under
* directory specified by SSU_TESTS_SANDBOX environment variable.
*/
class SandboxFileEngineHandler : public QAbstractFileEngineHandler {
public:
QAbstractFileEngine *create(const QString &fileName) const{
static bool enabled = false;
static bool firstCall = true;

if (!enabled && !firstCall){
return 0;
}

static QString sandboxPath =
QProcessEnvironment::systemEnvironment().value("SSU_TESTS_SANDBOX");

if (firstCall){
firstCall = false;

if (sandboxPath.isEmpty()){
return 0;
}

if (!QFileInfo(sandboxPath).exists()){
qFatal("%s: Invalid SSU_TESTS_SANDBOX value: No such file or directory",
qPrintable(sandboxPath));
}

if (!QFileInfo(sandboxPath).isDir()){
qFatal("%s: Invalid SSU_TESTS_SANDBOX value: Not a directory",
qPrintable(sandboxPath));
}

enabled = true;
}

if (!fileName.startsWith('/')){
return 0;
}

static QSet<QString> ssuConfigFiles = QSet<QString>()
<< SSU_CONFIGURATION
<< SSU_REPO_CONFIGURATION
<< SSU_DEFAULT_CONFIGURATION
<< SSU_BOARD_MAPPING_CONFIGURATION;

static QSet<QString> ssuConfigDirectories = QSet<QString>()
<< SSU_BOARD_MAPPING_CONFIGURATION_DIR;

if (!ssuConfigFiles.contains(fileName)){
bool match = false;
foreach (const QString &ssuConfigDirectory, ssuConfigDirectories){
if (fileName.startsWith(ssuConfigDirectory + '/')){
match = true;
break;
}
}
if (!match){
return 0;
}
}

const QString fileName_ = QDir(sandboxPath).absoluteFilePath(QString(fileName).remove(0, 1));

return new QFSFileEngine(fileName_);
}
};

#endif
12 changes: 12 additions & 0 deletions tests/sandbox/sandboxhook.cpp
@@ -0,0 +1,12 @@
#include <dlfcn.h>

#include "sandboxfileenginehandler.h"

extern "C" void qt_startup_hook()
{
SandboxFileEngineHandler *const handler = new SandboxFileEngineHandler();
Q_UNUSED(handler);

static void(*next_qt_startup_hook)() = (void (*)()) dlsym(RTLD_NEXT, "qt_startup_hook");
next_qt_startup_hook();
}
9 changes: 8 additions & 1 deletion tests/tests.pri
@@ -1 +1,8 @@
TESTS_PATH = /opt/tests/ssu
DEPENDPATH *= $${PWD}/sandbox

TESTS_PATH = /opt/tests/ssu
DEFINES += TESTS_PATH="'\"$${TESTS_PATH}\"'"

isEmpty(TARGET):error("TARGET must be defined before this file is included")
TESTS_DATA_PATH = /opt/tests/ssu/data/$${TARGET}
DEFINES += TESTS_DATA_PATH="'\"$${TESTS_DATA_PATH}\"'"
7 changes: 6 additions & 1 deletion tests/tests.pro
@@ -1,6 +1,11 @@
TEMPLATE = subdirs
CONFIG += qt ordered coverage debug
SUBDIRS = ut_urlresolver ut_variables
SUBDIRS = \
sandbox \
ut_settings \
ut_ssuurlresolver \
ut_urlresolver \
ut_variables \

!include( tests.pri ) { error("Unable to find tests include") }

Expand Down
10 changes: 10 additions & 0 deletions tests/tests.xml
Expand Up @@ -3,6 +3,16 @@
<!-- 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="ssuurlresolver" description="Test to determine if the UrlResolverPlugin works well with installed version of libzypp" feature="ssuurlresolver">
<case name="ut_ssuurlresolver" type="Functional" description="URL resolver plugin test" timeout="1000" subfeature="">
<step expected_result="0">/opt/tests/ssu/ut_ssuurlresolver</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>
Expand Down
28 changes: 28 additions & 0 deletions tests/ut_settings/main.cpp
@@ -0,0 +1,28 @@
/**
* @file main.cpp
* @copyright 2012 Jolla Ltd.
* @author Martin Kampas <martin.kampas@tieto.com>
* @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))
return 1;

return 0;
}

0 comments on commit 694b53a

Please sign in to comment.