Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Tests for specload plugin
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #include <stdio.h>
11 : #include <stdlib.h>
12 :
13 : #include <kdb.h>
14 : #include <kdbopts.h>
15 : #include <kdbplugin.h>
16 :
17 : #include <tests_plugin.h>
18 :
19 : #include "testdata.h"
20 :
21 : extern char ** environ;
22 :
23 184 : static KeySet * getSpec (const char * name, Key ** parentKey)
24 : {
25 184 : *parentKey = keyNew ("spec/tests/gopts", KEY_END);
26 :
27 184 : if (strcmp (name, TEST_EMPTY) == 0)
28 : {
29 4 : return TEST_KS_EMPTY;
30 : }
31 :
32 180 : if (strcmp (name, TEST_SINGLEOPT) == 0)
33 : {
34 40 : return TEST_KS_SINGLEOPT;
35 : }
36 :
37 140 : if (strcmp (name, TEST_TWOOPT) == 0)
38 : {
39 84 : return TEST_KS_TWOOPT;
40 : }
41 :
42 56 : if (strcmp (name, TEST_SINGLEENV) == 0)
43 : {
44 12 : return TEST_KS_SINGLEENV;
45 : }
46 :
47 44 : if (strcmp (name, TEST_TWOENV) == 0)
48 : {
49 24 : return TEST_KS_TWOENV;
50 : }
51 :
52 20 : if (strcmp (name, TEST_MIXED) == 0)
53 : {
54 20 : return TEST_KS_MIXED;
55 : }
56 :
57 0 : yield_error ("unknown spec name");
58 0 : printf ("specname: %s\n", name);
59 0 : exit (EXIT_FAILURE);
60 : }
61 :
62 92 : int main (int argc, const char ** argv)
63 : {
64 92 : const char * specname = argv[1];
65 92 : const char * appname = argv[0];
66 92 : argv[1] = appname;
67 :
68 : Key * parentKey;
69 92 : KeySet * ks = getSpec (specname, &parentKey);
70 :
71 92 : bool libFailed = elektraGetOpts (ks, argc - 1, &argv[1], (const char **) environ, parentKey) != 0;
72 :
73 92 : KeySet * conf = ksNew (0, KS_END);
74 :
75 92 : PLUGIN_OPEN ("gopts");
76 :
77 : Key * parentKey2;
78 92 : KeySet * ks2 = getSpec (specname, &parentKey2);
79 :
80 92 : bool pluginFailed = plugin->kdbGet (plugin, ks2, parentKey2) == ELEKTRA_PLUGIN_STATUS_ERROR;
81 :
82 92 : if (pluginFailed != libFailed)
83 : {
84 0 : PLUGIN_CLOSE ();
85 0 : ksDel (ks);
86 0 : keyDel (parentKey);
87 0 : ksDel (ks2);
88 0 : keyDel (parentKey2);
89 : char buf[256];
90 0 : strcpy (buf, "elektraGetOpts (");
91 0 : strcat (buf, libFailed ? "FAIL" : "OK");
92 0 : strcat (buf, ") differs from plugin->get (");
93 0 : strcat (buf, pluginFailed ? "FAIL" : "OK");
94 0 : strcat (buf, "): ");
95 0 : strncat (buf, specname, 128);
96 0 : yield_error (buf);
97 :
98 0 : return nbError;
99 : }
100 :
101 92 : compare_key (parentKey, parentKey2);
102 92 : compare_keyset (ks, ks2);
103 :
104 92 : PLUGIN_CLOSE ();
105 :
106 92 : ksDel (ks);
107 92 : keyDel (parentKey);
108 92 : ksDel (ks2);
109 92 : keyDel (parentKey2);
110 :
111 92 : return nbError;
112 : }
|