Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elektra backend without master #14

Merged
merged 22 commits into from
Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
60c908e
Added benchmarking application
Oct 3, 2019
d9e4341
Merge branch 'master' of github.com:ElektraInitiative/kconfig
Oct 10, 2019
b56c713
added optional linking with libElektra
FelixResch Oct 28, 2019
b49010b
added minimal viable backend
FelixResch Oct 30, 2019
5563643
Merge branch 'master' into elektra-backend
FelixResch Oct 30, 2019
dcb497c
WIP: use elektra-backend in kconfig
FelixResch Nov 2, 2019
f9a4566
minimum working version of the elektra-backend
FelixResch Nov 2, 2019
7d54abd
small fixes to test elektra backend
FelixResch Nov 12, 2019
762fb61
fixed manual opening with only app name
FelixResch Nov 14, 2019
abf0a72
WIP: fixed many tests but still need to check if it works
FelixResch Nov 17, 2019
f15a8bb
WIP: added headers to cmake targets
FelixResch Nov 19, 2019
f8e8fa9
WIP: added private headers so it hopefully compiles
FelixResch Nov 19, 2019
ba46b2d
WIP: fixed headers
FelixResch Nov 19, 2019
8a17e9a
WIP: fixed headers (again)
FelixResch Nov 19, 2019
875fe3a
WIP: fixed headers (and again)
FelixResch Nov 19, 2019
cedc446
finished reformatting and skipped tests, which are not working with e…
FelixResch Nov 19, 2019
362159b
added some documentation
FelixResch Nov 19, 2019
b03da9a
commit without changes from upstream master
FelixResch Nov 20, 2019
9e3794f
Update autotests/kconfigskeletontest.cpp
FelixResch Nov 21, 2019
230ec3d
added changes suggested by markus
FelixResch Nov 21, 2019
033187d
added improvements suggested by dardan
FelixResch Nov 23, 2019
126b73b
changed URLs to include the full Elektra path
FelixResch Nov 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these sources required? It would be better if we can test directly against the public interfaces.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need those sources to test the backend directly

../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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better if you create issues and not TODOs or FIXMEs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will create the issues today in the afternoon

}

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to exclude the whole file in CMake


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline?

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