1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE:         Test for PrivateExtractIcons
5  * PROGRAMMER:      Hermes Belusca-Maito
6  */
7 
8 #include "precomp.h"
9 
10 static struct
11 {
12     PCWSTR FilePath;
13     UINT cIcons;        // Return value from PrivateExtractIconsW
14     BOOL bhIconValid;   // Whether or not the returned icon handle is not NULL.
15 } IconTests[] =
16 {
17     /* Executables with icons */
18     {L"notepad.exe", 1, TRUE},
19     {L"%SystemRoot%\\System32\\cmd.exe", 1, TRUE},
20 
21     /* Executable without icon */
22     {L"%SystemRoot%\\System32\\autochk.exe", 0, FALSE},
23 
24     /* Existing file */
25     {L"%SystemRoot%\\System32\\shell32.dll", 1, TRUE},
26 
27     /* Non-existing files */
28     {L"%SystemRoot%\\non-existent-file.sdf", 0xFFFFFFFF, FALSE},
29 };
30 
31 START_TEST(PrivateExtractIcons)
32 {
33     HICON ahIcon;
34     UINT i, aIconId, cIcons;
35 
36     for (i = 0; i < _countof(IconTests); ++i)
37     {
38         /* Always test extraction of the FIRST icon (index 0) */
39         ahIcon = (HICON)UlongToHandle(0xdeadbeef);
40         aIconId = 0xdeadbeef;
41         cIcons = PrivateExtractIconsW(IconTests[i].FilePath, 0, 16, 16, &ahIcon, &aIconId, 1, 0);
42         ok(cIcons == IconTests[i].cIcons, "PrivateExtractIconsW(%u): got %u, expected %u\n", i, cIcons, IconTests[i].cIcons);
43         ok(ahIcon != (HICON)UlongToHandle(0xdeadbeef), "PrivateExtractIconsW(%u): icon not set\n", i);
44         ok((IconTests[i].bhIconValid && ahIcon) || (!IconTests[i].bhIconValid && !ahIcon),
45             "PrivateExtractIconsW(%u): icon expected to be %s, but got 0x%p\n",
46             i, IconTests[i].bhIconValid ? "valid" : "not valid", ahIcon);
47         if (cIcons == 0xFFFFFFFF)
48         {
49             ok(aIconId == 0xdeadbeef, "PrivateExtractIconsW(%u): id should not be set\n", i);
50         }
51         else
52         {
53             ok(aIconId != 0xdeadbeef, "PrivateExtractIconsW(%u): id not set\n", i);
54         }
55         if (ahIcon && ahIcon != (HICON)UlongToHandle(0xdeadbeef))
56             DestroyIcon(ahIcon);
57     }
58 }
59