summaryrefslogtreecommitdiffstats
path: root/lib/tests/test_opts1.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests/test_opts1.c')
-rw-r--r--lib/tests/test_opts1.c103
1 files changed, 51 insertions, 52 deletions
diff --git a/lib/tests/test_opts1.c b/lib/tests/test_opts1.c
index 077c5b6..e32115c 100644
--- a/lib/tests/test_opts1.c
+++ b/lib/tests/test_opts1.c
@@ -1,19 +1,19 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4* it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
5* the Free Software Foundation, either version 3 of the License, or 5 * the Free Software Foundation, either version 3 of the License, or
6* (at your option) any later version. 6 * (at your option) any later version.
7* 7 *
8* This program is distributed in the hope that it will be useful, 8 * This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details. 11 * GNU General Public License for more details.
12* 12 *
13* You should have received a copy of the GNU General Public License 13 * You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15* 15 *
16*****************************************************************************/ 16 *****************************************************************************/
17 17
18#include "common.h" 18#include "common.h"
19#include "utils_base.h" 19#include "utils_base.h"
@@ -40,23 +40,24 @@ void my_free(int *argc, char **newargv, char **argv) {
40#else 40#else
41void my_free(int *argc, char **newargv, char **argv) { 41void my_free(int *argc, char **newargv, char **argv) {
42 /* Free stuff (and print while we're at it) */ 42 /* Free stuff (and print while we're at it) */
43 int i, freeflag=1; 43 int i, freeflag = 1;
44 printf (" Arg(%i): ", *argc+1); 44 printf(" Arg(%i): ", *argc + 1);
45 printf ("'%s' ", newargv[0]); 45 printf("'%s' ", newargv[0]);
46 for (i=1; i<*argc; i++) { 46 for (i = 1; i < *argc; i++) {
47 printf ("'%s' ", newargv[i]); 47 printf("'%s' ", newargv[i]);
48 /* Stop freeing when we get to the start of the original array */ 48 /* Stop freeing when we get to the start of the original array */
49 if (freeflag) { 49 if (freeflag) {
50 if (newargv[i] == argv[1]) 50 if (newargv[i] == argv[1])
51 freeflag=0; 51 freeflag = 0;
52 else 52 else
53 free(newargv[i]); 53 free(newargv[i]);
54 } 54 }
55 } 55 }
56 printf ("\n"); 56 printf("\n");
57 /* Free only if it's a different array */ 57 /* Free only if it's a different array */
58 if (newargv != argv) free(newargv); 58 if (newargv != argv)
59 *argc=0; 59 free(newargv);
60 *argc = 0;
60} 61}
61#endif 62#endif
62 63
@@ -67,9 +68,10 @@ int array_diff(int i1, char **a1, int i2, char **a2) {
67 printf(" Argument count doesn't match!\n"); 68 printf(" Argument count doesn't match!\n");
68 return 0; 69 return 0;
69 } 70 }
70 for (i=0; i<=i1; i++) { 71 for (i = 0; i <= i1; i++) {
71 if (a1[i]==NULL && a2[i]==NULL) continue; 72 if (a1[i] == NULL && a2[i] == NULL)
72 if (a1[i]==NULL || a2[i]==NULL) { 73 continue;
74 if (a1[i] == NULL || a2[i] == NULL) {
73 printf(" Argument # %i null in one array!\n", i); 75 printf(" Argument # %i null in one array!\n", i);
74 return 0; 76 return 0;
75 } 77 }
@@ -81,59 +83,56 @@ int array_diff(int i1, char **a1, int i2, char **a2) {
81 return 1; 83 return 1;
82} 84}
83 85
84int 86int main(int argc, char **argv) {
85main (int argc, char **argv) 87 char **argv_new = NULL;
86{
87 char **argv_new=NULL;
88 int i, argc_test; 88 int i, argc_test;
89 89
90 plan_tests(5); 90 plan_tests(5);
91 91
92 { 92 {
93 char *argv_test[] = {"prog_name", (char *) NULL}; 93 char *argv_test[] = {"prog_name", (char *)NULL};
94 argc_test=1; 94 argc_test = 1;
95 char *argv_known[] = {"prog_name", (char *) NULL}; 95 char *argv_known[] = {"prog_name", (char *)NULL};
96 argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); 96 argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
97 ok(array_diff(argc_test, argv_new, 1, argv_known), "No opts, returns correct argv/argc"); 97 ok(array_diff(argc_test, argv_new, 1, argv_known), "No opts, returns correct argv/argc");
98 my_free(&argc_test, argv_new, argv_test); 98 my_free(&argc_test, argv_new, argv_test);
99 } 99 }
100 100
101 { 101 {
102 char *argv_test[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *) NULL}; 102 char *argv_test[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *)NULL};
103 argc_test=5; 103 argc_test = 5;
104 char *argv_known[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *) NULL}; 104 char *argv_known[] = {"prog_name", "arg1", "--arg2=val1", "--arg3", "val2", (char *)NULL};
105 argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); 105 argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
106 ok(array_diff(argc_test, argv_new, 5, argv_known), "No extra opts, verbatim copy of argv"); 106 ok(array_diff(argc_test, argv_new, 5, argv_known), "No extra opts, verbatim copy of argv");
107 my_free(&argc_test, argv_new, argv_test); 107 my_free(&argc_test, argv_new, argv_test);
108 } 108 }
109 109
110 { 110 {
111 char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *) NULL}; 111 char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *)NULL};
112 argc_test=2; 112 argc_test = 2;
113 char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *) NULL}; 113 char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *)NULL};
114 argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); 114 argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
115 ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts using default section"); 115 ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts using default section");
116 my_free(&argc_test, argv_new, argv_test); 116 my_free(&argc_test, argv_new, argv_test);
117 } 117 }
118 118
119 { 119 {
120 char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts", "sect2@./config-opts.ini", (char *) NULL}; 120 char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts", "sect2@./config-opts.ini", (char *)NULL};
121 argc_test=4; 121 argc_test = 4;
122 char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *) NULL}; 122 char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *)NULL};
123 argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); 123 argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
124 ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts specified twice"); 124 ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts specified twice");
125 my_free(&argc_test, argv_new, argv_test); 125 my_free(&argc_test, argv_new, argv_test);
126 } 126 }
127 127
128 { 128 {
129 char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1@./config-opts.ini", "--arg2", (char *) NULL}; 129 char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1@./config-opts.ini", "--arg2", (char *)NULL};
130 argc_test=6; 130 argc_test = 6;
131 char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two", "--arg1=val1", "--arg2", (char *) NULL}; 131 char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two", "--arg1=val1", "--arg2", (char *)NULL};
132 argv_new=np_extra_opts(&argc_test, argv_test, "check_disk"); 132 argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
133 ok(array_diff(argc_test, argv_new, 7, argv_known), "twice extra opts using two sections"); 133 ok(array_diff(argc_test, argv_new, 7, argv_known), "twice extra opts using two sections");
134 my_free(&argc_test, argv_new, argv_test); 134 my_free(&argc_test, argv_new, argv_test);
135 } 135 }
136 136
137 return exit_status(); 137 return exit_status();
138} 138}
139