summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFreeArtMan <=>2016-01-24 13:13:09 +0000
committerFreeArtMan <=>2016-01-24 13:13:09 +0000
commit14ff7106da7e79432a85805e8ce49296f1cf9216 (patch)
tree02c100de21977c7222535e528c5348d988bd6dd1 /test
downloadlibarg-14ff7106da7e79432a85805e8ce49296f1cf9216.tar.gz
libarg-14ff7106da7e79432a85805e8ce49296f1cf9216.zip
Initial
Diffstat (limited to 'test')
-rw-r--r--test/.gitignore2
-rw-r--r--test/Makefile7
-rw-r--r--test/test1.c86
3 files changed, 95 insertions, 0 deletions
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..92746d2
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1,2 @@
+log.txt
+test1
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..7297e92
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,7 @@
+CC=gcc
+CLFAGS=
+make:
+ $(CC) $(CFLAGS) test1.c ../arg.o -o test1
+
+leak:
+ valgrind --leak-check=full --track-origins=yes --log-file=log.txt ./test1 -f -g -e ads \ No newline at end of file
diff --git a/test/test1.c b/test/test1.c
new file mode 100644
index 0000000..dacae2e
--- /dev/null
+++ b/test/test1.c
@@ -0,0 +1,86 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "../arg.h"
+
+s_arg_ip src_ip =
+{
+ .port = 8080,
+ .ip = 0x7f000001
+};
+
+s_arg_range freq_range =
+{
+ .start = 88,
+ .end = 108,
+ .step = 100e3
+};
+
+s_arg_float ratio_float =
+{
+ .val = 0.8
+};
+
+s_arg_list color_name_list =
+{
+ .num = 3,
+ .default_val = "RED",
+ .vals = {"RED","GREEN","BLUE"}
+};
+
+s_arg_val number_val =
+{
+ .ptr = NULL
+};
+
+def_arg cmd_arg[] =
+{
+ ARG_ENTRY("-a",IP,&src_ip),
+ ARG_ENTRY("-b",RANGE,&freq_range),
+ ARG_ENTRY("-c",FLOAT,&ratio_float),
+ ARG_ENTRY("-d",LIST,&color_name_list),
+ ARG_ENTRY("-e",VAL,&number_val),
+ ARG_ENTRY("-f",FLAG,NULL),
+ ARG_ENTRY("-g",FLAG,NULL),
+ {NULL,0,NULL}
+};
+
+
+int main( int argc, char **argv )
+{
+
+ int i=0;
+ arg_t *cfg = NULL;
+
+ i = 0;
+ while ( cmd_arg[i].param != NULL )
+ {
+ printf("%s\n",cmd_arg[i].param);
+ i++;
+ }
+
+ cfg = arg_load( argc, argv, cmd_arg );
+
+ if (cfg->size == 0)
+ {
+ printf("No arguments found\n");
+ goto exit_error;
+ }
+
+ for (i=0;i<cfg->size;i++)
+ {
+ printf("TYPE:%d\n", cfg->arg[i]->type);
+ }
+
+ arg_print( cfg );
+
+ arg_free( cfg );
+
+ return 0;
+
+exit_error:
+ arg_free( cfg );
+
+ return -1;
+
+}