1 
2 #include "precomp.h"
3 
4 START_TEST(LookupIconIdFromDirectoryEx)
5 {
6     HRSRC hResource;
7     HGLOBAL hMem;
8     HMODULE hMod;
9     int wResId;
10     DEVMODEW dm;
11     DWORD dwOrigBpp;
12     UINT i;
13     BYTE* lpResource;
14 
15     /* This tests assumes that default icon size is 32x32 */
16 
17     struct
18     {
19         DWORD bpp;
20         int wResId;
21         int cxDesired;
22         int cyDesired;
23         UINT flags;
24     }
25     TestData[] =
26     {
27         {8,  1,  0,  0,  0},
28         {8,  1,  48, 48, 0},
29         {8,  2,  32, 32, 0},
30         {8,  3,  24, 24, 0},
31         {8,  4,  16, 16, 0},
32         {8,  1,  0,  0,  LR_MONOCHROME},
33         {8,  1,  48, 48, LR_MONOCHROME},
34         {8,  2,  32, 32, LR_MONOCHROME},
35         {8,  3,  24, 24, LR_MONOCHROME},
36         {8,  4,  16, 16, LR_MONOCHROME},
37         {8,  2,  0,  0,  LR_DEFAULTSIZE},
38         {8,  1,  48, 48, LR_DEFAULTSIZE},
39         /* Non exact sizes */
40         {8,  1,  41, 41, 0},
41         {8,  1,  40, 40, 0},
42         /* Non square sizes */
43         {8,  1,  16, 48, 0},
44         {8,  1,  48, 16, 0},
45         {16, 5,  0,  0,  0},
46         {16, 5,  48, 48, 0},
47         {16, 6,  32, 32, 0},
48         {16, 7,  24, 24, 0},
49         {16, 1,  0,  0,  LR_MONOCHROME},
50         {16, 1,  48, 48, LR_MONOCHROME},
51         {16, 2,  32, 32, LR_MONOCHROME},
52         {16, 3,  24, 24, LR_MONOCHROME},
53         {16, 4,  16, 16, LR_MONOCHROME},
54         {16, 6,  0,  0,  LR_DEFAULTSIZE},
55         {16, 5,  48, 48, LR_DEFAULTSIZE},
56         {24, 5,  0,  0,  0},
57         {24, 5,  48, 48, 0},
58         {24, 6,  32, 32, 0},
59         {24, 7,  24, 24, 0},
60         {24, 8,  16, 16, 0},
61         {16, 8,  16, 16, 0},
62         {24, 1,  0,  0,  LR_MONOCHROME},
63         {24, 1,  48, 48, LR_MONOCHROME},
64         {24, 2,  32, 32, LR_MONOCHROME},
65         {24, 3,  24, 24, LR_MONOCHROME},
66         {24, 4,  16, 16, LR_MONOCHROME},
67         {24, 6,  0,  0,  LR_DEFAULTSIZE},
68         {24, 5,  48, 48, LR_DEFAULTSIZE},
69         {32, 9,  0,  0,  0},
70         {32, 9,  48, 48, 0},
71         {32, 10, 32, 32, 0},
72         {32, 11, 24, 24, 0},
73         {32, 12, 16, 16, 0},
74         {32, 1,  0,  0,  LR_MONOCHROME},
75         {32, 1,  48, 48, LR_MONOCHROME},
76         {32, 2,  32, 32, LR_MONOCHROME},
77         {32, 3,  24, 24, LR_MONOCHROME},
78         {32, 4,  16, 16, LR_MONOCHROME},
79         {32, 10, 0,  0,  LR_DEFAULTSIZE},
80         {32, 9,  48, 48, LR_DEFAULTSIZE},
81     };
82 
83     hMod = GetModuleHandle(NULL);
84     ok(hMod != NULL, "\n");
85     /* Find our cursor directory resource */
86     hResource = FindResourceA(hMod,
87                             MAKEINTRESOURCE(IDI_TEST),
88                             RT_GROUP_ICON);
89     ok(hResource != NULL, "\n");
90 
91     hMem = LoadResource(hMod, hResource);
92     ok(hMem != NULL, "\n");
93 
94     lpResource = LockResource(hMem);
95     ok(lpResource != NULL, "\n");
96 
97     dm.dmSize = sizeof(dm);
98     dm.dmDriverExtra = 0;
99 
100     ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &dm), "\n");
101 
102     dwOrigBpp = dm.dmBitsPerPel;
103 
104     for (i = 0; i < sizeof(TestData)/sizeof(TestData[0]); i++)
105     {
106         dm.dmBitsPerPel = TestData[i].bpp;
107         if (ChangeDisplaySettingsExW(NULL, &dm, NULL, 0, NULL) != DISP_CHANGE_SUCCESSFUL)
108         {
109             skip("Unable to change bpp to %lu.\n", dm.dmBitsPerPel);
110             continue;
111         }
112         wResId = LookupIconIdFromDirectoryEx(lpResource, TRUE, TestData[i].cxDesired, TestData[i].cyDesired, TestData[i].flags);
113         ok(wResId == TestData[i].wResId, "Got %d, expected %d for %dx%dx%lu, flags %x.\n",
114             wResId,
115             TestData[i].wResId,
116             TestData[i].cxDesired,
117             TestData[i].cyDesired,
118             TestData[i].bpp,
119             TestData[i].flags);
120     }
121 
122     /* Restore */
123     dm.dmBitsPerPel = dwOrigBpp;
124     ok(ChangeDisplaySettingsExW(NULL, &dm, NULL, 0, NULL) == DISP_CHANGE_SUCCESSFUL, "\n");
125 
126     FreeResource(hMem);
127 }
128