Skip to content

Commit

Permalink
Merge pull request #14 from ElektraInitiative/elektra-backend-without…
Browse files Browse the repository at this point in the history
…-master

Elektra backend without master
  • Loading branch information
markus2330 authored Nov 24, 2019
2 parents db2315d + 126b73b commit 7aa6f44
Show file tree
Hide file tree
Showing 36 changed files with 2,555 additions and 224 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ random_seed
/build*/
CMakeLists.txt.user*
*.unc-backup*
/cmake-build-debug/
.idea/
cmake-build-debug/src/kreadcon
fig/CTestTestfile.cmake
20 changes: 20 additions & 0 deletions autotests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include(ECMAddTests)

find_package(Qt5Test ${REQUIRED_QT_VERSION} CONFIG QUIET)
find_package(Qt5Concurrent ${REQUIRED_QT_VERSION} CONFIG QUIET)
find_package(Elektra)

if(NOT Qt5Test_FOUND)
message(STATUS "Qt5Test not found, autotests will not be built.")
Expand Down Expand Up @@ -50,6 +51,25 @@ ecm_add_tests(
LINK_LIBRARIES KF5::ConfigCore Qt5::Test Qt5::Concurrent
)

if (ELEKTRA_FOUND AND NOT DEFINED SkipTest)
include_directories(${ELEKTRA_INCLUDE_DIR})

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")

ecm_add_test(
kconfigelektratest.cpp
../src/core/kconfigelektra.cpp
../src/core/kconfigdata.cpp
../src/core/kconfigbackend.cpp
../src/core/kconfigini.cpp
../cmake-build-debug/src/core/kconfig_core_log_settings.cpp
TEST_NAME kconfigelektra
NAME_PREFIX kconfigcore-
LINK_LIBRARIES KF5::ConfigCore Qt5::Test Qt5::Concurrent ${ELEKTRA_LIBRARIES}
)
add_definitions(-DFEAT_ELEKTRA)
endif ()

target_include_directories(test_kconf_update PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src/kconf_update)

if(TARGET Qt5::Gui)
Expand Down
2 changes: 1 addition & 1 deletion autotests/fallbackconfigresourcestest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private Q_SLOTS:

void FallbackConfigResourcesTest::initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
QStandardPaths::setTestModeEnabled(true); //TODO create and drop expected data (i guess)
}

