forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestmod_quickdump.c
110 lines (78 loc) · 2.3 KB
/
testmod_quickdump.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
/**
* @file
*
* @brief Tests for quickdump plugin
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*
*/
#include <stdlib.h>
#include <string.h>
#include <kdbconfig.h>
#include <tests_plugin.h>
#include <stdio.h>
#include <unistd.h>
#include "quickdump/test.quickdump.h"
static int compare_binary_files (const char * filename1, const char * filename2)
{
FILE * f1 = fopen (filename1, "rb");
FILE * f2 = fopen (filename2, "rb");
int result = 0;
int c1, c2;
while (result == 0 && (c1 = fgetc (f1)) != EOF && (c2 = fgetc (f2)) != EOF)
{
result = c1 - c2;
}
if (result == 0)
{
int end1 = fgetc (f1) == EOF && feof (f1) != 0;
int end2 = fgetc (f2) == EOF && feof (f2) != 0;
result = end1 - end2;
}
fclose (f1);
fclose (f2);
return result;
}
static void test_basics (void)
{
printf ("test basics");
KeySet * ks = ksNew (0, KS_END);
char * infile = elektraStrDup (srcdir_file ("quickdump/test.quickdump"));
char * outfile = elektraStrDup (srcdir_file ("quickdump/test.quickdump.out"));
{
Key * getKey = keyNew ("dir/tests/bench", KEY_VALUE, infile, KEY_END);
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("quickdump");
KeySet * expected = test_quickdump_expected ();
succeed_if (plugin->kdbGet (plugin, ks, getKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbGet was not successful");
compare_keyset (expected, ks);
Key * k1 = ksLookupByName (ks, "dir/tests/bench/__112", 0);
Key * k8 = ksLookupByName (ks, "dir/tests/bench/__911", 0);
succeed_if (keyGetMeta (k1, "meta/_35") == keyGetMeta (k8, "meta/_35"), "copy meta failed");
ksDel (expected);
keyDel (getKey);
PLUGIN_CLOSE ();
}
{
Key * setKey = keyNew ("dir/tests/bench", KEY_VALUE, outfile, KEY_END);
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("quickdump");
succeed_if (plugin->kdbSet (plugin, ks, setKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "call to kdbSet was not successful");
succeed_if (compare_binary_files (infile, outfile) == 0, "files differ");
remove (outfile);
keyDel (setKey);
PLUGIN_CLOSE ();
}
elektraFree (infile);
elektraFree (outfile);
ksDel (ks);
}
int main (int argc, char ** argv)
{
printf ("QUICKDUMP TESTS\n");
printf ("==================\n\n");
init (argc, argv);
test_basics ();
print_result ("testmod_quickdump");
return nbError;
}