FreeRDP
Loading...
Searching...
No Matches
TestFilePatternMatch.c
1
2
#include <stdio.h>
3
#include <winpr/crt.h>
4
#include <winpr/file.h>
5
#include <winpr/windows.h>
6
7
int
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
/* '*.*' expression: every name, as on Windows */
19
20
if
(!FilePatternMatchA(
"document.txt"
,
"*.*"
))
21
{
22
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"document.txt"
,
"*.*"
);
23
return
-1;
24
}
25
26
if
(!FilePatternMatchA(
"Documents"
,
"*.*"
))
27
{
28
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"Documents"
,
"*.*"
);
29
return
-1;
30
}
31
32
/* '*X' expression */
33
34
if
(!FilePatternMatchA(
"document.txt"
,
"*.txt"
))
35
{
36
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"document.txt"
,
"*.txt"
);
37
return
-1;
38
}
39
40
if
(FilePatternMatchA(
"document.docx"
,
"*.txt"
))
41
{
42
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"document.docx"
,
"*.txt"
);
43
return
-1;
44
}
45
46
if
(FilePatternMatchA(
"document.txt.bak"
,
"*.txt"
))
47
{
48
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"document.txt.bak"
,
"*.txt"
);
49
return
-1;
50
}
51
52
if
(FilePatternMatchA(
"bak"
,
"*.txt"
))
53
{
54
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"bak"
,
"*.txt"
);
55
return
-1;
56
}
57
58
/* 'X*' expression */
59
60
if
(!FilePatternMatchA(
"document.txt"
,
"document.*"
))
61
{
62
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"document.txt"
,
"document.*"
);
63
return
-1;
64
}
65
66
/* 'X?' expression */
67
68
if
(!FilePatternMatchA(
"document.docx"
,
"document.doc?"
))
69
{
70
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"document.docx"
,
71
"document.doc?"
);
72
return
-1;
73
}
74
75
if
(FilePatternMatchA(
"document.doc"
,
"document.doc?"
))
76
{
77
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"document.doc"
,
78
"document.doc?"
);
79
return
-1;
80
}
81
82
/* no wildcards expression */
83
84
if
(!FilePatternMatchA(
"document.txt"
,
"document.txt"
))
85
{
86
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"document.txt"
,
87
"document.txt"
);
88
return
-1;
89
}
90
91
/* 'X * Y' expression */
92
93
if
(!FilePatternMatchA(
"X123Y.txt"
,
"X*Y.txt"
))
94
{
95
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"X123Y.txt"
,
"X*Y.txt"
);
96
return
-1;
97
}
98
99
if
(!FilePatternMatchA(
"XY.txt"
,
"X*Y.txt"
))
100
{
101
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"XY.txt"
,
"X*Y.txt"
);
102
return
-1;
103
}
104
105
if
(FilePatternMatchA(
"XZ.txt"
,
"X*Y.txt"
))
106
{
107
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"XZ.txt"
,
"X*Y.txt"
);
108
return
-1;
109
}
110
111
if
(FilePatternMatchA(
"X123Z.txt"
,
"X*Y.txt"
))
112
{
113
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"X123Z.txt"
,
"X*Y.txt"
);
114
return
-1;
115
}
116
117
/* 'X * Y * Z' expression */
118
119
if
(!FilePatternMatchA(
"X123Y456Z.txt"
,
"X*Y*Z.txt"
))
120
{
121
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"X123Y456Z.txt"
,
"X*Y*Z.txt"
);
122
return
-1;
123
}
124
125
if
(!FilePatternMatchA(
"XYZ.txt"
,
"X*Y*Z.txt"
))
126
{
127
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"XYZ.txt"
,
"X*Y*Z.txt"
);
128
return
-1;
129
}
130
131
if
(!FilePatternMatchA(
"X123Y456W.txt"
,
"X*Y*Z.txt"
))
132
{
133
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"X123Y456W.txt"
,
"X*Y*Z.txt"
);
134
return
-1;
135
}
136
137
if
(!FilePatternMatchA(
"XYW.txt"
,
"X*Y*Z.txt"
))
138
{
139
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"XYW.txt"
,
"X*Y*Z.txt"
);
140
return
-1;
141
}
142
143
/* 'X ? Y' expression */
144
145
if
(!FilePatternMatchA(
"X1Y.txt"
,
"X?Y.txt"
))
146
{
147
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"X1Y.txt"
,
"X?Y.txt"
);
148
return
-1;
149
}
150
151
if
(FilePatternMatchA(
"XY.txt"
,
"X?Y.txt"
))
152
{
153
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"XY.txt"
,
"X?Y.txt"
);
154
return
-1;
155
}
156
157
if
(FilePatternMatchA(
"XZ.txt"
,
"X?Y.txt"
))
158
{
159
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"XZ.txt"
,
"X?Y.txt"
);
160
return
-1;
161
}
162
163
if
(FilePatternMatchA(
"X123Z.txt"
,
"X?Y.txt"
))
164
{
165
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"X123Z.txt"
,
"X?Y.txt"
);
166
return
-1;
167
}
168
169
/* 'X ? Y ? Z' expression */
170
171
if
(!FilePatternMatchA(
"X123Y456Z.txt"
,
"X?Y?Z.txt"
))
172
{
173
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"X123Y456Z.txt"
,
"X?Y?Z.txt"
);
174
return
-1;
175
}
176
177
if
(FilePatternMatchA(
"XYZ.txt"
,
"X?Y?Z.txt"
))
178
{
179
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"XYZ.txt"
,
"X?Y?Z.txt"
);
180
return
-1;
181
}
182
183
if
(!FilePatternMatchA(
"X123Y456W.txt"
,
"X?Y?Z.txt"
))
184
{
185
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"X123Y456W.txt"
,
"X?Y?Z.txt"
);
186
return
-1;
187
}
188
189
if
(FilePatternMatchA(
"XYW.txt"
,
"X?Y?Z.txt"
))
190
{
191
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"XYW.txt"
,
"X?Y?Z.txt"
);
192
return
-1;
193
}
194
195
/* '?' must not match past the end of the file name.
196
* The file name "X" is one character; the byte after its terminator
197
* is set to 'Y' so that an out-of-bounds read in the X?Y branch would
198
* wrongly report a match. */
199
{
200
const
char
shortName[] = {
'X'
,
'\0'
,
'Y'
,
'\0'
};
201
202
if
(FilePatternMatchA(shortName,
"X?Y"
))
203
{
204
printf(
"FilePatternMatchA error: FileName: %s Pattern: %s\n"
,
"X"
,
"X?Y"
);
205
return
-1;
206
}
207
}
208
209
return
0;
210
}
winpr
libwinpr
file
test
TestFilePatternMatch.c
Generated by
1.9.8