1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * PROJECT:         ReactOS api tests
3*c2c66affSColin Finck  * LICENSE:         GPLv2+ - See COPYING in the top level directory
4*c2c66affSColin Finck  * PURPOSE:         Test for LdrEnumResources
5*c2c66affSColin Finck  * PROGRAMMER:      Timo Kreuzer
6*c2c66affSColin Finck  */
7*c2c66affSColin Finck 
8*c2c66affSColin Finck #include <apitest.h>
9*c2c66affSColin Finck 
10*c2c66affSColin Finck #define WIN32_NO_STATUS
11*c2c66affSColin Finck #include <ndk/ldrfuncs.h>
12*c2c66affSColin Finck 
13*c2c66affSColin Finck typedef struct _TEST_RESOURCES
14*c2c66affSColin Finck {
15*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY TypeDirectory;
16*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY_ENTRY TypeEntries[2];
17*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY Name1Directory;
18*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY_ENTRY Name1Entries[2];
19*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY Name2Directory;
20*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY_ENTRY Name2Entries[2];
21*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY Lang1Directory;
22*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY_ENTRY Lang1Entries[2];
23*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY Lang2Directory;
24*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY_ENTRY Lang2Entries[2];
25*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY Lang3Directory;
26*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY_ENTRY Lang3Entries[2];
27*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY Lang4Directory;
28*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY_ENTRY Lang4Entries[2];
29*c2c66affSColin Finck     IMAGE_RESOURCE_DATA_ENTRY DataEntries[8];
30*c2c66affSColin Finck     IMAGE_RESOURCE_DIRECTORY_STRING Name1String;
31*c2c66affSColin Finck     ULONG StringIndex;
32*c2c66affSColin Finck     WCHAR StringBuffer[20];
33*c2c66affSColin Finck } TEST_RESOURCES, *PTEST_RESOURCES;
34*c2c66affSColin Finck 
35*c2c66affSColin Finck typedef struct _TEST_IMAGE
36*c2c66affSColin Finck {
37*c2c66affSColin Finck     IMAGE_DOS_HEADER DosHeader;
38*c2c66affSColin Finck     IMAGE_NT_HEADERS NtHeaders;
39*c2c66affSColin Finck     IMAGE_SECTION_HEADER SectionHeaders[1];
40*c2c66affSColin Finck     TEST_RESOURCES Resources;
41*c2c66affSColin Finck } TEST_IMAGE, *PTEST_IMAGE;
42*c2c66affSColin Finck 
43*c2c66affSColin Finck static
44*c2c66affSColin Finck VOID
45*c2c66affSColin Finck InitializeResourceDirectory(
46*c2c66affSColin Finck     PIMAGE_RESOURCE_DIRECTORY ResourceDirectory,
47*c2c66affSColin Finck     USHORT NumberOfNamedEntries,
48*c2c66affSColin Finck     USHORT NumberOfIdEntries)
49*c2c66affSColin Finck {
50*c2c66affSColin Finck     ResourceDirectory->Characteristics = 0;
51*c2c66affSColin Finck     ResourceDirectory->TimeDateStamp = 0;
52*c2c66affSColin Finck     ResourceDirectory->MajorVersion = 0;
53*c2c66affSColin Finck     ResourceDirectory->MinorVersion = 0;
54*c2c66affSColin Finck     ResourceDirectory->NumberOfNamedEntries = NumberOfNamedEntries;
55*c2c66affSColin Finck     ResourceDirectory->NumberOfIdEntries = NumberOfIdEntries;
56*c2c66affSColin Finck }
57*c2c66affSColin Finck 
58*c2c66affSColin Finck static
59*c2c66affSColin Finck VOID
60*c2c66affSColin Finck InitializeNamedEntry(
61*c2c66affSColin Finck     PTEST_RESOURCES Resource,
62*c2c66affSColin Finck     PIMAGE_RESOURCE_DIRECTORY_ENTRY DirEntry,
63*c2c66affSColin Finck     PWCHAR Name,
64*c2c66affSColin Finck     PVOID Data)
65*c2c66affSColin Finck {
66*c2c66affSColin Finck     DirEntry->Name = Resource->StringIndex * 2 + FIELD_OFFSET(TEST_RESOURCES, StringBuffer);
67*c2c66affSColin Finck     DirEntry->NameIsString = 1;
68*c2c66affSColin Finck     DirEntry->OffsetToData = (PUCHAR)Data - (PUCHAR)Resource;
69*c2c66affSColin Finck     if (DirEntry < Resource->Lang1Entries)
70*c2c66affSColin Finck         DirEntry->DataIsDirectory = 1;
71*c2c66affSColin Finck     Resource->StringBuffer[Resource->StringIndex] = wcslen(Name);
72*c2c66affSColin Finck     wcscpy(&Resource->StringBuffer[Resource->StringIndex + 1], Name);
73*c2c66affSColin Finck     Resource->StringIndex += Resource->StringBuffer[Resource->StringIndex] * 2 + 1;
74*c2c66affSColin Finck }
75*c2c66affSColin Finck 
76*c2c66affSColin Finck static
77*c2c66affSColin Finck VOID
78*c2c66affSColin Finck InitializeIdEntry(
79*c2c66affSColin Finck     PTEST_RESOURCES Resource,
80*c2c66affSColin Finck     PIMAGE_RESOURCE_DIRECTORY_ENTRY DirEntry,
81*c2c66affSColin Finck     USHORT Id,
82*c2c66affSColin Finck     PVOID Data)
83*c2c66affSColin Finck {
84*c2c66affSColin Finck     DirEntry->Name = Id;
85*c2c66affSColin Finck     DirEntry->NameIsString = 0;
86*c2c66affSColin Finck     DirEntry->OffsetToData = (PUCHAR)Data - (PUCHAR)Resource;
87*c2c66affSColin Finck     if (DirEntry < Resource->Lang1Entries)
88*c2c66affSColin Finck         DirEntry->DataIsDirectory = 1;
89*c2c66affSColin Finck }
90*c2c66affSColin Finck 
91*c2c66affSColin Finck static
92*c2c66affSColin Finck VOID
93*c2c66affSColin Finck InitializeDataEntry(
94*c2c66affSColin Finck     PVOID ImageBase,
95*c2c66affSColin Finck     PIMAGE_RESOURCE_DATA_ENTRY DataEntry,
96*c2c66affSColin Finck     PVOID Data,
97*c2c66affSColin Finck     ULONG Size)
98*c2c66affSColin Finck {
99*c2c66affSColin Finck 
100*c2c66affSColin Finck     DataEntry->OffsetToData = (PUCHAR)Data - (PUCHAR)ImageBase;
101*c2c66affSColin Finck     DataEntry->Size = Size;
102*c2c66affSColin Finck     DataEntry->CodePage = 0;
103*c2c66affSColin Finck     DataEntry->Reserved = 0;
104*c2c66affSColin Finck }
105*c2c66affSColin Finck 
106*c2c66affSColin Finck static
107*c2c66affSColin Finck VOID
108*c2c66affSColin Finck InitializeTestResource(
109*c2c66affSColin Finck     PVOID ImageBase,
110*c2c66affSColin Finck     PTEST_RESOURCES Resource)
111*c2c66affSColin Finck {
112*c2c66affSColin Finck 
113*c2c66affSColin Finck     memset(Resource->StringBuffer, 0, sizeof(Resource->StringBuffer));
114*c2c66affSColin Finck     Resource->StringIndex = 0;
115*c2c66affSColin Finck 
116*c2c66affSColin Finck     InitializeResourceDirectory(&Resource->TypeDirectory, 0, 2);
117*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->TypeEntries[0], 1, &Resource->Name1Directory);
118*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->TypeEntries[1], 2, &Resource->Name2Directory);
119*c2c66affSColin Finck 
120*c2c66affSColin Finck     InitializeResourceDirectory(&Resource->Name1Directory, 1, 1);
121*c2c66affSColin Finck     InitializeNamedEntry(Resource, &Resource->Name1Entries[0], L"TEST", &Resource->Lang1Directory);
122*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->Name1Entries[1], 7, &Resource->Lang2Directory);
123*c2c66affSColin Finck 
124*c2c66affSColin Finck     InitializeResourceDirectory(&Resource->Name2Directory, 2, 0);
125*c2c66affSColin Finck     InitializeNamedEntry(Resource, &Resource->Name2Entries[0], L"LOL", &Resource->Lang3Directory);
126*c2c66affSColin Finck     InitializeNamedEntry(Resource, &Resource->Name2Entries[1], L"xD", &Resource->Lang4Directory);
127*c2c66affSColin Finck 
128*c2c66affSColin Finck     InitializeResourceDirectory(&Resource->Lang1Directory, 0, 2);
129*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->Lang1Entries[0], 0x409, &Resource->DataEntries[0]);
130*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->Lang1Entries[1], 0x407, &Resource->DataEntries[1]);
131*c2c66affSColin Finck 
132*c2c66affSColin Finck     InitializeResourceDirectory(&Resource->Lang2Directory, 0, 2);
133*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->Lang2Entries[0], 0x408, &Resource->DataEntries[2]);
134*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->Lang2Entries[1], 0x406, &Resource->DataEntries[3]);
135*c2c66affSColin Finck 
136*c2c66affSColin Finck     InitializeResourceDirectory(&Resource->Lang3Directory, 0, 2);
137*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->Lang3Entries[0], 0x405, &Resource->DataEntries[4]);
138*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->Lang3Entries[1], 0x403, &Resource->DataEntries[5]);
139*c2c66affSColin Finck 
140*c2c66affSColin Finck     InitializeResourceDirectory(&Resource->Lang4Directory, 0, 2);
141*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->Lang4Entries[0], 0x402, &Resource->DataEntries[6]);
142*c2c66affSColin Finck     InitializeIdEntry(Resource, &Resource->Lang4Entries[1], 0x404, &Resource->DataEntries[7]);
143*c2c66affSColin Finck 
144*c2c66affSColin Finck     InitializeDataEntry(ImageBase, &Resource->DataEntries[0], Resource->StringBuffer + 0, 2);
145*c2c66affSColin Finck     InitializeDataEntry(ImageBase, &Resource->DataEntries[1], Resource->StringBuffer + 2, 4);
146*c2c66affSColin Finck     InitializeDataEntry(ImageBase, &Resource->DataEntries[2], Resource->StringBuffer + 4, 6);
147*c2c66affSColin Finck     InitializeDataEntry(ImageBase, &Resource->DataEntries[3], Resource->StringBuffer + 6, 8);
148*c2c66affSColin Finck     InitializeDataEntry(ImageBase, &Resource->DataEntries[4], Resource->StringBuffer + 8, 10);
149*c2c66affSColin Finck     InitializeDataEntry(ImageBase, &Resource->DataEntries[5], Resource->StringBuffer + 10, 12);
150*c2c66affSColin Finck     InitializeDataEntry(ImageBase, &Resource->DataEntries[6], Resource->StringBuffer + 12, 14);
151*c2c66affSColin Finck     InitializeDataEntry(ImageBase, &Resource->DataEntries[7], Resource->StringBuffer + 14, 16);
152*c2c66affSColin Finck 
153*c2c66affSColin Finck }
154*c2c66affSColin Finck 
155*c2c66affSColin Finck VOID
156*c2c66affSColin Finck InitializeTestImage(
157*c2c66affSColin Finck     PTEST_IMAGE TestImage)
158*c2c66affSColin Finck {
159*c2c66affSColin Finck     PIMAGE_DATA_DIRECTORY ResourceDirectory;
160*c2c66affSColin Finck 
161*c2c66affSColin Finck     TestImage->DosHeader.e_magic = IMAGE_DOS_SIGNATURE;
162*c2c66affSColin Finck     TestImage->DosHeader.e_lfanew = sizeof(IMAGE_DOS_HEADER);
163*c2c66affSColin Finck 
164*c2c66affSColin Finck     TestImage->NtHeaders.Signature = IMAGE_NT_SIGNATURE;
165*c2c66affSColin Finck 
166*c2c66affSColin Finck     TestImage->NtHeaders.FileHeader.Machine = IMAGE_FILE_MACHINE_I386;
167*c2c66affSColin Finck     TestImage->NtHeaders.FileHeader.NumberOfSections = 1;
168*c2c66affSColin Finck     TestImage->NtHeaders.FileHeader.TimeDateStamp = 0;
169*c2c66affSColin Finck     TestImage->NtHeaders.FileHeader.PointerToSymbolTable = 0;
170*c2c66affSColin Finck     TestImage->NtHeaders.FileHeader.NumberOfSymbols = 0;
171*c2c66affSColin Finck     TestImage->NtHeaders.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
172*c2c66affSColin Finck     TestImage->NtHeaders.FileHeader.Characteristics = 0;
173*c2c66affSColin Finck 
174*c2c66affSColin Finck     TestImage->NtHeaders.OptionalHeader.Magic = IMAGE_NT_OPTIONAL_HDR32_MAGIC;
175*c2c66affSColin Finck     TestImage->NtHeaders.OptionalHeader.ImageBase = (DWORD)TestImage;
176*c2c66affSColin Finck     TestImage->NtHeaders.OptionalHeader.SizeOfImage = sizeof(TEST_IMAGE);
177*c2c66affSColin Finck     TestImage->NtHeaders.OptionalHeader.SizeOfHeaders = sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS);
178*c2c66affSColin Finck 
179*c2c66affSColin Finck     ResourceDirectory = &TestImage->NtHeaders.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE];
180*c2c66affSColin Finck     ResourceDirectory->VirtualAddress = FIELD_OFFSET(TEST_IMAGE, Resources);
181*c2c66affSColin Finck     ResourceDirectory->Size = sizeof(TEST_RESOURCES);
182*c2c66affSColin Finck 
183*c2c66affSColin Finck     strcpy((char*)TestImage->SectionHeaders[0].Name, ".rsrc");
184*c2c66affSColin Finck     TestImage->SectionHeaders[0].Misc.VirtualSize = sizeof(TEST_IMAGE);
185*c2c66affSColin Finck     TestImage->SectionHeaders[0].VirtualAddress = FIELD_OFFSET(TEST_IMAGE, Resources);
186*c2c66affSColin Finck     TestImage->SectionHeaders[0].SizeOfRawData = sizeof(TEST_IMAGE);
187*c2c66affSColin Finck     TestImage->SectionHeaders[0].PointerToRawData = FIELD_OFFSET(TEST_IMAGE, Resources);
188*c2c66affSColin Finck     TestImage->SectionHeaders[0].PointerToRelocations = 0;
189*c2c66affSColin Finck     TestImage->SectionHeaders[0].PointerToLinenumbers = 0;
190*c2c66affSColin Finck     TestImage->SectionHeaders[0].NumberOfRelocations = 0;
191*c2c66affSColin Finck     TestImage->SectionHeaders[0].NumberOfLinenumbers = 0;
192*c2c66affSColin Finck     TestImage->SectionHeaders[0].Characteristics = 0;
193*c2c66affSColin Finck 
194*c2c66affSColin Finck     InitializeTestResource(TestImage, &TestImage->Resources);
195*c2c66affSColin Finck }
196*c2c66affSColin Finck 
197*c2c66affSColin Finck #define ok_nwstr(str1, str2, count) \
198*c2c66affSColin Finck     ok(wcsncmp((PWCHAR)str1, (PWCHAR)str2, count) == 0, \
199*c2c66affSColin Finck        "string is wrong, expected: '%S', got '%S'\n", str1, str2); \
200*c2c66affSColin Finck 
201*c2c66affSColin Finck #define ok_enumres(_Res, _Type, _Name, _Lang, _Data, _Size) \
202*c2c66affSColin Finck     ok_dec((_Res)->Type, _Type); \
203*c2c66affSColin Finck     if ((ULONG_PTR)(_Name) > 0xFFFF) \
204*c2c66affSColin Finck     { \
205*c2c66affSColin Finck         ok_dec(*(WORD*)((_Res)->Name), wcslen((PWCHAR)(_Name))); \
206*c2c66affSColin Finck         ok_nwstr((PWCHAR)((_Res)->Name + 2), (PWCHAR)_Name, *(WORD*)((_Res)->Name)); \
207*c2c66affSColin Finck     } \
208*c2c66affSColin Finck     else \
209*c2c66affSColin Finck     { \
210*c2c66affSColin Finck         ok_dec((_Res)->Name, (ULONG_PTR)_Name); \
211*c2c66affSColin Finck     } \
212*c2c66affSColin Finck     ok_hex((_Res)->Language, _Lang); \
213*c2c66affSColin Finck     ok_ptr((PVOID)(_Res)->Data, _Data); \
214*c2c66affSColin Finck     ok_dec((_Res)->Size, _Size); \
215*c2c66affSColin Finck     ok_dec((_Res)->Reserved, 0);
216*c2c66affSColin Finck 
217*c2c66affSColin Finck static
218*c2c66affSColin Finck void
219*c2c66affSColin Finck Test_Data(PTEST_IMAGE TestImage)
220*c2c66affSColin Finck {
221*c2c66affSColin Finck     LDR_RESOURCE_INFO ResourceInfo;
222*c2c66affSColin Finck     LDR_ENUM_RESOURCE_INFO EnumRes[8];
223*c2c66affSColin Finck     ULONG ResourceCount;
224*c2c66affSColin Finck     NTSTATUS Status;
225*c2c66affSColin Finck 
226*c2c66affSColin Finck     InitializeTestImage(TestImage);
227*c2c66affSColin Finck 
228*c2c66affSColin Finck     memset(EnumRes, 0xcc, sizeof(EnumRes));
229*c2c66affSColin Finck 
230*c2c66affSColin Finck     ResourceInfo.Type = 1;
231*c2c66affSColin Finck     ResourceInfo.Name = 1;
232*c2c66affSColin Finck     ResourceInfo.Language = 0x408;
233*c2c66affSColin Finck     ResourceCount = 8;
234*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, EnumRes);
235*c2c66affSColin Finck     ok_hex(Status, STATUS_SUCCESS);
236*c2c66affSColin Finck     ok_dec(ResourceCount, 8);
237*c2c66affSColin Finck 
238*c2c66affSColin Finck     ok_ptr((PVOID)EnumRes[0].Data, TestImage->Resources.StringBuffer);
239*c2c66affSColin Finck     ok_dec(EnumRes[0].Size, 2);
240*c2c66affSColin Finck 
241*c2c66affSColin Finck     ok_enumres(&EnumRes[0], 1, L"TEST", 0x409, TestImage->Resources.StringBuffer, 2)
242*c2c66affSColin Finck     ok_enumres(&EnumRes[1], 1, L"TEST", 0x407, TestImage->Resources.StringBuffer + 2, 4)
243*c2c66affSColin Finck     ok_enumres(&EnumRes[2], 1, 7, 0x408, TestImage->Resources.StringBuffer + 4, 6)
244*c2c66affSColin Finck     ok_enumres(&EnumRes[3], 1, 7, 0x406, TestImage->Resources.StringBuffer + 6, 8)
245*c2c66affSColin Finck     ok_enumres(&EnumRes[4], 2, L"LOL", 0x405, TestImage->Resources.StringBuffer + 8, 10)
246*c2c66affSColin Finck     ok_enumres(&EnumRes[5], 2, L"LOL", 0x403, TestImage->Resources.StringBuffer + 10, 12)
247*c2c66affSColin Finck     ok_enumres(&EnumRes[6], 2, L"xD", 0x402, TestImage->Resources.StringBuffer + 12, 14)
248*c2c66affSColin Finck     ok_enumres(&EnumRes[7], 2, L"xD", 0x404, TestImage->Resources.StringBuffer + 14, 16)
249*c2c66affSColin Finck 
250*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, EnumRes);
251*c2c66affSColin Finck     ok_hex(Status, STATUS_SUCCESS);
252*c2c66affSColin Finck     ok_dec(ResourceCount, 4);
253*c2c66affSColin Finck 
254*c2c66affSColin Finck }
255*c2c66affSColin Finck 
256*c2c66affSColin Finck 
257*c2c66affSColin Finck static
258*c2c66affSColin Finck void
259*c2c66affSColin Finck Test_Parameters(PTEST_IMAGE TestImage)
260*c2c66affSColin Finck {
261*c2c66affSColin Finck     LDR_RESOURCE_INFO ResourceInfo;
262*c2c66affSColin Finck     LDR_ENUM_RESOURCE_INFO Resources[8];
263*c2c66affSColin Finck     ULONG ResourceCount;
264*c2c66affSColin Finck     NTSTATUS Status;
265*c2c66affSColin Finck 
266*c2c66affSColin Finck     InitializeTestImage(TestImage);
267*c2c66affSColin Finck 
268*c2c66affSColin Finck     ResourceInfo.Type = 6;
269*c2c66affSColin Finck     ResourceInfo.Name = 1;
270*c2c66affSColin Finck     ResourceInfo.Language = 0x409;
271*c2c66affSColin Finck 
272*c2c66affSColin Finck     ResourceCount = 8;
273*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 3, &ResourceCount, Resources);
274*c2c66affSColin Finck     ok_hex(Status, STATUS_SUCCESS);
275*c2c66affSColin Finck     ok_dec(ResourceCount, 0);
276*c2c66affSColin Finck 
277*c2c66affSColin Finck     ResourceInfo.Type = 1;
278*c2c66affSColin Finck     ResourceInfo.Name = 7;
279*c2c66affSColin Finck     ResourceInfo.Language = 0x406;
280*c2c66affSColin Finck     ResourceCount = 8;
281*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, Resources);
282*c2c66affSColin Finck     ok_hex(Status,  STATUS_SUCCESS);
283*c2c66affSColin Finck     ok_dec(ResourceCount, 8);
284*c2c66affSColin Finck 
285*c2c66affSColin Finck     ResourceCount = 8;
286*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, Resources);
287*c2c66affSColin Finck     ok_hex(Status, STATUS_SUCCESS);
288*c2c66affSColin Finck     ok_dec(ResourceCount, 4);
289*c2c66affSColin Finck 
290*c2c66affSColin Finck     ResourceCount = 8;
291*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 2, &ResourceCount, Resources);
292*c2c66affSColin Finck     ok_hex(Status, STATUS_SUCCESS);
293*c2c66affSColin Finck     ok_dec(ResourceCount, 2);
294*c2c66affSColin Finck 
295*c2c66affSColin Finck     ResourceCount = 8;
296*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 3, &ResourceCount, Resources);
297*c2c66affSColin Finck     ok_hex(Status, STATUS_SUCCESS);
298*c2c66affSColin Finck     ok_dec(ResourceCount, 1);
299*c2c66affSColin Finck 
300*c2c66affSColin Finck     ResourceCount = 8;
301*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 99, &ResourceCount, Resources);
302*c2c66affSColin Finck     ok_hex(Status, STATUS_SUCCESS);
303*c2c66affSColin Finck     ok_dec(ResourceCount, 1);
304*c2c66affSColin Finck 
305*c2c66affSColin Finck     ResourceCount = 0;
306*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, Resources);
307*c2c66affSColin Finck     ok_hex(Status,  STATUS_INFO_LENGTH_MISMATCH);
308*c2c66affSColin Finck     ok_dec(ResourceCount, 8);
309*c2c66affSColin Finck 
310*c2c66affSColin Finck     ResourceCount = 7;
311*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 0, &ResourceCount, Resources);
312*c2c66affSColin Finck     ok_hex(Status,  STATUS_INFO_LENGTH_MISMATCH);
313*c2c66affSColin Finck     ok_dec(ResourceCount, 8);
314*c2c66affSColin Finck 
315*c2c66affSColin Finck     ResourceCount = 8;
316*c2c66affSColin Finck     Status = LdrEnumResources(NULL, &ResourceInfo, 1, &ResourceCount, Resources);
317*c2c66affSColin Finck     ok_hex(Status, STATUS_RESOURCE_DATA_NOT_FOUND);
318*c2c66affSColin Finck     ok_dec(ResourceCount, 0);
319*c2c66affSColin Finck 
320*c2c66affSColin Finck     ResourceCount = 8;
321*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, NULL);
322*c2c66affSColin Finck     ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
323*c2c66affSColin Finck     ok_dec(ResourceCount, 4);
324*c2c66affSColin Finck 
325*c2c66affSColin Finck     ResourceCount = 8;
326*c2c66affSColin Finck     _SEH2_TRY
327*c2c66affSColin Finck     {
328*c2c66affSColin Finck         Status = LdrEnumResources(NULL, NULL, 0, NULL, NULL);
329*c2c66affSColin Finck     }
330*c2c66affSColin Finck     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
331*c2c66affSColin Finck     {
332*c2c66affSColin Finck         Status = 0xDeadC0de;
333*c2c66affSColin Finck     }
334*c2c66affSColin Finck     _SEH2_END
335*c2c66affSColin Finck     ok_hex(Status, 0xDeadC0de);
336*c2c66affSColin Finck 
337*c2c66affSColin Finck     ResourceCount = 42;
338*c2c66affSColin Finck     _SEH2_TRY
339*c2c66affSColin Finck     {
340*c2c66affSColin Finck         Status = LdrEnumResources(TestImage, &ResourceInfo, 1, NULL, Resources);
341*c2c66affSColin Finck     }
342*c2c66affSColin Finck     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
343*c2c66affSColin Finck     {
344*c2c66affSColin Finck         Status = 0xDeadC0de;
345*c2c66affSColin Finck     }
346*c2c66affSColin Finck     _SEH2_END
347*c2c66affSColin Finck     ok_hex(Status, 0xDeadC0de);
348*c2c66affSColin Finck     ok_dec(ResourceCount, 42);
349*c2c66affSColin Finck 
350*c2c66affSColin Finck     ResourceCount = 8;
351*c2c66affSColin Finck     Status = LdrEnumResources(TestImage + 2, &ResourceInfo, 1, &ResourceCount, NULL);
352*c2c66affSColin Finck     ok_hex(Status,  STATUS_RESOURCE_DATA_NOT_FOUND);
353*c2c66affSColin Finck     ok_dec(ResourceCount, 0);
354*c2c66affSColin Finck 
355*c2c66affSColin Finck     TestImage->Resources.TypeEntries[0].DataIsDirectory = 0;
356*c2c66affSColin Finck     Status = LdrEnumResources(TestImage, &ResourceInfo, 1, &ResourceCount, NULL);
357*c2c66affSColin Finck     ok_hex(Status,  STATUS_INVALID_IMAGE_FORMAT);
358*c2c66affSColin Finck     ok_dec(ResourceCount, 0);
359*c2c66affSColin Finck 
360*c2c66affSColin Finck }
361*c2c66affSColin Finck 
362*c2c66affSColin Finck START_TEST(LdrEnumResources)
363*c2c66affSColin Finck {
364*c2c66affSColin Finck     TEST_IMAGE TestImage;
365*c2c66affSColin Finck 
366*c2c66affSColin Finck     Test_Parameters(&TestImage);
367*c2c66affSColin Finck     Test_Data(&TestImage);
368*c2c66affSColin Finck 
369*c2c66affSColin Finck }
370