This source file includes following definitions.
- main
- test1
- test2
- test3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include "orte_config.h"
20
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #ifdef HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27 #ifdef HAVE_SYS_PARAM_H
28 #include <sys/param.h>
29 #endif
30 #include <sys/stat.h>
31
32 #include "support.h"
33 #include "opal/runtime/opal.h"
34 #include "opal/constants.h"
35 #include "opal/util/os_path.h"
36 #include "opal/util/os_dirpath.h"
37
38 #define PATH_SEP "/"
39
40 static const char *path_sep = PATH_SEP;
41
42 static bool test1(void);
43 static bool test2(void);
44 static bool test3(void);
45
46
47 int main(int argc, char* argv[])
48 {
49 opal_init(&argc, &argv);
50
51 test_init("opal_os_create_dirpath_t");
52
53
54
55 if (test1()) {
56 test_success();
57 }
58 else {
59 test_failure("opal_os_create_dirpath test1 failed");
60 }
61
62 if (test2()) {
63 test_success();
64 }
65 else {
66 test_failure("opal_os_create_dirpath test2 failed");
67 }
68
69 if (test3()) {
70 test_success();
71 }
72 else {
73 test_failure("opal_os_create_dirpath test3 failed");
74 }
75
76 test_finalize();
77 opal_finalize();
78
79 return 0;
80 }
81
82
83 static bool test1(void)
84 {
85
86
87
88 if (OPAL_SUCCESS == opal_os_dirpath_create(NULL, S_IRWXU))
89 return(false);
90
91 return true;
92 }
93
94
95 static bool test2(void)
96 {
97 char *tmp;
98 struct stat buf;
99
100 if (NULL == path_sep) {
101 printf("test2 cannot be run\n");
102 return(false);
103 }
104 tmp = opal_os_path(true, "tmp", NULL);
105 if (0 != mkdir(tmp, S_IRWXU)) {
106 printf("test2 could not be run - directory could not be made\n");
107 return(false);
108 }
109
110 if (OPAL_SUCCESS != opal_os_dirpath_create(tmp, S_IRWXU)) {
111 rmdir(tmp);
112 return(false);
113 }
114
115 chmod(tmp, S_IRUSR);
116
117 if (OPAL_SUCCESS != opal_os_dirpath_create(tmp, S_IRWXU)) {
118 rmdir(tmp);
119 return(false);
120 }
121
122 stat(tmp, &buf);
123 if (S_IRWXU != (S_IRWXU & buf.st_mode)) {
124 rmdir(tmp);
125 return(false);
126 }
127
128 rmdir(tmp);
129
130 free(tmp);
131 return true;
132 }
133
134
135 static bool test3(void)
136 {
137 char *out;
138 struct stat buf;
139 char *a[] = { "aaa", "bbb", "ccc", NULL };
140
141 if (NULL == path_sep) {
142 printf("test3 cannot be run\n");
143 return(false);
144 }
145
146 out = opal_os_path(true, a[0], a[1], a[2], NULL);
147 if (OPAL_SUCCESS != opal_os_dirpath_create(out, S_IRWXU)) {
148 out = opal_os_path(true, a[0], a[1], a[2], NULL);
149 if (0 == stat(out, &buf))
150 rmdir(out);
151 out = opal_os_path(true, a[0], a[1], NULL);
152 if (0 == stat(out, &buf))
153 rmdir(out);
154 out = opal_os_path(true, a[0], NULL);
155 if (0 == stat(out, &buf))
156 rmdir(out);
157 return(false);
158 }
159
160 free(out);
161
162 return(true);
163 }