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