summaryrefslogtreecommitdiffstats
path: root/lib/tests
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/test_cmd.c14
-rw-r--r--lib/tests/test_ini1.c3
-rw-r--r--lib/tests/test_opts1.c17
-rw-r--r--lib/tests/test_opts2.c17
-rw-r--r--lib/tests/test_tcp.c5
5 files changed, 25 insertions, 31 deletions
diff --git a/lib/tests/test_cmd.c b/lib/tests/test_cmd.c
index ade0da90..d51016cc 100644
--- a/lib/tests/test_cmd.c
+++ b/lib/tests/test_cmd.c
@@ -38,31 +38,29 @@ char *get_command(char *const *line) {
38} 38}
39 39
40int main(int argc, char **argv) { 40int main(int argc, char **argv) {
41 char **command_line = malloc(sizeof(char *) * COMMAND_LINE);
42 char *command = NULL;
43 char *perl;
44 output chld_out, chld_err;
45 int c;
46 int result = UNSET;
47
48 plan_tests(51); 41 plan_tests(51);
49 42
50 diag("Running plain echo command, set one"); 43 diag("Running plain echo command, set one");
51 44
52 /* ensure everything is empty before we begin */ 45 /* ensure everything is empty before we begin */
46
47 output chld_out;
53 memset(&chld_out, 0, sizeof(output)); 48 memset(&chld_out, 0, sizeof(output));
49 output chld_err;
54 memset(&chld_err, 0, sizeof(output)); 50 memset(&chld_err, 0, sizeof(output));
55 ok(chld_out.lines == 0, "(initialised) Checking stdout is reset"); 51 ok(chld_out.lines == 0, "(initialised) Checking stdout is reset");
56 ok(chld_err.lines == 0, "(initialised) Checking stderr is reset"); 52 ok(chld_err.lines == 0, "(initialised) Checking stderr is reset");
53 int result = UNSET;
57 ok(result == UNSET, "(initialised) Checking exit code is reset"); 54 ok(result == UNSET, "(initialised) Checking exit code is reset");
58 55
56 char **command_line = malloc(sizeof(char *) * COMMAND_LINE);
59 command_line[0] = strdup("/bin/echo"); 57 command_line[0] = strdup("/bin/echo");
60 command_line[1] = strdup("this"); 58 command_line[1] = strdup("this");
61 command_line[2] = strdup("is"); 59 command_line[2] = strdup("is");
62 command_line[3] = strdup("test"); 60 command_line[3] = strdup("test");
63 command_line[4] = strdup("one"); 61 command_line[4] = strdup("one");
64 62
65 command = get_command(command_line); 63 char *command = get_command(command_line);
66 64
67 result = cmd_run_array(command_line, &chld_out, &chld_err, 0); 65 result = cmd_run_array(command_line, &chld_out, &chld_err, 0);
68 ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines"); 66 ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines");
diff --git a/lib/tests/test_ini1.c b/lib/tests/test_ini1.c
index 3792d142..de983764 100644
--- a/lib/tests/test_ini1.c
+++ b/lib/tests/test_ini1.c
@@ -50,11 +50,10 @@ char *list2str(np_arg_list *optlst) {
50} 50}
51 51
52int main(int argc, char **argv) { 52int main(int argc, char **argv) {
53 char *optstr = NULL;
54 53
55 plan_tests(12); 54 plan_tests(12);
56 55
57 optstr = list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); 56 char *optstr = list2str(np_get_defaults("section@./config-tiny.ini", "check_disk"));
58 ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), 57 ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"),
59 "config-tiny.ini's section as expected"); 58 "config-tiny.ini's section as expected");
60 my_free(optstr); 59 my_free(optstr);
diff --git a/lib/tests/test_opts1.c b/lib/tests/test_opts1.c
index 99da5596..fa95c4d4 100644
--- a/lib/tests/test_opts1.c
+++ b/lib/tests/test_opts1.c
@@ -40,15 +40,16 @@ 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 bool freeflag = true;
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
47 for (int i = 1; i < *argc; i++) {
47 printf("'%s' ", newargv[i]); 48 printf("'%s' ", newargv[i]);
48 /* Stop freeing when we get to the start of the original array */ 49 /* Stop freeing when we get to the start of the original array */
49 if (freeflag) { 50 if (freeflag) {
50 if (newargv[i] == argv[1]) { 51 if (newargv[i] == argv[1]) {
51 freeflag = 0; 52 freeflag = false;
52 } else { 53 } else {
53 free(newargv[i]); 54 free(newargv[i]);
54 } 55 }
@@ -64,13 +65,12 @@ void my_free(int *argc, char **newargv, char **argv) {
64#endif 65#endif
65 66
66int array_diff(int i1, char **a1, int i2, char **a2) { 67int array_diff(int i1, char **a1, int i2, char **a2) {
67 int i;
68
69 if (i1 != i2) { 68 if (i1 != i2) {
70 printf(" Argument count doesn't match!\n"); 69 printf(" Argument count doesn't match!\n");
71 return 0; 70 return 0;
72 } 71 }
73 for (i = 0; i <= i1; i++) { 72
73 for (int i = 0; i <= i1; i++) {
74 if (a1[i] == NULL && a2[i] == NULL) { 74 if (a1[i] == NULL && a2[i] == NULL) {
75 continue; 75 continue;
76 } 76 }
@@ -87,11 +87,10 @@ int array_diff(int i1, char **a1, int i2, char **a2) {
87} 87}
88 88
89int main(int argc, char **argv) { 89int main(int argc, char **argv) {
90 char **argv_new = NULL;
91 int i, argc_test;
92
93 plan_tests(5); 90 plan_tests(5);
94 91
92 char **argv_new = NULL;
93 int argc_test;
95 { 94 {
96 char *argv_test[] = {"prog_name", (char *)NULL}; 95 char *argv_test[] = {"prog_name", (char *)NULL};
97 argc_test = 1; 96 argc_test = 1;
diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c
index d1b0aca3..3dd1b039 100644
--- a/lib/tests/test_opts2.c
+++ b/lib/tests/test_opts2.c
@@ -23,15 +23,16 @@
23 23
24void my_free(int *argc, char **newargv, char **argv) { 24void my_free(int *argc, char **newargv, char **argv) {
25 /* Free stuff (and print while we're at it) */ 25 /* Free stuff (and print while we're at it) */
26 int i, freeflag = 1; 26 bool freeflag = true;
27
27 printf(" Arg(%i): ", *argc + 1); 28 printf(" Arg(%i): ", *argc + 1);
28 printf("'%s' ", newargv[0]); 29 printf("'%s' ", newargv[0]);
29 for (i = 1; i < *argc; i++) { 30 for (int i = 1; i < *argc; i++) {
30 printf("'%s' ", newargv[i]); 31 printf("'%s' ", newargv[i]);
31 /* Stop freeing when we get to the start of the original array */ 32 /* Stop freeing when we get to the start of the original array */
32 if (freeflag) { 33 if (freeflag) {
33 if (newargv[i] == argv[1]) { 34 if (newargv[i] == argv[1]) {
34 freeflag = 0; 35 freeflag = false;
35 } else { 36 } else {
36 free(newargv[i]); 37 free(newargv[i]);
37 } 38 }
@@ -46,13 +47,12 @@ void my_free(int *argc, char **newargv, char **argv) {
46} 47}
47 48
48int array_diff(int i1, char **a1, int i2, char **a2) { 49int array_diff(int i1, char **a1, int i2, char **a2) {
49 int i;
50
51 if (i1 != i2) { 50 if (i1 != i2) {
52 printf(" Argument count doesn't match!\n"); 51 printf(" Argument count doesn't match!\n");
53 return 0; 52 return 0;
54 } 53 }
55 for (i = 0; i <= i1; i++) { 54
55 for (int i = 0; i <= i1; i++) {
56 if (a1[i] == NULL && a2[i] == NULL) { 56 if (a1[i] == NULL && a2[i] == NULL) {
57 continue; 57 continue;
58 } 58 }
@@ -69,11 +69,10 @@ int array_diff(int i1, char **a1, int i2, char **a2) {
69} 69}
70 70
71int main(int argc, char **argv) { 71int main(int argc, char **argv) {
72 char **argv_new = NULL;
73 int i, argc_test;
74
75 plan_tests(5); 72 plan_tests(5);
76 73
74 char **argv_new = NULL;
75 int argc_test;
77 { 76 {
78 char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *)NULL}; 77 char *argv_test[] = {"prog_name", "arg1", "--extra-opts", "--arg3", "val2", (char *)NULL};
79 argc_test = 5; 78 argc_test = 5;
diff --git a/lib/tests/test_tcp.c b/lib/tests/test_tcp.c
index de3a2102..37c818c9 100644
--- a/lib/tests/test_tcp.c
+++ b/lib/tests/test_tcp.c
@@ -21,11 +21,10 @@
21#include "tap.h" 21#include "tap.h"
22 22
23int main(void) { 23int main(void) {
24 char **server_expect;
25 int server_expect_count = 3;
26
27 plan_tests(9); 24 plan_tests(9);
28 25
26 char **server_expect;
27 const int server_expect_count = 3;
29 server_expect = malloc(sizeof(char *) * server_expect_count); 28 server_expect = malloc(sizeof(char *) * server_expect_count);
30 29
31 server_expect[0] = strdup("AA"); 30 server_expect[0] = strdup("AA");