void FallbackConfigResourcesTest::testResourceFallbackFile()
Expand Down
3 changes: 3 additions & 0 deletions autotests/kconfig_compiler/kconfigcompiler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ static CompilerTestSet willFailCases = {

void KConfigCompiler_Test::initTestCase()
{
#ifdef FEAT_ELEKTRA
QSKIP("test cannot be run currently with Elektra");
#endif
m_diffExe = QStandardPaths::findExecutable( QStringLiteral("diff") );
if (m_diffExe.isEmpty()) {
qDebug() << "diff command not found, detailed info on comparison failure will not be available.";
Expand Down
4 changes: 4 additions & 0 deletions autotests/kconfig_compiler/test4main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ int main(int argc, char **argv)
group.writeEntry(QStringLiteral("foo bar"), QStringLiteral("Value"));
}
Test4 *t = Test4::self();
#ifndef FEAT_ELEKTRA
bool ok = QFile::exists(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/test4rc");
if (!ok) {
qWarning() << "config file was not created!";
}
if (t->fooBar() != QLatin1String("Value")) {
qWarning() << "wrong value for foo bar:" << t->fooBar();
}
#else
bool ok = true;
#endif
delete t;
return ok ? 0 : 1;
}
195 changes: 195 additions & 0 deletions autotests/kconfigelektratest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
//
// Created by felix on 28.10.19.
//

#include <QtTest/QTest>
#include <kconfigdata.h>
#include <kconfigelektra_p.h>
#include <KConfig>
#include <KConfigGroup>
#include <iostream>
#include "kconfigelektratest.h"

#ifdef FEAT_ELEKTRA

QTEST_MAIN(KConfigElektraTest)

using namespace kdb;

void KConfigElektraTest::testBackend ()
{

KDB kdb_local;

KeySet ks;

kdb_local.get(ks, "user/sw/org/kde/elektratest/#0/current/");

ks.append(Key("user/sw/org/kde/elektratest/#0/current/Text Editor/Font/DELETE", KEY_VALUE, "delete me", KEY_END));

kdb_local.set(ks, "user/sw/org/kde/elektratest/#0/current/");

kdb_local.close();
ks.clear();

KEntryMap map;

std::string elektratest = "elektratest";

KConfigElektra elektraBackend(elektratest, 0);
KConfigElektra elektraGlobalBackend("elektratestglobals", 0);

elektraBackend.parseConfig(nullptr, map, nullptr);

QCOMPARE(map.getEntry("<default>", "hello"), "hello");
QCOMPARE(map.getEntry("Text Editor", "preferred"), "kate");
QCOMPARE(map.getEntry("Text Editor\x1d""Font", "Name"), "Arial");

map.setEntry(QByteArray::fromStdString("Text Editor\x1d""Font"),
QByteArray::fromStdString("Color"),
QString::fromStdString("green"),
KEntryMap::EntryDirty);

map.setEntry(QByteArray::fromStdString("Text Editor\x1d""Global"),
QByteArray::fromStdString("The Earth is"),
QString::fromStdString("Globular ... err GLOBAL!"),
KEntryMap::EntryDirty | KEntryMap::EntryGlobal);

map.setEntry(QByteArray::fromStdString("Text Editor\x1d""Font"),
QByteArray::fromStdString("DELETE"),
QByteArray(),
KEntryMap::EntryDeleted);

elektraBackend.writeConfig(nullptr, map, nullptr);
elektraGlobalBackend.writeConfig(nullptr, map, KConfigBackend::WriteGlobal);

KDB kdb_local_check;
ks = KeySet();

kdb_local_check.get(ks, "user/sw/org/kde/elektratest/#0/current");
kdb_local_check.get(ks, "user/sw/org/kde/elektratestglobals/#0/current");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#0/current/hello"), "hello");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#0/current/Text Editor/preferred"), "kate");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#0/current/Text Editor/Font/Name"), "Arial");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#0/current/Text Editor/Font/Color"), "green");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratestglobals/#0/current/Text Editor/Global/The Earth is"),
"Globular ... err GLOBAL!");

QCOMPARE(ks.lookup(Key("user/sw/org/kde/elektratest/#0/current/Text Editor/Font/DELETE", KEY_END)), nullptr);

kdb_local_check.close();
}

void KConfigElektraTest::initTestCase ()
{
KDB kdb_local;

KeySet ks;

kdb_local.get(ks, "user/sw/org/kde/elektratest/#0/current/");

ks.append(Key("user/sw/org/kde/elektratest/#0/current/hello", KEY_VALUE, "hello", KEY_END));
ks.append(Key("user/sw/org/kde/elektratest/#0/current/Text Editor/preferred", KEY_VALUE, "kate", KEY_END));
ks.append(Key("user/sw/org/kde/elektratest/#0/current/Text Editor/Font/Name", KEY_VALUE, "Arial", KEY_END));

kdb_local.set(ks, "user/sw/org/kde/elektratest/#0/current/");

kdb_local.close();
}

void KConfigElektraTest::cleanupTestCase ()
{
KDB kdb_local;

KeySet ks;

kdb_local.get(ks, "user/sw/org/kde/elektratest/#0/current/");

ks.cut(Key("user/sw/org/kde/elektratest/#0/current/", KEY_END));

kdb_local.set(ks, "user/sw/org/kde/elektratest/#0/current/");

ks.clear();

kdb_local.get(ks, "user/sw/org/kde/elektratestglobals/#0/current/");

ks.cut(Key("user/sw/org/kde/elektratestglobals/#0/current/", KEY_END));

kdb_local.set(ks, "user/sw/org/kde/elektratestglobals/#0/current/");

kdb_local.close();
}

void KConfigElektraTest::testKConfigElektraRead ()
{
KConfig kConfig(ElektraInfo{"elektratest", 0, "current"});

KConfigGroup group_default = kConfig.group("<default>");

QCOMPARE(group_default.readEntry("hello", ""), "hello");

KConfigGroup group_text_editor = kConfig.group("Text Editor");

QCOMPARE(group_text_editor.readEntry("preferred", ""), "kate");

KConfigGroup group_text_editor_font = group_text_editor.group("Font");

QCOMPARE(group_text_editor_font.readEntry("Name", ""), "Arial");
}

void KConfigElektraTest::testKConfigElektraWrite ()
{
KConfig kConfig(ElektraInfo("elektratest", 0, "current"));

KConfigGroup group_default = kConfig.group("<default>");
KConfigGroup group_test = kConfig.group("Test");
KConfigGroup group_test_with_space = kConfig.group("Test With Space");
KConfigGroup group_with_subgroup = group_test_with_space.group("Subgroup");

group_test.writeEntry("Testing", "In Progress");
group_test_with_space.writeEntry("Still in", "Progress");
group_with_subgroup.writeEntry("This subgroup is", "also being tested!");
group_default.writeEntry("This is default", "or is it...");

kConfig.sync();

KDB kdb_local_check;
KeySet ks = KeySet();

kdb_local_check.get(ks, "user/sw/org/kde/elektratest/#0/current");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#0/current/This is default"), "or is it...");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#0/current/Test/Testing"), "In Progress");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#0/current/Test With Space/Still in"), "Progress");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#0/current/Test With Space/Subgroup/This subgroup is"),
"also being tested!");
}

