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