add normalizepath_cstr()
[rofl0r-libulz.git] / examples / optparser_test.c
blob394f309a608ce2ba53a78ae795c57fb3e76044d5
1 #include "../include/optparser.h"
2 #include <assert.h>
4 // laughably the test needs c++0x so the strings can be passed on the stack without too much hardcoding.
6 // c++ -Wall -std=c++0x -g optparser_test.c optparser.c stringptr.c strlib.c -o optparser_test
7 // or
9 // c++ -Wall -std=c++0x -g optparser_test.c optparser.c stringptr.c strlib.c -o optparser_test -DMANUAL
10 //and
11 //gdb --args ./optparser_test -cmd=test -cmd2=test2=test2 -cmd -o -p -q -rst
14 int main(int argl, char** argv) {
16 #define STK __attribute__ ((section ("STACK")))
18 char a0[] = "a.out";
19 char a1[] = "-cmd=test";
20 char a2[] = "-cmd2=test2=test2";
21 char a3[] = "-cmd";
22 char a4[] = "-o";
23 char a5[] = "-p";
24 char a6[] = "-q";
25 char a7[] = "-rst";
28 static char* buf[] STK = {
29 a0,
30 a1,
31 a2,
32 a3,
33 a4,
34 a5,
35 a6,
36 a7};
37 #undef STK
38 int argc = 8;
39 #ifdef MANUAL
40 opts* opt = op_parse(argl, argv);
41 #else
42 opts* opt = op_parse(argc, buf);
43 #endif
44 stringptr* temp;
46 assert(!op_hasflag(opt, 'a'));
47 assert(!op_hasflag(opt, 'b'));
48 assert(!op_hasflag(opt, 'z'));
50 assert(op_hasflag(opt, 'o'));
51 assert(op_hasflag(opt, 'p'));
52 assert(op_hasflag(opt, 'q'));
54 assert(op_hasflag(opt, 'r'));
55 assert(op_hasflag(opt, 's'));
56 assert(op_hasflag(opt, 't'));
58 assert(op_hasflag(opt, 'c'));
59 assert(op_hasflag(opt, 'm'));
60 assert(op_hasflag(opt, 'd'));
62 temp = op_get(opt, "cmd");
63 assert(temp && !strcmp(temp->ptr, "test"));
64 temp = op_get(opt, "cmd2");
65 assert(temp && !strcmp(temp->ptr, "test2=test2"));
66 assert(!op_get(opt, "cmd3"));
67 assert(!op_get(opt, "cmd4"));
68 assert(!op_get(opt, "foo"));
70 op_free(opt);
72 return 0;