/* args_test.c - test program for args.c * PUBLIC DOMAIN - April 1, 2009 - Jon Mayo */ #include #include #include "args.h" #define NR(x) (sizeof(x)/sizeof*(x)) int main(int argc, char **argv) { const char *test1_str=NULL; const char *test2_str=NULL; long test3_long=-1; const struct arginfo sys_ai[] = { {"-test1", 1, args_cbset_charptrptr, &test1_str, "Set the test1 variable."}, {"-test2", 1, args_cbset_charptrptr, &test2_str, "Set the test2 variable."}, {"-test3", 1, args_cbset_longptr, &test3_long, "Set the test3 variable."}, }; /* grab the args */ if(!args_parser(sys_ai, NR(sys_ai), NULL, NULL, argc, argv)) { return EXIT_FAILURE; } printf("test1 : \"%s\"\n", test1_str); printf("test2 : \"%s\"\n", test2_str); printf("test3 : %ld %#lx\n", test3_long, test3_long); return EXIT_SUCCESS; } /* Test Cases * * POSITIVE: * ./args_test -test1 'hello there' -test1 'okay' -test2 'duh' -test3 1235523 * * NEGATIVE: * ./args_test -test3 hello * ./args_test -test1 'hello there' -test1 'okay' -test2 'duh' -test3 1235q23 * ./args_test -test3 1q * */