FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
TestFilePatternMatch.c
1
2#include <stdio.h>
3#include <winpr/crt.h>
4#include <winpr/file.h>
5#include <winpr/windows.h>
6
7int TestFilePatternMatch(int argc, char* argv[])
8{
9 /* '*' expression */
10 WINPR_UNUSED(argc);
11 WINPR_UNUSED(argv);
12 if (!FilePatternMatchA("document.txt", "*"))
13 {
14 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "document.txt", "*");
15 return -1;
16 }
17
18 /* '*X' expression */
19
20 if (!FilePatternMatchA("document.txt", "*.txt"))
21 {
22 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "document.txt", "*.txt");
23 return -1;
24 }
25
26 if (FilePatternMatchA("document.docx", "*.txt"))
27 {
28 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "document.docx", "*.txt");
29 return -1;
30 }
31
32 if (FilePatternMatchA("document.txt.bak", "*.txt"))
33 {
34 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "document.txt.bak", "*.txt");
35 return -1;
36 }
37
38 if (FilePatternMatchA("bak", "*.txt"))
39 {
40 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "bak", "*.txt");
41 return -1;
42 }
43
44 /* 'X*' expression */
45
46 if (!FilePatternMatchA("document.txt", "document.*"))
47 {
48 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "document.txt", "document.*");
49 return -1;
50 }
51
52 /* 'X?' expression */
53
54 if (!FilePatternMatchA("document.docx", "document.doc?"))
55 {
56 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "document.docx",
57 "document.doc?");
58 return -1;
59 }
60
61 if (FilePatternMatchA("document.doc", "document.doc?"))
62 {
63 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "document.doc",
64 "document.doc?");
65 return -1;
66 }
67
68 /* no wildcards expression */
69
70 if (!FilePatternMatchA("document.txt", "document.txt"))
71 {
72 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "document.txt",
73 "document.txt");
74 return -1;
75 }
76
77 /* 'X * Y' expression */
78
79 if (!FilePatternMatchA("X123Y.txt", "X*Y.txt"))
80 {
81 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "X123Y.txt", "X*Y.txt");
82 return -1;
83 }
84
85 if (!FilePatternMatchA("XY.txt", "X*Y.txt"))
86 {
87 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "XY.txt", "X*Y.txt");
88 return -1;
89 }
90
91 if (FilePatternMatchA("XZ.txt", "X*Y.txt"))
92 {
93 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "XZ.txt", "X*Y.txt");
94 return -1;
95 }
96
97 if (FilePatternMatchA("X123Z.txt", "X*Y.txt"))
98 {
99 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "X123Z.txt", "X*Y.txt");
100 return -1;
101 }
102
103 /* 'X * Y * Z' expression */
104
105 if (!FilePatternMatchA("X123Y456Z.txt", "X*Y*Z.txt"))
106 {
107 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "X123Y456Z.txt", "X*Y*Z.txt");
108 return -1;
109 }
110
111 if (!FilePatternMatchA("XYZ.txt", "X*Y*Z.txt"))
112 {
113 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "XYZ.txt", "X*Y*Z.txt");
114 return -1;
115 }
116
117 if (!FilePatternMatchA("X123Y456W.txt", "X*Y*Z.txt"))
118 {
119 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "X123Y456W.txt", "X*Y*Z.txt");
120 return -1;
121 }
122
123 if (!FilePatternMatchA("XYW.txt", "X*Y*Z.txt"))
124 {
125 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "XYW.txt", "X*Y*Z.txt");
126 return -1;
127 }
128
129 /* 'X ? Y' expression */
130
131 if (!FilePatternMatchA("X1Y.txt", "X?Y.txt"))
132 {
133 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "X1Y.txt", "X?Y.txt");
134 return -1;
135 }
136
137 if (FilePatternMatchA("XY.txt", "X?Y.txt"))
138 {
139 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "XY.txt", "X?Y.txt");
140 return -1;
141 }
142
143 if (FilePatternMatchA("XZ.txt", "X?Y.txt"))
144 {
145 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "XZ.txt", "X?Y.txt");
146 return -1;
147 }
148
149 if (FilePatternMatchA("X123Z.txt", "X?Y.txt"))
150 {
151 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "X123Z.txt", "X?Y.txt");
152 return -1;
153 }
154
155 /* 'X ? Y ? Z' expression */
156
157 if (!FilePatternMatchA("X123Y456Z.txt", "X?Y?Z.txt"))
158 {
159 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "X123Y456Z.txt", "X?Y?Z.txt");
160 return -1;
161 }
162
163 if (FilePatternMatchA("XYZ.txt", "X?Y?Z.txt"))
164 {
165 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "XYZ.txt", "X?Y?Z.txt");
166 return -1;
167 }
168
169 if (!FilePatternMatchA("X123Y456W.txt", "X?Y?Z.txt"))
170 {
171 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "X123Y456W.txt", "X?Y?Z.txt");
172 return -1;
173 }
174
175 if (FilePatternMatchA("XYW.txt", "X?Y?Z.txt"))
176 {
177 printf("FilePatternMatchA error: FileName: %s Pattern: %s\n", "XYW.txt", "X?Y?Z.txt");
178 return -1;
179 }
180
181 return 0;
182}