1 |
|
---|
2 | #include "config_xor.h"
|
---|
3 |
|
---|
4 | #include <string.h>
|
---|
5 | #include "CuTest.h"
|
---|
6 | #include "samhain.h"
|
---|
7 | #include "sh_utils.h"
|
---|
8 |
|
---|
9 | void Test_sh_util_strdup_ok (CuTest *tc) {
|
---|
10 | char * ret = 0;
|
---|
11 | char inp[] = "foobar";
|
---|
12 |
|
---|
13 | ret = sh_util_strdup(inp);
|
---|
14 | CuAssertPtrNotNull(tc, ret);
|
---|
15 | CuAssert(tc, "expected inp != ret, but inp == ret", (inp != ret));
|
---|
16 | CuAssertStrEquals(tc, "foobar", ret);
|
---|
17 | return;
|
---|
18 | }
|
---|
19 |
|
---|
20 | void Test_sh_util_strconcat_ok (CuTest *tc) {
|
---|
21 | char * ret = 0;
|
---|
22 |
|
---|
23 | ret = sh_util_strconcat("foo", NULL);
|
---|
24 | CuAssertPtrNotNull(tc, ret);
|
---|
25 | CuAssertStrEquals(tc, "foo", ret);
|
---|
26 |
|
---|
27 | ret = sh_util_strconcat("foo", "bar", NULL);
|
---|
28 | CuAssertPtrNotNull(tc, ret);
|
---|
29 | CuAssertStrEquals(tc, "foobar", ret);
|
---|
30 |
|
---|
31 | ret = sh_util_strconcat("/", "foo", "/", "bar", NULL);
|
---|
32 | CuAssertPtrNotNull(tc, ret);
|
---|
33 | CuAssertStrEquals(tc, "/foo/bar", ret);
|
---|
34 |
|
---|
35 | return;
|
---|
36 | }
|
---|
37 |
|
---|
38 | void Test_sh_util_dirname_ok (CuTest *tc) {
|
---|
39 | char * ret = 0;
|
---|
40 |
|
---|
41 | char input0[] = "/foo/bar";
|
---|
42 | char res0[] = "/foo";
|
---|
43 |
|
---|
44 | char input1[] = "/foo/bar/";
|
---|
45 | char res1[] = "/foo";
|
---|
46 |
|
---|
47 | char input2[] = "/foo";
|
---|
48 | char res2[] = "/";
|
---|
49 |
|
---|
50 | char input3[] = "/";
|
---|
51 | char res3[] = "/";
|
---|
52 |
|
---|
53 | ret = sh_util_dirname(input0);
|
---|
54 | CuAssertPtrNotNull(tc, ret);
|
---|
55 | CuAssertStrEquals(tc, res0, ret);
|
---|
56 |
|
---|
57 | ret = sh_util_dirname(input1);
|
---|
58 | CuAssertPtrNotNull(tc, ret);
|
---|
59 | CuAssertStrEquals(tc, res1, ret);
|
---|
60 |
|
---|
61 | ret = sh_util_dirname(input2);
|
---|
62 | CuAssertPtrNotNull(tc, ret);
|
---|
63 | CuAssertStrEquals(tc, res2, ret);
|
---|
64 |
|
---|
65 | ret = sh_util_dirname(input3);
|
---|
66 | CuAssertPtrNotNull(tc, ret);
|
---|
67 | CuAssertStrEquals(tc, res3, ret);
|
---|
68 | return;
|
---|
69 | }
|
---|
70 |
|
---|
71 | void Test_sh_util_basename_ok (CuTest *tc) {
|
---|
72 | char * ret = 0;
|
---|
73 |
|
---|
74 | char input0[] = "/foo/bar";
|
---|
75 | char res0[] = "bar";
|
---|
76 |
|
---|
77 | char input1[] = "/foo/";
|
---|
78 | char res1[] = "foo";
|
---|
79 |
|
---|
80 | char input2[] = "/foo";
|
---|
81 | char res2[] = "foo";
|
---|
82 |
|
---|
83 | char input3[] = "/";
|
---|
84 | char res3[] = "/";
|
---|
85 |
|
---|
86 | char input4[] = "/foo/bar/";
|
---|
87 | char res4[] = "bar";
|
---|
88 |
|
---|
89 | ret = sh_util_basename(input0);
|
---|
90 | CuAssertPtrNotNull(tc, ret);
|
---|
91 | CuAssertStrEquals(tc, res0, ret);
|
---|
92 |
|
---|
93 | ret = sh_util_basename(input1);
|
---|
94 | CuAssertPtrNotNull(tc, ret);
|
---|
95 | CuAssertStrEquals(tc, res1, ret);
|
---|
96 |
|
---|
97 | ret = sh_util_basename(input2);
|
---|
98 | CuAssertPtrNotNull(tc, ret);
|
---|
99 | CuAssertStrEquals(tc, res2, ret);
|
---|
100 |
|
---|
101 | ret = sh_util_basename(input3);
|
---|
102 | CuAssertPtrNotNull(tc, ret);
|
---|
103 | CuAssertStrEquals(tc, res3, ret);
|
---|
104 |
|
---|
105 | ret = sh_util_basename(input4);
|
---|
106 | CuAssertPtrNotNull(tc, ret);
|
---|
107 | CuAssertStrEquals(tc, res4, ret);
|
---|
108 |
|
---|
109 | return;
|
---|
110 | }
|
---|
111 |
|
---|
112 | void Test_sh_util_obscure_ok (CuTest *tc) {
|
---|
113 |
|
---|
114 | int ret = 0;
|
---|
115 | #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
|
---|
116 | char input[16] = "foobar";
|
---|
117 |
|
---|
118 | ret = sh_util_obscure_ok ("0xA1,0xA2,0xA3");
|
---|
119 | CuAssertIntEquals(tc, ret, 0);
|
---|
120 |
|
---|
121 | ret = sh_util_obscurename (0, input, S_FALSE /* no log message */);
|
---|
122 | CuAssertIntEquals(tc, ret, 0);
|
---|
123 |
|
---|
124 | input[0] = '\t';
|
---|
125 | ret = sh_util_obscurename (0, input, S_FALSE /* no log message */);
|
---|
126 | CuAssertIntEquals(tc, ret, -1);
|
---|
127 |
|
---|
128 | input[0] = 0xA1;
|
---|
129 | ret = sh_util_obscurename (0, input, S_FALSE /* no log message */);
|
---|
130 | CuAssertIntEquals(tc, ret, 0);
|
---|
131 |
|
---|
132 | input[0] = 0xA2;
|
---|
133 | ret = sh_util_obscurename (0, input, S_FALSE /* no log message */);
|
---|
134 | CuAssertIntEquals(tc, ret, 0);
|
---|
135 |
|
---|
136 | input[0] = 0xA3;
|
---|
137 | ret = sh_util_obscurename (0, input, S_FALSE /* no log message */);
|
---|
138 | CuAssertIntEquals(tc, ret, 0);
|
---|
139 |
|
---|
140 | input[0] = 0xA4;
|
---|
141 | ret = sh_util_obscurename (0, input, S_FALSE /* no log message */);
|
---|
142 | CuAssertIntEquals(tc, ret, -1);
|
---|
143 |
|
---|
144 | #else
|
---|
145 | CuAssertIntEquals(tc, ret, 0);
|
---|
146 | #endif
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|