source: branches/samhain-2_2-branch/src/cutest_sh_hash.c@ 219

Last change on this file since 219 was 33, checked in by katerina, 19 years ago

Unit test addition

File size: 1.4 KB
Line 
1
2#include "config_xor.h"
3
4#include <string.h>
5#include "CuTest.h"
6
7extern char * quote_string (const char * str);
8extern char * unquote_string (const char * str);
9
10void Test_quote_string_ok (CuTest *tc) {
11
12#if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
13 char * ret = 0;
14
15 char inp1[] = "foo\nba=r\ntest";
16 char out1[] = "foo=0Aba=3Dr=0Atest";
17
18 char inp2[] = "\n=foo\nba=r\ntest=\n";
19 char out2[] = "=0A=3Dfoo=0Aba=3Dr=0Atest=3D=0A";
20
21 ret = quote_string(inp1);
22 CuAssertPtrNotNull(tc, ret);
23 CuAssertStrEquals(tc, out1, ret);
24
25 ret = quote_string(inp2);
26 CuAssertPtrNotNull(tc, ret);
27 CuAssertStrEquals(tc, out2, ret);
28#else
29 (void) tc; /* fix compiler warning */
30#endif
31 return;
32}
33
34void Test_unquote_string_ok (CuTest *tc) {
35#if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
36 char * ret = 0;
37
38 char out1[] = "foo\nba=r\ntes[t";
39 char inp1[] = "foo=0Aba=3Dr=0Ates=5Bt";
40
41 char out2[] = "\n=foo\nba=r\ntest=\n";
42 char inp2[] = "=0A=3Dfoo=0Aba=3Dr=0Atest=3D=0A";
43
44 char out3[] = ""; /* encoded '\0' at start */
45 char inp3[] = "=00=3Dfoo=0Aba=3Dr=0Atest=3D=0A";
46
47 ret = unquote_string(inp1);
48 CuAssertPtrNotNull(tc, ret);
49 CuAssertStrEquals(tc, out1, ret);
50
51 ret = unquote_string(inp2);
52 CuAssertPtrNotNull(tc, ret);
53 CuAssertStrEquals(tc, out2, ret);
54
55 ret = unquote_string(inp3);
56 CuAssertPtrNotNull(tc, ret);
57 CuAssertStrEquals(tc, out3, ret);
58#else
59 (void) tc; /* fix compiler warning */
60#endif
61 return;
62}
63
64
65
Note: See TracBrowser for help on using the repository browser.