summaryrefslogtreecommitdiffstats
path: root/lib/tests/test_opts2.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests/test_opts2.c')
-rw-r--r--lib/tests/test_opts2.c146
1 files changed, 58 insertions, 88 deletions
diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c
index e50f23e..c3d2067 100644
--- a/lib/tests/test_opts2.c
+++ b/lib/tests/test_opts2.c
@@ -21,12 +21,24 @@
21 21
22#include "tap.h" 22#include "tap.h"
23 23
24void my_free(int *argc, char **argv) { 24void my_free(int *argc, char **newargv, char **argv) {
25 int i; 25 /* Free stuff (and print while we're at it) */
26 printf (" Arg(%i): ", *argc); 26 int i, freeflag=1;
27 for (i=1; i<*argc; i++) printf ("'%s' ", argv[i]); 27 printf (" Arg(%i): ", *argc+1);
28 printf ("'%s' ", newargv[0]);
29 for (i=1; i<*argc; i++) {
30 printf ("'%s' ", newargv[i]);
31 /* Stop freeing when we get to the start of the original array */
32 if (freeflag) {
33 if (newargv[i] == argv[1])
34 freeflag=0;
35 else
36 free(newargv[i]);
37 }
38 }
28 printf ("\n"); 39 printf ("\n");
29 free(argv); 40 /* Free only if it's a different array */
41 if (newargv != argv) free(newargv);
30 *argc=0; 42 *argc=0;
31} 43}
32 44
@@ -54,97 +66,55 @@ int array_diff(int i1, char **a1, int i2, char **a2) {
54int 66int
55main (int argc, char **argv) 67main (int argc, char **argv)
56{ 68{
57 char **argv_test=NULL, **argv_known=NULL; 69 char **argv_new=NULL;
58 int i, argc_test; 70 int i, argc_test;
59 71
60 plan_tests(5); 72 plan_tests(5);
61 73
62 argv_test=(char **)malloc(6*sizeof(char **)); 74 {
63 argv_test[0] = "prog_name"; 75 char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *) NULL};
64 argv_test[1] = "arg1"; 76 argc_test=5;
65 argv_test[2] = "--extra-opts"; 77 char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "--arg3", "val2", (char *) NULL};
66 argv_test[3] = "--arg3"; 78 argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
67 argv_test[4] = "val2"; 79 ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 1");
68 argv_test[5] = NULL; 80 my_free(&argc_test, argv_new, argv_test);
69 argc_test=5; 81 }
70 argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
71 argv_known[0] = "prog_name";
72 argv_known[1] = "--foo=bar";
73 argv_known[2] = "arg1";
74 argv_known[3] = "--arg3";
75 argv_known[4] = "val2";
76 argv_known[5] = NULL;
77 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
78 ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 1");
79 82
80 argv_test=(char **)malloc(3*sizeof(char **)); 83 {
81 argv_test[0] = "prog_name"; 84 char *argv_test[] = {"prog_name", "--extra-opts", (char *) NULL};
82 argv_test[1] = "--extra-opts"; 85 argc_test=2;
83 argv_test[2] = NULL; 86 char *argv_known[] = {"prog_name", "--foo=bar", (char *) NULL};
84 argc_test=2; 87 argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
85 argv_known=(char **)realloc(argv_known, 3*sizeof(char **)); 88 ok(array_diff(argc_test, argv_new, 2, argv_known), "Default section 2");
86 argv_known[0] = "prog_name"; 89 my_free(&argc_test, argv_new, argv_test);
87 argv_known[1] = "--foo=bar"; 90 }
88 argv_known[2] = NULL;
89 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
90 ok(array_diff(argc_test, argv_test, 2, argv_known), "Default section 2");
91 my_free(&argc_test,argv_test);
92 91
93 argv_test=(char **)malloc(6*sizeof(char **)); 92 {
94 argv_test[0] = "prog_name"; 93 char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1", "--arg3", "val2", (char *) NULL};
95 argv_test[1] = "arg1"; 94 argc_test=5;
96 argv_test[2] = "--extra-opts=section1"; 95 char *argv_known[] = {"prog_name", "--foobar=baz", "arg1", "--arg3", "val2", (char *) NULL};
97 argv_test[3] = "--arg3"; 96 argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
98 argv_test[4] = "val2"; 97 ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 3");
99 argv_test[5] = NULL; 98 my_free(&argc_test, argv_new, argv_test);
100 argc_test=5; 99 }
101 argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
102 argv_known[0] = "prog_name";
103 argv_known[1] = "--foobar=baz";
104 argv_known[2] = "arg1";
105 argv_known[3] = "--arg3";
106 argv_known[4] = "val2";
107 argv_known[5] = NULL;
108 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
109 ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 3");
110 my_free(&argc_test,argv_test);
111 100
112 argv_test=(char **)malloc(6*sizeof(char **)); 101 {
113 argv_test[0] = "prog_name"; 102 char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "-arg3", "val2", (char *) NULL};
114 argv_test[1] = "arg1"; 103 argc_test=5;
115 argv_test[2] = "--extra-opts"; 104 char *argv_known[] = {"prog_name", "--foo=bar", "arg1", "-arg3", "val2", (char *) NULL};
116 argv_test[3] = "-arg3"; 105 argv_new=np_extra_opts(&argc_test, argv_test, "check_disk");
117 argv_test[4] = "val2"; 106 ok(array_diff(argc_test, argv_new, 5, argv_known), "Default section 4");
118 argv_test[5] = NULL; 107 my_free(&argc_test, argv_new, argv_test);
119 argc_test=5; 108 }
120 argv_known=(char **)realloc(argv_known, 6*sizeof(char **));
121 argv_known[0] = "prog_name";
122 argv_known[1] = "--foo=bar";
123 argv_known[2] = "arg1";
124 argv_known[3] = "-arg3";
125 argv_known[4] = "val2";
126 argv_known[5] = NULL;
127 argv_test=np_extra_opts(&argc_test, argv_test, "check_disk");
128 ok(array_diff(argc_test, argv_test, 5, argv_known), "Default section 4");
129 my_free(&argc_test,argv_test);
130 109
131 argv_test=(char **)malloc(4*sizeof(char **)); 110 {
132 argv_test[0] = "check_tcp"; 111 char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines", (char *) NULL};
133 argv_test[1] = "--extra-opts"; 112 argc_test=3;
134 argv_test[2] = "--extra-opts=tcp_long_lines"; 113 char *argv_known[] = {"check_tcp", "--timeout=10", "--escape", "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda", "--jail", (char *) NULL};
135 argv_test[3] = NULL; 114 argv_new=np_extra_opts(&argc_test, argv_test, "check_tcp");
136 argc_test=3; 115 ok(array_diff(argc_test, argv_new, 6, argv_known), "Long lines test");
137 argv_known=(char **)realloc(argv_known, 7*sizeof(char **)); 116 my_free(&argc_test, argv_new, argv_test);
138 argv_known[0] = "check_tcp"; 117 }
139 argv_known[1] = "--timeout=10";
140 argv_known[2] = "--escape";
141 argv_known[3] = "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda";
142 argv_known[4] = "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda";
143 argv_known[5] = "--jail";
144 argv_known[6] = NULL;
145 argv_test=np_extra_opts(&argc_test, argv_test, "check_tcp");
146 ok(array_diff(argc_test, argv_test, 6, argv_known), "Long lines test");
147 my_free(&argc_test,argv_test);
148 118
149 return exit_status(); 119 return exit_status();
150} 120}