[WS2_32_APITEST]
[reactos.git] / rostests / apitests / ntdll / RtlDosSearchPath_Ustr.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for RtlDosSearchPath_Ustr
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
12
13 /*
14 NTSTATUS
15 NTAPI
16 RtlDosSearchPath_Ustr(
17 IN ULONG Flags,
18 IN PUNICODE_STRING PathString,
19 IN PUNICODE_STRING FileNameString,
20 IN PUNICODE_STRING ExtensionString,
21 IN PUNICODE_STRING CallerBuffer,
22 IN OUT PUNICODE_STRING DynamicString OPTIONAL,
23 OUT PUNICODE_STRING *FullNameOut OPTIONAL,
24 OUT PSIZE_T FilePartSize OPTIONAL,
25 OUT PSIZE_T LengthNeeded OPTIONAL
26 );
27 */
28
29 #define ok_eq_ulong(value, expected) ok((value) == (expected), #value " = %lu, expected %lu\n", value, expected)
30 #define ok_eq_hex(value, expected) ok((value) == (expected), #value " = 0x%lx, expected 0x%lx\n", value, expected)
31 #define ok_eq_pointer(value, expected) ok((value) == (expected), #value " = %p, expected %p\n", value, expected)
32
33 #define ok_eq_ustr(str1, str2) do { \
34 ok((str1)->Buffer == (str2)->Buffer, "Buffer modified\n"); \
35 ok((str1)->Length == (str2)->Length, "Length modified\n"); \
36 ok((str1)->MaximumLength == (str2)->MaximumLength, "MaximumLength modified\n"); \
37 } while (0)
38
39 START_TEST(RtlDosSearchPath_Ustr)
40 {
41 NTSTATUS Status;
42 UNICODE_STRING PathString;
43 UNICODE_STRING FileNameString;
44 UNICODE_STRING ExtensionString;
45 UNICODE_STRING CallerBuffer;
46 UNICODE_STRING DynamicString;
47 PUNICODE_STRING FullNameOut;
48 UNICODE_STRING EmptyString;
49 SIZE_T FilePartSize;
50 SIZE_T LengthNeeded;
51 INT i;
52
53 RtlInitUnicodeString(&EmptyString, NULL);
54
55 /* NULLs */
56 StartSeh()
57 Status = RtlDosSearchPath_Ustr(0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
58 ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
59 EndSeh(STATUS_SUCCESS);
60
61 RtlInitUnicodeString(&FileNameString, NULL);
62 StartSeh()
63 Status = RtlDosSearchPath_Ustr(0, NULL, &FileNameString, NULL, NULL, NULL, NULL, NULL, NULL);
64 ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
65 EndSeh(STATUS_SUCCESS);
66
67 RtlInitUnicodeString(&PathString, NULL);
68 StartSeh()
69 Status = RtlDosSearchPath_Ustr(0, &PathString, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
70 ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
71 EndSeh(STATUS_SUCCESS);
72 ok_eq_ustr(&PathString, &EmptyString);
73
74 /* Minimal valid set of parameters */
75 RtlInitUnicodeString(&PathString, NULL);
76 RtlInitUnicodeString(&FileNameString, NULL);
77 StartSeh()
78 Status = RtlDosSearchPath_Ustr(0, &PathString, &FileNameString, NULL, NULL, NULL, NULL, NULL, NULL);
79 ok_eq_hex(Status, STATUS_NO_SUCH_FILE);
80 EndSeh(STATUS_SUCCESS);
81 ok_eq_ustr(&PathString, &EmptyString);
82 ok_eq_ustr(&FileNameString, &EmptyString);
83
84 /* Check valid flags */
85 for (i = 0; i < 32; i++)
86 {
87 RtlInitUnicodeString(&PathString, NULL);
88 RtlInitUnicodeString(&FileNameString, NULL);
89 StartSeh()
90 Status = RtlDosSearchPath_Ustr(1 << i, &PathString, &FileNameString, NULL, NULL, NULL, NULL, NULL, NULL);
91 ok_eq_hex(Status, i > 2 ? STATUS_INVALID_PARAMETER : STATUS_NO_SUCH_FILE);
92 EndSeh(STATUS_SUCCESS);
93 ok_eq_ustr(&PathString, &EmptyString);
94 ok_eq_ustr(&FileNameString, &EmptyString);
95 }
96
97 RtlInitUnicodeString(&PathString, NULL);
98 RtlInitUnicodeString(&FileNameString, NULL);
99 StartSeh()
100 Status = RtlDosSearchPath_Ustr(7, &PathString, &FileNameString, NULL, NULL, NULL, NULL, NULL, NULL);
101 ok_eq_hex(Status, STATUS_NO_SUCH_FILE);
102 EndSeh(STATUS_SUCCESS);
103 ok_eq_ustr(&PathString, &EmptyString);
104 ok_eq_ustr(&FileNameString, &EmptyString);
105
106 /* Everything except PathString */
107 RtlInitUnicodeString(&FileNameString, NULL);
108 RtlInitUnicodeString(&ExtensionString, NULL);
109 RtlInitUnicodeString(&CallerBuffer, NULL);
110 RtlInitUnicodeString(&DynamicString, NULL);
111 FullNameOut = InvalidPointer;
112 FilePartSize = (SIZE_T)-1;
113 LengthNeeded = (SIZE_T)-1;
114 StartSeh()
115 Status = RtlDosSearchPath_Ustr(0,
116 NULL,
117 &FileNameString,
118 &ExtensionString,
119 &CallerBuffer,
120 &DynamicString,
121 &FullNameOut,
122 &FilePartSize,
123 &LengthNeeded);
124 ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
125 EndSeh(STATUS_SUCCESS);
126 ok_eq_ustr(&FileNameString, &EmptyString);
127 ok_eq_ustr(&ExtensionString, &EmptyString);
128 ok_eq_ustr(&CallerBuffer, &EmptyString);
129 ok_eq_ustr(&DynamicString, &EmptyString);
130 ok_eq_pointer(FullNameOut, NULL);
131 ok_eq_ulong(FilePartSize, 0UL);
132 ok_eq_ulong(LengthNeeded, 0UL);
133
134 /* Everything except FileNameString */
135 RtlInitUnicodeString(&PathString, NULL);
136 RtlInitUnicodeString(&ExtensionString, NULL);
137 RtlInitUnicodeString(&CallerBuffer, NULL);
138 RtlInitUnicodeString(&DynamicString, NULL);
139 FullNameOut = InvalidPointer;
140 FilePartSize = (SIZE_T)-1;
141 LengthNeeded = (SIZE_T)-1;
142 StartSeh()
143 Status = RtlDosSearchPath_Ustr(0,
144 &PathString,
145 NULL,
146 &ExtensionString,
147 &CallerBuffer,
148 &DynamicString,
149 &FullNameOut,
150 &FilePartSize,
151 &LengthNeeded);
152 ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
153 EndSeh(STATUS_SUCCESS);
154 ok_eq_ustr(&PathString, &EmptyString);
155 ok_eq_ustr(&ExtensionString, &EmptyString);
156 ok_eq_ustr(&CallerBuffer, &EmptyString);
157 ok_eq_ustr(&DynamicString, &EmptyString);
158 ok_eq_pointer(FullNameOut, NULL);
159 ok_eq_ulong(FilePartSize, 0UL);
160 ok_eq_ulong(LengthNeeded, 0UL);
161
162 /* Passing CallerBuffer and DynamicString, but not FullNameOut is invalid */
163 RtlInitUnicodeString(&PathString, NULL);
164 RtlInitUnicodeString(&FileNameString, NULL);
165 RtlInitUnicodeString(&ExtensionString, NULL);
166 RtlInitUnicodeString(&CallerBuffer, NULL);
167 RtlInitUnicodeString(&DynamicString, NULL);
168 FullNameOut = InvalidPointer;
169 FilePartSize = (SIZE_T)-1;
170 LengthNeeded = (SIZE_T)-1;
171 StartSeh()
172 Status = RtlDosSearchPath_Ustr(0,
173 &PathString,
174 &FileNameString,
175 &ExtensionString,
176 &CallerBuffer,
177 &DynamicString,
178 NULL,
179 &FilePartSize,
180 &LengthNeeded);
181 ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
182 EndSeh(STATUS_SUCCESS);
183 ok_eq_ustr(&PathString, &EmptyString);
184 ok_eq_ustr(&FileNameString, &EmptyString);
185 ok_eq_ustr(&ExtensionString, &EmptyString);
186 ok_eq_ustr(&CallerBuffer, &EmptyString);
187 ok_eq_ustr(&DynamicString, &EmptyString);
188 ok_eq_ulong(FilePartSize, 0UL);
189 ok_eq_ulong(LengthNeeded, 0UL);
190
191 /* All parameters given */
192 RtlInitUnicodeString(&PathString, NULL);
193 RtlInitUnicodeString(&FileNameString, NULL);
194 RtlInitUnicodeString(&ExtensionString, NULL);
195 RtlInitUnicodeString(&CallerBuffer, NULL);
196 RtlInitUnicodeString(&DynamicString, NULL);
197 FullNameOut = InvalidPointer;
198 FilePartSize = (SIZE_T)-1;
199 LengthNeeded = (SIZE_T)-1;
200 StartSeh()
201 Status = RtlDosSearchPath_Ustr(0,
202 &PathString,
203 &FileNameString,
204 &ExtensionString,
205 &CallerBuffer,
206 &DynamicString,
207 &FullNameOut,
208 &FilePartSize,
209 &LengthNeeded);
210 ok_eq_hex(Status, STATUS_NO_SUCH_FILE);
211 EndSeh(STATUS_SUCCESS);
212 ok_eq_ustr(&PathString, &EmptyString);
213 ok_eq_ustr(&FileNameString, &EmptyString);
214 ok_eq_ustr(&ExtensionString, &EmptyString);
215 ok_eq_ustr(&CallerBuffer, &EmptyString);
216 ok_eq_ustr(&DynamicString, &EmptyString);
217 ok_eq_pointer(FullNameOut, NULL);
218 ok_eq_ulong(FilePartSize, 0UL);
219 ok_eq_ulong(LengthNeeded, 0UL);
220 }