forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testapp.c
76 lines (61 loc) · 1.43 KB
/
testapp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* @file
*
* @brief Tests for specload plugin
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*
*/
#include <stdlib.h>
#include <string.h>
#include <kdbinvoke.h>
#include <kdbmodule.h>
#include "testdata.h"
// keep #ifdef in sync with kdb export
#ifdef _WIN32
#define STDOUT_FILENAME ("CON")
#else
#define STDOUT_FILENAME ("/dev/stdout")
#endif
static int outputKeySet (KeySet * ks)
{
Key * parentKey = keyNew (PARENT_KEY, KEY_END);
KeySet * specloadConf = ksNew (1, keyNew ("system/sendspec", KEY_END), KS_END);
ElektraInvokeHandle * specload = elektraInvokeOpen ("specload", specloadConf, parentKey);
int result = elektraInvoke2Args (specload, "sendspec", ks, parentKey);
elektraInvokeClose (specload, parentKey);
keyDel (parentKey);
ksDel (specloadConf);
return result == ELEKTRA_PLUGIN_STATUS_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
}
static int outputDefaultSpec (void)
{
KeySet * ks = DEFAULT_SPEC;
int result = outputKeySet (ks);
ksDel (ks);
return result;
}
static int outputSpec (const char * name)
{
if (strcmp (name, "default") == 0)
{
return outputDefaultSpec ();
}
return EXIT_FAILURE;
}
int main (int argc, const char ** argv)
{
if (argc != 2 && argc != 3)
{
return EXIT_FAILURE;
}
if (strcmp (argv[1], "--elektra-spec") == 0)
{
return outputDefaultSpec ();
}
else if (strcmp (argv[1], "spec") == 0 && argc == 3)
{
return outputSpec (argv[2]);
}
return EXIT_FAILURE;
}