void KConfigElektraTest::testKConfigElektraOpenSimpleName ()
{

KConfig kConfig("elektratest");

KConfigGroup group_default = kConfig.group("<default>");
KConfigGroup group_test = kConfig.group("Test");
KConfigGroup group_test_with_space = kConfig.group("Test With Space");
KConfigGroup group_with_subgroup = group_test_with_space.group("Subgroup");

group_test.writeEntry("Testing", "In Progress");
group_test_with_space.writeEntry("Still in", "Progress");
group_with_subgroup.writeEntry("This subgroup is", "also being tested!");
group_default.writeEntry("This is default", "or is it...");

kConfig.sync();

KDB kdb_local_check;
KeySet ks = KeySet();

kdb_local_check.get(ks, "user/sw/org/kde/elektratest/#5/current");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#5/current/This is default"), "or is it...");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#5/current/Test/Testing"), "In Progress");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#5/current/Test With Space/Still in"), "Progress");
QCOMPARE(ks.get<std::string>("user/sw/org/kde/elektratest/#5/current/Test With Space/Subgroup/This subgroup is"),
"also being tested!");
}

#endif //FEAT_ELEKTRA
48 changes: 48 additions & 0 deletions autotests/kconfigelektratest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* This file is part of the KDE libraries
Copyright (C) 2019 Felix Resch ([email protected])
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/

#ifdef FEAT_ELEKTRA

#ifndef KCONFIG_KCONFIGELEKTRATEST_H
#define KCONFIG_KCONFIGELEKTRATEST_H

#include <QObject>

class KConfigElektraTest : public QObject
{

Q_OBJECT

private Q_SLOTS:

void testBackend ();

void initTestCase ();

void cleanupTestCase ();

void testKConfigElektraRead ();

void testKConfigElektraWrite ();

void testKConfigElektraOpenSimpleName ();
};

#endif //KCONFIG_KCONFIGELEKTRATEST_H
#endif //FEAT_ELEKTRA
2 changes: 2 additions & 0 deletions autotests/kconfignokdehometest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ void KConfigNoKdeHomeTest::testNoKdeHome()
KConfigGroup group(KSharedConfig::openConfig(), "Group");
group.writeEntry("Key", "Value");
group.sync();
#ifndef FEAT_ELEKTRA //TODO add Elektra tests
QVERIFY(QFile::exists(configPath));
const QString rcFile = QCoreApplication::applicationName() + QStringLiteral("rc");
QVERIFY(QFile::exists(configPath + QLatin1Char('/') + rcFile));
#endif

// Cleanup
configDir.removeRecursively();
Expand Down
23 changes: 23 additions & 0 deletions autotests/kconfigskeletontest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#include <QFont>
#include <QtTestGui>

#if false
#ifdef FEAT_ELEKTRA
#include <kdb.hpp>
#endif
#endif

QTEST_MAIN(KConfigSkeletonTest)

#define DEFAULT_SETTING1 false
Expand All @@ -38,6 +44,9 @@ QTEST_MAIN(KConfigSkeletonTest)
void KConfigSkeletonTest::initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
#ifdef FEAT_ELEKTRA
QSKIP("Test is currently not possible with Elektra");
#endif
}

void KConfigSkeletonTest::init()
Expand All @@ -61,6 +70,20 @@ void KConfigSkeletonTest::init()
void KConfigSkeletonTest::cleanup()
{
delete s;
//TODO delete keys from Elektra DB
#ifdef false
#ifdef FEAT_ELEKTRA
KDB kdb;

KeySet keySet;

kdb.get(keySet, "user/sw/org/kde/kconfigskeletontestrc/#5/current/");

keySet.cut(Key("user/sw/org/kde/kconfigskeletontestrc/#5/current/", KEY_END));

kdb.set(keySet, "user/sw/org/kde/kconfigskeletontestrc/#5/current/");
#endif
#endif
}

void KConfigSkeletonTest::testSimple()
Expand Down
Loading

0 comments on commit 7aa6f44

Please sign in to comment.