source: trunk/src/cutest_sh_hash.c@ 183

Last change on this file since 183 was 149, checked in by katerina, 17 years ago

Make sh_hash.c thread-safe, remove plenty of tiny allocations, improve sh_mem_dump, modify port check to run as thread, and fix unsetting of sh_thread_pause_flag (was too early).

File size: 2.8 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, size_t len);
8extern char * unquote_string (const char * str, size_t len);
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, strlen(inp1));
22 CuAssertPtrNotNull(tc, ret);
23 CuAssertStrEquals(tc, out1, ret);
24
25 ret = quote_string(inp2,strlen(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, strlen(inp1));
48 CuAssertPtrNotNull(tc, ret);
49 CuAssertStrEquals(tc, out1, ret);
50
51 ret = unquote_string(inp2, strlen(inp2));
52 CuAssertPtrNotNull(tc, ret);
53 CuAssertStrEquals(tc, out2, ret);
54
55 ret = unquote_string(inp3, strlen(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
65void Test_csv_escape_ok (CuTest *tc) {
66#if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
67
68 extern char * csv_escape(const char * str);
69
70 char test0[80];
71 char expec[80];
72 char *ret;
73
74 strcpy(test0, "foobar");
75 strcpy(expec, "\"foobar\"");
76 ret = csv_escape(test0);
77 CuAssertStrEquals(tc, expec, ret);
78
79 strcpy(test0, "\"foobar\"");
80 strcpy(expec, "\"\"\"foobar\"\"\"");
81 ret = csv_escape(test0);
82 CuAssertStrEquals(tc, expec, ret);
83
84 strcpy(test0, "foo,bar");
85 strcpy(expec, "\"foo,bar\"");
86 ret = csv_escape(test0);
87 CuAssertStrEquals(tc, expec, ret);
88
89 strcpy(test0, "foob,\"a\"r");
90 strcpy(expec, "\"foob,\"\"a\"\"r\"");
91 ret = csv_escape(test0);
92 CuAssertStrEquals(tc, expec, ret);
93
94 strcpy(test0, "\",\"foobar\",\"");
95 strcpy(expec, "\"\"\",\"\"foobar\"\",\"\"\"");
96 ret = csv_escape(test0);
97 CuAssertStrEquals(tc, expec, ret);
98
99 strcpy(test0, "");
100 strcpy(expec, "");
101 ret = csv_escape(test0);
102 CuAssertStrEquals(tc, expec, ret);
103
104 strcpy(test0, "a");
105 strcpy(expec, "\"a\"");
106 ret = csv_escape(test0);
107 CuAssertStrEquals(tc, expec, ret);
108
109 strcpy(test0, "foo\"bar");
110 strcpy(expec, "\"foo\"\"bar\"");
111 ret = csv_escape(test0);
112 CuAssertStrEquals(tc, expec, ret);
113
114#else
115 (void) tc; /* fix compiler warning */
116#endif
117 return;
118}
119
120
121
Note: See TracBrowser for help on using the repository browser.