1 /* $Id$
2 */
3
4
5 #include<stdio.h>
6 #include "../../huskylib/huskylib.h"
7
printStrArrayInfo(s_str_array * ss)8 void printStrArrayInfo(s_str_array *ss)
9 {
10 int ii;
11 printf("%d tokens found\n", ss->count);
12 for(ii=0; ii < ss->count-1; ++ii)
13 printf("\"%s\", ", STR_N(ss, ii));
14 printf("\"%s\"\n", STR_N(ss, ii));
15 }
16
main(void)17 int main(void)
18 {
19 s_str_array *ss, *ssc;
20 char *test_string = " \tt1 t3, ,,t3\t,t4\tt5,t6\t ttt7 , "; /* that's right, 2xt3 */
21 int ii;
22 char *converted;
23 printf("test string = \"%s\"\n", test_string);
24 ss = makeStrArray(test_string);
25 printStrArrayInfo(ss);
26
27 printf("Testing copy...\n");
28 ssc = copyStrArray(ss);
29 printStrArrayInfo(ssc);
30
31 printf("Testing find...\n");
32
33 for(ii=0; ii < ss->count; ++ii)
34 if(findInStrArray(ss, STR_N(ssc,ii)) != ii)
35 {
36 printf("ERROR! finding string #%d failed\n", ii);
37 if(ii == 2)
38 printf("(not an error, findInStrArray finds first occurrence of a string)\n");
39 }
40 else
41 {
42 printf("finding string #%d ok\n", ii);
43 if(ii == 2)
44 printf("Not OK at all!!! findInStrArray should find first occurrence of a string.\n");
45 }
46
47 ii = findInStrArray(ss, "t7");
48 if(ii != -1)
49 printf("ERROR! found nonexistent string at #%d\n", ii);
50
51 converted = StrArray2String(ss);
52 if(converted == NULL)
53 printf("ERROR! something unexpected happened in StrArray2String\n");
54 printf("StrArray2String returned this string:\n \"%s\"\n", converted);
55
56 return 0;
57 }
58