1 #include "../include/optparser.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
9 // c++ -Wall -std=c++0x -g optparser_test.c optparser.c stringptr.c strlib.c -o optparser_test -DMANUAL
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")))
19 char a1
[] = "-cmd=test";
20 char a2
[] = "-cmd2=test2=test2";
28 static char* buf
[] STK
= {
40 opts
* opt
= op_parse(argl
, argv
);
42 opts
* opt
= op_parse(argc
, buf
);
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"));