-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
60c908e
d9e4341
b56c713
b49010b
5563643
dcb497c
f9a4566
7d54abd
762fb61
abf0a72
f15a8bb
f8e8fa9
ba46b2d
8a17e9a
875fe3a
cedc446
362159b
b03da9a
9e3794f
230ec3d
033187d
126b73b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ private Q_SLOTS: | |
|
||
void FallbackConfigResourcesTest::initTestCase() | ||
{ | ||
QStandardPaths::setTestModeEnabled(true); | ||
QStandardPaths::setTestModeEnabled(true); //TODO create and drop expected data (i guess) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i will create the issues today in the afternoon |
||
} | ||
|
||
void FallbackConfigResourcesTest::testResourceFallbackFile() | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newline? |
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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