forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 1
/
testapp.c
112 lines (86 loc) · 2.02 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* @file
*
* @brief Tests for specload plugin
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <kdb.h>
#include <kdbopts.h>
#include <kdbplugin.h>
#include <tests_plugin.h>
#include "testdata.h"
extern char ** environ;
static KeySet * getSpec (const char * name, Key ** parentKey)
{
*parentKey = keyNew ("spec/tests/gopts", KEY_END);
if (strcmp (name, TEST_EMPTY) == 0)
{
return TEST_KS_EMPTY;
}
if (strcmp (name, TEST_SINGLEOPT) == 0)
{
return TEST_KS_SINGLEOPT;
}
if (strcmp (name, TEST_TWOOPT) == 0)
{
return TEST_KS_TWOOPT;
}
if (strcmp (name, TEST_SINGLEENV) == 0)
{
return TEST_KS_SINGLEENV;
}
if (strcmp (name, TEST_TWOENV) == 0)
{
return TEST_KS_TWOENV;
}
if (strcmp (name, TEST_MIXED) == 0)
{
return TEST_KS_MIXED;
}
yield_error ("unknown spec name");
printf ("specname: %s\n", name);
exit (EXIT_FAILURE);
}
int main (int argc, const char ** argv)
{
const char * specname = argv[1];
const char * appname = argv[0];
argv[1] = appname;
Key * parentKey;
KeySet * ks = getSpec (specname, &parentKey);
bool libFailed = elektraGetOpts (ks, argc - 1, &argv[1], (const char **) environ, parentKey) != 0;
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("gopts");
Key * parentKey2;
KeySet * ks2 = getSpec (specname, &parentKey2);
bool pluginFailed = plugin->kdbGet (plugin, ks2, parentKey2) == ELEKTRA_PLUGIN_STATUS_ERROR;
if (pluginFailed != libFailed)
{
PLUGIN_CLOSE ();
ksDel (ks);
keyDel (parentKey);
ksDel (ks2);
keyDel (parentKey2);
char buf[256];
strcpy (buf, "elektraGetOpts (");
strcat (buf, libFailed ? "FAIL" : "OK");
strcat (buf, ") differs from plugin->get (");
strcat (buf, pluginFailed ? "FAIL" : "OK");
strcat (buf, "): ");
strncat (buf, specname, 128);
yield_error (buf);
return nbError;
}
compare_key (parentKey, parentKey2);
compare_keyset (ks, ks2);
PLUGIN_CLOSE ();
ksDel (ks);
keyDel (parentKey);
ksDel (ks2);
keyDel (parentKey2);
return nbError;
}