Skip to content

Commit

Permalink
Add tests and update documentation for the kconfig plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
darddan committed Nov 24, 2019
1 parent 7a9ff1f commit 9891e6d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/news/_preparation_next_release.md
Expand Up @@ -89,6 +89,7 @@ plugins. _(René Schwaiger)_
### KConfig

- We added a plugin which can be used to parse kconfig ini files into a keyset and save keysets to such files. _(Dardan Haxhimustafa)_
- We implemented the methods that save a KeySet into a file with the KConfig Ini format. _(Dardan Haxhimustafa)_

### Mmapstorage

Expand Down
13 changes: 11 additions & 2 deletions src/plugins/kconfig/README.md
Expand Up @@ -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:

Expand Down Expand Up @@ -73,6 +74,14 @@ echo 'key=Value' > `kdb file /tests/kconfig`
kdb get /tests/kconfig/key
#> Value

# Set the value to Example
kdb set /tests/kconfig/key Example
#> Set string to "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`

Expand Down
49 changes: 48 additions & 1 deletion src/plugins/kconfig/testmod_kconfig.cpp
Expand Up @@ -9,6 +9,7 @@

#include "kconfig.hpp"

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

Expand Down Expand Up @@ -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");

Expand All @@ -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",
Expand Down

0 comments on commit 9891e6d

Please sign in to comment.