mirror of
https://gitee.com/Lamdonn/varch.git
synced 2025-12-06 16:56:42 +08:00
92 lines
1.8 KiB
C
92 lines
1.8 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#if defined(TEST_TARGET_queue)
|
|
#include <varch/command.h>
|
|
#include <varch/queue.h>
|
|
#else
|
|
#include "init.h"
|
|
#include "command.h"
|
|
#include "queue.h"
|
|
#endif
|
|
|
|
static void test_base(void)
|
|
{
|
|
queue_t queue = queue(int, 10);
|
|
int i = 0;
|
|
|
|
for (i = 0; i < queue_capacity(queue); i++)
|
|
{
|
|
queue_push(queue, &i);
|
|
}
|
|
queue_pop(queue, NULL);
|
|
queue_pop(queue, NULL);
|
|
printf("queue capacity=%d, size=%d, dsize=%d\r\n", queue_capacity(queue), queue_size(queue), queue_dsize(queue));
|
|
for (i = 0; i < queue_size(queue); i++)
|
|
{
|
|
printf("queue[%d] = %d\r\n", i, queue_at(queue, int, i));
|
|
}
|
|
|
|
_queue(queue);
|
|
}
|
|
|
|
static void usage(void)
|
|
{
|
|
printf(
|
|
"Usage: queue [opt] [arg]\n"
|
|
"\n"
|
|
"options:\n"
|
|
" -h Print help\n"
|
|
" -v Print version\n"
|
|
"\n"
|
|
"argument:\n"
|
|
" <read> Test default read function\n"
|
|
" <write> 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("queue version %d.%d.%d\r\n", QUEUE_V_MAJOR, QUEUE_V_MINOR, QUEUE_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_queue)
|
|
int main(int argc, char *argv[])
|
|
{
|
|
return test(argc, argv);
|
|
}
|
|
#else
|
|
void test_queue(void)
|
|
{
|
|
command_export("queue", test);
|
|
}
|
|
init_export_app(test_queue);
|
|
#endif
|
|
|
|
|