mirror of
https://gitee.com/Lamdonn/varch.git
synced 2025-12-07 17:26:43 +08:00
128 lines
2.3 KiB
C
128 lines
2.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#if defined(TEST_TARGET_cQueue)
|
|
#include <varch/command.h>
|
|
#include <varch/cQueue.h>
|
|
#else
|
|
#include "init.h"
|
|
#include "command.h"
|
|
#include "cQueue.h"
|
|
#endif
|
|
|
|
void test_int(void)
|
|
{
|
|
typedef struct
|
|
{
|
|
cQueue queue;
|
|
int data[10];
|
|
} intQueueType;
|
|
intQueueType intQueue;
|
|
|
|
cQueue_init(intQueue);
|
|
|
|
for (int i = 0; i < intQueue.queue.cap; i++)
|
|
{
|
|
cQueue_push(intQueue, i);
|
|
}
|
|
|
|
printf("cQueue[5] = %d\r\n", cQueue_at(intQueue, 5));
|
|
|
|
while (intQueue.queue.size > 0)
|
|
{
|
|
int data;
|
|
cQueue_pop(intQueue, data);
|
|
printf("cQueue_pop %d\r\n", data);
|
|
}
|
|
}
|
|
|
|
void test_struct(void)
|
|
{
|
|
typedef struct
|
|
{
|
|
char *name;
|
|
int age;
|
|
} Stu;
|
|
typedef struct
|
|
{
|
|
cQueue queue;
|
|
Stu data[10];
|
|
} StuQueueType;
|
|
StuQueueType StuQueue;
|
|
|
|
Stu s = {"Zhang", 18};
|
|
|
|
cQueue_init(StuQueue);
|
|
|
|
for (int i = 0; i < StuQueue.queue.cap; i++)
|
|
{
|
|
s.age = 18 + i;
|
|
cQueue_push(StuQueue, s);
|
|
}
|
|
|
|
while (StuQueue.queue.size > 0)
|
|
{
|
|
cQueue_pop(StuQueue, s);
|
|
printf("cQueue_pop name: %s age %d\r\n", s.name, s.age);
|
|
}
|
|
}
|
|
|
|
static void usage(void)
|
|
{
|
|
printf(
|
|
"Usage: cQueue [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("cQueue version %d.%d.%d\r\n", CQUEUE_V_MAJOR, CQUEUE_V_MINOR, CQUEUE_V_PATCH);
|
|
return 0;
|
|
case '?':
|
|
printf("Unknown option `%c`\r\n", command_optopt);
|
|
return -1;
|
|
case 'h' :
|
|
default:
|
|
usage();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
// test_int();
|
|
test_struct();
|
|
|
|
return 0;
|
|
}
|
|
|
|
#if defined(TEST_TARGET_cQueue)
|
|
int main(int argc, char *argv[])
|
|
{
|
|
return test(argc, argv);
|
|
}
|
|
#else
|
|
void test_cQueue(void)
|
|
{
|
|
command_export("cQueue", test);
|
|
}
|
|
init_export_app(test_cQueue);
|
|
#endif
|