Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Tests for mozprefs plugin
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #include <stdlib.h>
11 : #include <string.h>
12 :
13 : #include <kdbconfig.h>
14 :
15 : #include <tests_plugin.h>
16 :
17 :
18 2 : static void test_readPref (char * fileName)
19 : {
20 2 : Key * parentKey = keyNew ("user/tests/pref-read", KEY_VALUE, srcdir_file (fileName), KEY_END);
21 2 : KeySet * conf = ksNew (0, KS_END);
22 :
23 2 : PLUGIN_OPEN ("mozprefs");
24 :
25 2 : KeySet * ks = ksNew (0, KS_END);
26 :
27 2 : succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
28 2 : Key * key = ksLookupByName (ks, "user/tests/pref-read/user/a/user/key", KDB_O_NONE);
29 2 : exit_if_fail (key, "Key a.user.key not found");
30 2 : succeed_if (!strcmp (keyString (key), "usertest"), "Key a.user.key contains invalid data");
31 2 : key = ksLookupByName (ks, "user/tests/pref-read/lock/a/lock/key", KDB_O_NONE);
32 2 : exit_if_fail (key, "Key a.lock.key not found");
33 2 : succeed_if (!strcmp (keyString (key), "true"), "Key a.lock.key contains invalid data");
34 2 : key = ksLookupByName (ks, "user/tests/pref-read/pref/a/default/key", KDB_O_NONE);
35 2 : exit_if_fail (key, "Key a.default.key not found");
36 2 : succeed_if (!strcmp (keyString (key), "1"), "Key a.default.key contains invalid data");
37 2 : key = ksLookupByName (ks, "user/tests/pref-read/sticky/a/sticky/key", KDB_O_NONE);
38 2 : exit_if_fail (key, "Key a.sticky.key not found");
39 2 : succeed_if (!strcmp (keyString (key), "false"), "Key a.sticky.key contains invalid data");
40 2 : ksDel (ks);
41 2 : keyDel (parentKey);
42 2 : PLUGIN_CLOSE ();
43 2 : }
44 :
45 2 : static void test_writePref (char * fileName)
46 : {
47 2 : Key * parentKey = keyNew ("user/tests/pref-write", KEY_VALUE, elektraFilename (), KEY_END);
48 2 : KeySet * conf = ksNew (0, KS_END);
49 :
50 2 : PLUGIN_OPEN ("mozprefs");
51 :
52 2 : KeySet * ks = ksNew (
53 : 30, keyNew ("user/tests/pref-write/user/a/user/key", KEY_VALUE, "usertest", KEY_META, "type", "string", KEY_END),
54 : keyNew ("user/tests/pref-write/lock/a/lock/key", KEY_VALUE, "true", KEY_META, "type", "boolean", KEY_END),
55 : keyNew ("user/tests/pref-write/pref/a/default/key", KEY_VALUE, "1", KEY_META, "type", "integer", KEY_END),
56 : keyNew ("user/tests/pref-write/sticky/a/sticky/key", KEY_VALUE, "false", KEY_META, "type", "boolean", KEY_END), KS_END);
57 :
58 2 : succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 1, "call to kdbSet was not successful");
59 :
60 2 : succeed_if (compare_line_files (srcdir_file (fileName), keyString (parentKey)), "files do not match as expected");
61 :
62 2 : ksDel (ks);
63 2 : keyDel (parentKey);
64 2 : PLUGIN_CLOSE ();
65 2 : }
66 :
67 2 : int main (int argc, char ** argv)
68 : {
69 2 : printf ("PREFS TESTS\n");
70 2 : printf ("==================\n\n");
71 :
72 2 : init (argc, argv);
73 :
74 :
75 2 : test_readPref ("mozprefs/prefs.js");
76 2 : test_writePref ("mozprefs/prefs.js");
77 :
78 2 : print_result ("testmod_mozprefs");
79 :
80 2 : return nbError;
81 : }
|