#include #include #include #if defined(TEST_TARGET_stack) #include #include #else #include "init.h" #include "command.h" #include "stack.h" #endif static void test_base(void) { stack_t stack = stack(int, 10); int i = 0; for (i = 0; i < stack_capacity(stack); i++) { stack_push(stack, &i); } stack_pop(stack, NULL); stack_pop(stack, NULL); for (i = 0; i < stack_size(stack); i++) { printf("stack[%d] = %d\r\n", i, stack_at(stack, int, i)); } _stack(stack); } static void usage(void) { printf( "Usage: stack [opt] [arg]\n" "\n" "options:\n" " -h Print help\n" " -v Print version\n" "\n" "argument:\n" " Test default read function\n" " Test default write function\n" ); } static int test(int argc, char *argv[]) { /* reset getopt */ command_opt_init(); while (1) { int opt = command_getopt(argc, argv, "hv"); if (opt == -1) break; switch (opt) { case 'v' : printf("stack version %d.%d.%d\r\n", STACK_V_MAJOR, STACK_V_MINOR, STACK_V_PATCH); return 0; case '?': printf("Unknown option `%c`\r\n", command_optopt); return -1; case 'h' : default: usage(); return 0; } } test_base(); return 0; } #if defined(TEST_TARGET_stack) int main(int argc, char *argv[]) { return test(argc, argv); } #else void test_stack(void) { command_export("stack", test); } init_export_app(test_stack); #endif