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