windows_test.c (2025B)
1 #include <cwalk.h> 2 #include <memory.h> 3 #include <stdlib.h> 4 #include <string.h> 5 6 int windows_root_empty(void) 7 { 8 size_t size; 9 cwk_path_set_style(CWK_STYLE_WINDOWS); 10 11 cwk_path_get_root("", &size); 12 if (size != 0) { 13 return EXIT_FAILURE; 14 } 15 16 return EXIT_SUCCESS; 17 } 18 19 int windows_root_backslash(void) 20 { 21 size_t size; 22 cwk_path_set_style(CWK_STYLE_WINDOWS); 23 24 cwk_path_get_root("\\no_network_path\\hello", &size); 25 if (size != 1) { 26 return EXIT_FAILURE; 27 } 28 29 return EXIT_SUCCESS; 30 } 31 32 int windows_intersection_case(void) 33 { 34 cwk_path_set_style(CWK_STYLE_WINDOWS); 35 36 if (cwk_path_get_intersection("C:\\MYFOLDER\\MYILE.TXT", 37 "c:\\myfolder\\myile.txt") != 21) { 38 return EXIT_FAILURE; 39 } 40 41 return EXIT_SUCCESS; 42 } 43 44 int windows_get_root_relative(void) 45 { 46 size_t size; 47 cwk_path_set_style(CWK_STYLE_WINDOWS); 48 cwk_path_get_root("C:file.txt", &size); 49 50 if (size != 2) { 51 return EXIT_FAILURE; 52 } 53 54 return EXIT_SUCCESS; 55 } 56 57 int windows_get_root_separator(void) 58 { 59 size_t size; 60 cwk_path_set_style(CWK_STYLE_WINDOWS); 61 cwk_path_get_root("C:/this/is/a/test", &size); 62 63 if (size != 3) { 64 return EXIT_FAILURE; 65 } 66 67 return EXIT_SUCCESS; 68 } 69 70 int windows_get_unc_root(void) 71 { 72 size_t size; 73 74 cwk_path_set_style(CWK_STYLE_WINDOWS); 75 cwk_path_get_root("\\\\server\\share\\test.txt", &size); 76 77 if (size != 15) { 78 return EXIT_FAILURE; 79 } 80 81 return EXIT_SUCCESS; 82 } 83 84 int windows_get_root(void) 85 { 86 size_t size; 87 88 cwk_path_set_style(CWK_STYLE_WINDOWS); 89 cwk_path_get_root("C:\\test.txt", &size); 90 91 if (size != 3) { 92 return EXIT_FAILURE; 93 } 94 95 return EXIT_SUCCESS; 96 } 97 98 int windows_change_style(void) 99 { 100 enum cwk_path_style style; 101 102 style = cwk_path_get_style(); 103 if (style == CWK_STYLE_WINDOWS) { 104 cwk_path_set_style(CWK_STYLE_UNIX); 105 if (cwk_path_get_style() != CWK_STYLE_UNIX) { 106 return EXIT_FAILURE; 107 } 108 } else { 109 cwk_path_set_style(CWK_STYLE_WINDOWS); 110 if (cwk_path_get_style() != CWK_STYLE_WINDOWS) { 111 return EXIT_FAILURE; 112 } 113 } 114 115 return EXIT_SUCCESS; 116 }