root_test.c (4827B)
1 #include <cwalk.h> 2 #include <memory.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 7 int root_change_without_root(void) 8 { 9 size_t length; 10 char buffer[FILENAME_MAX] = "hello\\world.txt"; 11 12 cwk_path_set_style(CWK_STYLE_WINDOWS); 13 length = cwk_path_change_root(buffer, "D:\\", buffer, 14 sizeof(buffer)); 15 16 if (length != 18) { 17 return EXIT_FAILURE; 18 } 19 20 if (strcmp(buffer, "D:\\hello\\world.txt") != 0) { 21 return EXIT_FAILURE; 22 } 23 24 return EXIT_SUCCESS; 25 } 26 27 int root_change_overlapping(void) 28 { 29 size_t length; 30 char buffer[FILENAME_MAX] = "C:\\hello\\world.txt"; 31 32 cwk_path_set_style(CWK_STYLE_WINDOWS); 33 length = cwk_path_change_root(buffer, "D:\\path\\", buffer, 34 sizeof(buffer)); 35 36 if (length != 23) { 37 return EXIT_FAILURE; 38 } 39 40 if (strcmp(buffer, "D:\\path\\hello\\world.txt") != 0) { 41 return EXIT_FAILURE; 42 } 43 44 return EXIT_SUCCESS; 45 } 46 47 int root_change_separators(void) 48 { 49 size_t length; 50 char buffer[FILENAME_MAX]; 51 52 cwk_path_set_style(CWK_STYLE_WINDOWS); 53 length = cwk_path_change_root("C:\\hello\\world.txt", "D:\\path\\", buffer, 54 sizeof(buffer)); 55 56 if (length != 23) { 57 return EXIT_FAILURE; 58 } 59 60 if (strcmp(buffer, "D:\\path\\hello\\world.txt") != 0) { 61 return EXIT_FAILURE; 62 } 63 64 return EXIT_SUCCESS; 65 } 66 67 int root_change_empty(void) 68 { 69 size_t length; 70 char buffer[FILENAME_MAX]; 71 72 cwk_path_set_style(CWK_STYLE_WINDOWS); 73 length = cwk_path_change_root("C:\\hello\\world.txt", "", buffer, 74 sizeof(buffer)); 75 76 if (length != 15) { 77 return EXIT_FAILURE; 78 } 79 80 if (strcmp(buffer, "hello\\world.txt") != 0) { 81 return EXIT_FAILURE; 82 } 83 84 return EXIT_SUCCESS; 85 } 86 87 int root_change_simple(void) 88 { 89 size_t length; 90 char buffer[FILENAME_MAX]; 91 92 cwk_path_set_style(CWK_STYLE_WINDOWS); 93 length = cwk_path_change_root("C:\\hello\\world.txt", "D:\\", buffer, 94 sizeof(buffer)); 95 96 if (length != 18) { 97 return EXIT_FAILURE; 98 } 99 100 if (strcmp(buffer, "D:\\hello\\world.txt") != 0) { 101 return EXIT_FAILURE; 102 } 103 104 return EXIT_SUCCESS; 105 } 106 107 int root_relative_windows(void) 108 { 109 size_t length; 110 111 cwk_path_set_style(CWK_STYLE_WINDOWS); 112 cwk_path_get_root("..\\hello\\world.txt", &length); 113 114 if (length != 0) { 115 return EXIT_FAILURE; 116 } 117 118 return EXIT_SUCCESS; 119 } 120 121 int root_relative_drive(void) 122 { 123 size_t length; 124 125 cwk_path_set_style(CWK_STYLE_WINDOWS); 126 cwk_path_get_root("C:test.txt", &length); 127 128 if (length != 2) { 129 return EXIT_FAILURE; 130 } 131 132 return EXIT_SUCCESS; 133 } 134 135 int root_device_question_mark(void) 136 { 137 size_t length; 138 139 cwk_path_set_style(CWK_STYLE_WINDOWS); 140 cwk_path_get_root("\\\\?\\mydevice\\test", &length); 141 142 if (length != 4) { 143 return EXIT_FAILURE; 144 } 145 146 return EXIT_SUCCESS; 147 } 148 149 int root_device_dot(void) 150 { 151 size_t length; 152 153 cwk_path_set_style(CWK_STYLE_WINDOWS); 154 cwk_path_get_root("\\\\.\\mydevice\\test", &length); 155 156 if (length != 4) { 157 return EXIT_FAILURE; 158 } 159 160 return EXIT_SUCCESS; 161 } 162 163 int root_device_unc(void) 164 { 165 size_t length; 166 167 cwk_path_set_style(CWK_STYLE_WINDOWS); 168 cwk_path_get_root("\\\\.\\UNC\\LOCALHOST\\c$\\temp\\test-file.txt", &length); 169 170 if (length != 4) { 171 return EXIT_FAILURE; 172 } 173 174 return EXIT_SUCCESS; 175 } 176 177 int root_unc(void) 178 { 179 size_t length; 180 181 cwk_path_set_style(CWK_STYLE_WINDOWS); 182 cwk_path_get_root("\\\\server\\folder\\data", &length); 183 184 if (length != 16) { 185 return EXIT_FAILURE; 186 } 187 188 return EXIT_SUCCESS; 189 } 190 191 int root_absolute_drive(void) 192 { 193 size_t length; 194 195 cwk_path_set_style(CWK_STYLE_WINDOWS); 196 cwk_path_get_root("C:\\test.txt", &length); 197 198 if (length != 3) { 199 return EXIT_FAILURE; 200 } 201 202 return EXIT_SUCCESS; 203 } 204 205 int root_unix_drive(void) 206 { 207 size_t length; 208 209 cwk_path_set_style(CWK_STYLE_UNIX); 210 cwk_path_get_root("C:\\test.txt", &length); 211 212 if (length != 0) { 213 return EXIT_FAILURE; 214 } 215 216 return EXIT_SUCCESS; 217 } 218 219 int root_unix_backslash(void) 220 { 221 size_t length; 222 223 cwk_path_set_style(CWK_STYLE_UNIX); 224 cwk_path_get_root("\\folder\\", &length); 225 226 if (length != 0) { 227 return EXIT_FAILURE; 228 } 229 230 return EXIT_SUCCESS; 231 } 232 233 int root_windows_slash(void) 234 { 235 size_t length; 236 237 cwk_path_set_style(CWK_STYLE_WINDOWS); 238 cwk_path_get_root("/test.txt", &length); 239 240 if (length != 1) { 241 return EXIT_FAILURE; 242 } 243 244 return EXIT_SUCCESS; 245 } 246 247 int root_windows_backslash(void) 248 { 249 size_t length; 250 251 cwk_path_set_style(CWK_STYLE_WINDOWS); 252 cwk_path_get_root("\\test.txt", &length); 253 254 if (length != 1) { 255 return EXIT_FAILURE; 256 } 257 258 return EXIT_SUCCESS; 259 } 260 261 int root_relative(void) 262 { 263 size_t length; 264 265 cwk_path_set_style(CWK_STYLE_UNIX); 266 cwk_path_get_root("test.txt", &length); 267 268 if (length != 0) { 269 return EXIT_FAILURE; 270 } 271 272 return EXIT_SUCCESS; 273 } 274 275 int root_absolute(void) 276 { 277 size_t length; 278 279 cwk_path_set_style(CWK_STYLE_UNIX); 280 cwk_path_get_root("/test.txt", &length); 281 282 if (length != 1) { 283 return EXIT_FAILURE; 284 } 285 286 return EXIT_SUCCESS; 287 }