Skip to content
Permalink
Browse files

Add tests and update documentation for the kconfig plugin

  • Loading branch information
darddan committed Nov 29, 2019
1 parent 610b454 commit 10237d352169f1c41d0663dddcdad2f35bf2ab6c
Showing with 62 additions and 3 deletions.
  1. +4 −0 doc/news/_preparation_next_release.md
  2. +10 −2 src/plugins/kconfig/README.md
  3. +48 −1 src/plugins/kconfig/testmod_kconfig.cpp
@@ -43,6 +43,10 @@ The following section lists news about the [modules](https://www.libelektra.org/

- Improved error message for augeas to show lensPath. _(Michael Zronek)_

### KConfig

- We implemented the methods that save a KeySet into a file with the KConfig Ini format. _(Dardan Haxhimustafa)_

### SWIG

- Configure line (-DBINDINGS="..") for SWIG based bindings have been changed from `swig_foo` to `foo`. _(Manuel Mausz)_
@@ -7,11 +7,12 @@
- infos/placements = getstorage setstorage
- infos/status = recommended maintained compatible specific experimental unfinished nodoc concept
- infos/metadata =
- infos/description = Reads the KConfig INI format
- infos/description = Reads and writes the KConfig INI format

## Introduction

This plugin can be used to parse a [KConfig](https://cgit.kde.org/kconfig.git) INI file into a KeySet.
This plugin can be used to parse a [KConfig](https://cgit.kde.org/kconfig.git) INI file into a KeySet, and also write a KeySet to a file in
such a format.

Information about the syntax:

@@ -73,6 +74,13 @@ echo 'key=Value' > `kdb file /tests/kconfig`
kdb get /tests/kconfig/key
#> Value
# Set the value to Example
kdb set /tests/kconfig/key Example
# Verify that the value has changed in the file too
cat `kdb file /tests/kconfig`
#> key=Example
# Manually add a gorup to the database
echo '[group][subgroup]' >> `kdb file /tests/kconfig`
@@ -9,6 +9,7 @@

#include "kconfig.hpp"

#include <fstream>
#include <kdbmodule.h>
#include <kdbprivate.h>

@@ -81,7 +82,7 @@ TEST (kconfig, basics)

succeed_if_same (plugin->kdbGet (plugin, keys.getKeySet (), *parent), ELEKTRA_PLUGIN_STATUS_SUCCESS, "Call of `kdbGet` failed");

succeed_if_same (plugin->kdbSet (plugin, keys.getKeySet (), *parent), ELEKTRA_PLUGIN_STATUS_NO_UPDATE, "Call of `kdbSet` failed");
succeed_if_same (plugin->kdbSet (plugin, keys.getKeySet (), *parent), ELEKTRA_PLUGIN_STATUS_ERROR, "Call of `kdbSet` failed");

succeed_if_same (plugin->kdbError (plugin, keys.getKeySet (), *parent), ELEKTRA_PLUGIN_STATUS_SUCCESS, "Call of `kdbError` failed");

@@ -99,6 +100,52 @@ TEST (kconfig, simple_file_get)
);
}

TEST (kconfig, simple_file_set)
{
// LOAD KConfig module
CppKeySet modules{ 0, KS_END };
CppKeySet config{ 0, KS_END };
CppKey pluginParent{ "system/elektra/modules/kconfig", KEY_END };
elektraModulesInit (modules.getKeySet (), 0);
Plugin * plugin = elektraPluginOpen ("kconfig", modules.getKeySet (), config.getKeySet (), pluginParent.getKey());
exit_if_fail (plugin != NULL, "Could not open kconfig plugin"); //! OCLint (empty if, too few branches switch)

// Create parent key
string filePath = elektraFilename ();
CppKey parent{ "user/namespace", KEY_END };
parent.setString (filePath);

// Create KeySet that we want to save
CppKey key1{ "user/namespace/group/title", KEY_VALUE, "KConfig Test", KEY_END };
CppKey key2{ "user/namespace/group/key[en]", KEY_VALUE, "Hello", KEY_META, "kconfig", "ei", KEY_END };
CppKey key3{ "user/namespace/group/key[de]", KEY_VALUE, "Hallo", KEY_END };
CppKeySet keys;
keys.append (key1);
keys.append (key2);
keys.append (key3);


// Save the KeySet to the file stored in the parent key
succeed_if_same (plugin->kdbSet (plugin, keys.getKeySet (), parent.getKey()), ELEKTRA_PLUGIN_STATUS_SUCCESS, "Call of `kdbSet` failed");


// Load the file and verify that it has the correct format
std::ifstream file {filePath};
std::string tmp;

getline (file, tmp);
succeed_if_same (tmp, "[group]", "");
getline (file, tmp);
succeed_if_same (tmp, "key[de]=Hallo", "");
getline (file, tmp);
succeed_if_same (tmp, "key[en][$e][$i]=Hello", "");
getline (file, tmp);
succeed_if_same (tmp, "title=KConfig Test", "");

file.close();

}

TEST (kconfig, meta_file_get)
{
test_read ("kconfig/meta_examplerc",

0 comments on commit 10237d3

Please sign in to comment.
You can’t perform that action at this time.