Fix several warnings that appear in gcc 4.3.2.
[wvstreams.git] / utils / tests / tcltest.cc
blob8c76323ee8de7d5128eaf07f18d56bdda1ebe68d
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 */
5 #include "wvtclstring.h"
6 #include "wvstringlist.h"
7 #include "wvstringmask.h"
9 int main(int argc, char **argv)
11 WvStringMask nasties(WVTCL_NASTY_SPACES);
12 WvStringMask splitchars(WVTCL_SPLITCHARS);
14 bool bad = false;
16 // correct output (all on one line):
17 // 'chicken hammer {} {banana split} {shameless{frog}parts}
18 // big\}monkey\ \{potatoes {hammer\}time} {"quotable quote"}'
19 static const char *strarray[] = {
20 "chicken",
21 "hammer",
22 "",
23 "banana split",
24 "split\nends",
25 "shameless{frog}parts",
26 "big}monkey {potatoes",
27 "hammer\\}time",
28 "\"quotable quote\"",
29 NULL
31 WvStringList l;
32 l.fill(strarray);
34 WvString ls(wvtcl_encode(l, nasties, splitchars));
35 printf(" List: '%s'\n", ls.cstr());
36 printf("Unescaped: '%s'\n", wvtcl_unescape(ls).cstr());
38 // wvtcl_encode (like the real tcl list encoder) will never put things
39 // in quotes by itself. However, the list decoder needs to be able to
40 // handle them, in case the user provides them by hand. So we'll just
41 // tack some quoted strings onto the end.
42 //
43 // We also take this opportunity to test handling of whitespace.
44 //
45 ls.append(" \n \t \"unquotable quote\"\r\n");
46 ls.append(" \"{embraced\\nunquotable}\" \"quote\"whacker");
48 // add the expected new strings to the end of the main list, for comparison
49 // purposes below.
50 l.append(new WvString("unquotable quote"), true);
51 l.append(new WvString("{embraced\nunquotable}"), true);
52 l.append(new WvString("quote"), true);
53 l.append(new WvString("whacker"), true);
55 printf("\nList split results:\n");
56 WvStringList l2;
57 wvtcl_decode(l2, ls, splitchars);
59 WvStringList::Iter i(l), i2(l2);
60 for (i.rewind(), i2.rewind(); i.next(), i2.next(), true; )
62 if (!i.cur() && !i2.cur())
63 break;
65 if (!i.cur())
67 printf("Extra element in list 2: '%s'\n", i2->cstr());
68 bad = true;
69 break;
72 if (!i2.cur())
74 printf("Extra element in list 1: '%s'\n", i->cstr());
75 bad = true;
76 break;
79 printf(" '%s'\n", i2->cstr());
81 if (*i != *i2)
83 printf(" --> should be '%s'\n", i->cstr());
84 bad = true;
88 if (bad)
89 printf("Lists don't match!\n");
90 else
91 printf("Lists match.\n");
92 return bad;