source: trunk/src/cutest_sh_tools.c@ 375

Last change on this file since 375 was 295, checked in by katerina, 14 years ago

Support for IPv6 (ticket #222).

File size: 3.1 KB
RevLine 
[17]1
2#include "config_xor.h"
3
4#include <string.h>
5#include "CuTest.h"
[19]6#include "samhain.h"
[17]7#include "sh_tools.h"
[295]8#include "sh_ipvx.h"
[17]9
10void Test_sh_tools_safe_name_01(CuTest *tc) {
11 /* xml specific */
12 char* input = strdup("hello<wo>rld\"foo&");
13 char* actual = sh_tools_safe_name(input, 1);
14#ifdef SH_USE_XML
15 char* expected = "hello=3cwo=3erld=22foo=26";
16#else
17 char* expected = "hello<wo>rld\"foo&";
18#endif
19 CuAssertStrEquals(tc, expected, actual);
20}
21
22void Test_sh_tools_safe_name_02(CuTest *tc) {
23 /* html entities */
24 char* input = strdup("hello&amp;&quot;&gt;&lt;");
25 char* actual = sh_tools_safe_name(input, 0);
26 char* expected = "hello=26=22=3e=3c";
27 CuAssertStrEquals(tc, expected, actual);
28}
29
30void Test_sh_tools_safe_name_03(CuTest *tc) {
31 char* input = strdup("\\\'hello\\");
32 char* actual = sh_tools_safe_name(input, 0);
33 char* expected = "=27hello";
34 CuAssertStrEquals(tc, expected, actual);
35
36 input = strdup("hello \"world\\\"");
37 actual = sh_tools_safe_name(input, 0);
38 expected = "hello \"world=22";
39 CuAssertStrEquals(tc, expected, actual);
40
41 input = strdup("hello\\\\");
42 actual = sh_tools_safe_name(input, 0);
43 expected = "hello=5c";
44 CuAssertStrEquals(tc, expected, actual);
45
46 input = strdup("hello\\n");
47 actual = sh_tools_safe_name(input, 0);
48 expected = "hello=0a";
49 CuAssertStrEquals(tc, expected, actual);
50}
51
52void Test_sh_tools_safe_name_04(CuTest *tc) {
53 /* invalid and valid octal code */
54 char* input = strdup("hello\\\n");
55 char* actual = sh_tools_safe_name(input, 0);
56 char* expected = "hello";
57 CuAssertStrEquals(tc, expected, actual);
58
59 input = strdup("hello\\100");
60 actual = sh_tools_safe_name(input, 0);
61 expected = "hello=40";
62 CuAssertStrEquals(tc, expected, actual);
63
64 input = strdup("h\\\"ello\\100a");
65 actual = sh_tools_safe_name(input, 0);
66 expected = "h=22ello=40a";
67 CuAssertStrEquals(tc, expected, actual);
68}
69
70void Test_sh_tools_safe_name_05(CuTest *tc) {
71 /* encoding of '=' */
72 char* input = strdup("he=llo=\"foo\"");
73 char* actual = sh_tools_safe_name(input, 0);
74 char* expected = "he=3dllo=\"foo\"";
75 CuAssertStrEquals(tc, expected, actual);
76
77 input = strdup("he=llo=<foo>");
78 actual = sh_tools_safe_name(input, 0);
79 expected = "he=3dllo=<foo>";
80 CuAssertStrEquals(tc, expected, actual);
81}
82
83void Test_sh_tools_safe_name_06(CuTest *tc) {
84 /* line break removal */
85 char* input = strdup("hello\nworld");
86 char* actual = sh_tools_safe_name(input, 0);
87 char* expected = "hello world";
88 CuAssertStrEquals(tc, expected, actual);
89}
90
91void Test_sh_tools_safe_name_07(CuTest *tc) {
92 /* non-printable chars */
93 char* input = strdup("hello world");
94 char* actual;
95 char* expected;
96
97 input[0] = 0x01;
98 input[5] = 0xFF;
99 input[10] = 0xF0;
100
101 actual = sh_tools_safe_name(input, 0);
102 expected = "=01ello=ffworl=f0";
103 CuAssertStrEquals(tc, expected, actual);
104}
105
106void Test_is_numeric_01(CuTest *tc) {
107 char* input = strdup("hello world");
108
[295]109 CuAssertTrue(tc, !sh_ipvx_is_numeric(input));
[17]110
111 input = strdup("127.0.0.1");
[295]112 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
[17]113 input = strdup("127.0.0.de");
[295]114 CuAssertTrue(tc, !sh_ipvx_is_numeric(input));
[17]115 input = strdup("127");
[295]116 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
[17]117}
118
Note: See TracBrowser for help on using the repository browser.