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