This source file includes following definitions.
- main
- test1
- test2
- test3
- test4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include "orte_config.h"
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #ifdef HAVE_SYS_PARAM_H
24 #include <sys/param.h>
25 #endif
26
27 #include "opal/runtime/opal.h"
28 #include "opal/util/os_path.h"
29 #include "support.h"
30
31 #define PATH_SEP "/"
32
33 static const char *path_sep = PATH_SEP;
34
35 static bool test1(void);
36 static bool test2(void);
37 static bool test3(void);
38 static bool test4(void);
39
40
41 int main(int argc, char* argv[])
42 {
43 opal_init(&argc, &argv);
44
45 test_init("opal_os_path_t");
46
47 if (test1()) {
48 test_success();
49 }
50 else {
51 test_failure("opal_os_path_t test1 failed");
52 }
53
54 if (test2()) {
55 test_success();
56 }
57 else {
58 test_failure("opal_os_path_t test2 failed");
59 }
60
61 if (test3()) {
62 test_success();
63 }
64 else {
65 test_failure("opal_os_path_t test3 failed");
66 }
67
68 if (test4()) {
69 test_success();
70 }
71 else {
72 test_failure("opal_os_path_t test4 failed");
73 }
74
75 opal_finalize();
76
77 test_finalize();
78 return 0;
79 }
80
81
82 static bool test1(void)
83 {
84 char *out, answer[100];
85
86
87
88 if (NULL != (out = opal_os_path(true,NULL))) {
89 answer[0] = '\0';
90 strcat(answer, ".");
91 strcat(answer, path_sep);
92 if (0 != strcmp(answer, out))
93 return(false);
94 free(out);
95 }
96 if (NULL != (out = opal_os_path(false,NULL))) {
97 if (0 != strcmp(path_sep, out))
98 return(false);
99 free(out);
100 }
101
102 return true;
103 }
104
105
106 static bool test2(void)
107 {
108 char out[1024];
109 char *tmp;
110 char *a[] = { "aaa", "bbb", "ccc", NULL };
111
112 if (NULL == path_sep) {
113 printf("test2 cannot be run\n");
114 return(false);
115 }
116
117
118 out[0] = '\0';
119 strcat(out, ".");
120 strcat(out, path_sep);
121 strcat(out, a[0]);
122
123 tmp = opal_os_path(true, a[0], NULL);
124 if (0 != strcmp(out, tmp))
125 return(false);
126 free(tmp);
127
128 strcat(out, path_sep);
129 strcat(out, a[1]);
130 tmp = opal_os_path(true, a[0], a[1], NULL);
131 if (0 != strcmp(out, tmp))
132 return(false);
133 free(tmp);
134
135 strcat(out, path_sep);
136 strcat(out, a[2]);
137 tmp = opal_os_path(true, a[0], a[1], a[2], NULL);
138 if (0 != strcmp(out, tmp))
139 return(false);
140 free(tmp);
141
142 return true;
143 }
144
145
146 static bool test3(void)
147 {
148 char out[1024];
149 char *tmp;
150 char *a[] = { "aaa", "bbb", "ccc", NULL };
151
152 if (NULL == path_sep) {
153 printf("test3 cannot be run\n");
154 return(false);
155 }
156
157
158 out[0] = '\0';
159 strcat(out, path_sep);
160 strcat(out, a[0]);
161 tmp = opal_os_path(false, a[0], NULL);
162 if (0 != strcmp(out, tmp))
163 return(false);
164 free(tmp);
165
166 strcat(out, path_sep);
167 strcat(out, a[1]);
168 tmp = opal_os_path(false, a[0], a[1], NULL);
169 if (0 != strcmp(out, tmp))
170 return(false);
171 free(tmp);
172
173 strcat(out, path_sep);
174 strcat(out, a[2]);
175 tmp = opal_os_path(false, a[0], a[1], a[2], NULL);
176 if (0 != strcmp(out, tmp))
177 return(false);
178 free(tmp);
179
180 return true;
181 }
182
183 static bool test4(void)
184 {
185 char a[MAXPATHLEN + 10];
186 int i;
187
188 if (NULL == path_sep) {
189 printf("test4 cannot be run\n");
190 return(false);
191 }
192
193 for (i=0; i< MAXPATHLEN+5; i++) {
194 a[i] = 'a';
195 }
196 a[i] = '\0';
197 if (NULL != opal_os_path(false, a, NULL)) {
198 return(false);
199 }
200 return (true);
201 }