ReactOS 0.4.16-dev-1489-g8fbbb41
LoadImage.c File Reference
#include "precomp.h"
Include dependency graph for LoadImage.c:

Go to the source code of this file.

Functions

static void test_LoadImage_DataFile (void)
 
static void test_LoadIcon_SystemIds (void)
 
 START_TEST (LoadImage)
 

Function Documentation

◆ START_TEST()

START_TEST ( LoadImage  )

Definition at line 84 of file LoadImage.c.

85{
86 char path[MAX_PATH];
88 STARTUPINFO si;
90
91 char **test_argv;
93
94 /* Now check its behaviour regarding Shared icons/cursors */
96 ok(handle != 0, "\n");
97
98 if (argc >= 3)
99 {
100 HANDLE arg;
101 HICON hCopy;
103 HDC hdc, hdcScreen;
104 ICONINFO ii;
105
106 sscanf (test_argv[2], "%Iu", (ULONG_PTR*) &arg);
107
108 ok(handle != arg, "Got same handles\n");
109
110 /* Try copying it */
111 hCopy = CopyIcon(arg);
112 ok(hCopy != NULL, "\n");
113 ok(DestroyIcon(hCopy), "\n");
114
115 hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, 0);
116 ok(hCopy != NULL, "\n");
117 ok(DestroyIcon(hCopy), "\n");
118 /* Unlike the original, this one is not shared */
119 ok(!DestroyIcon(hCopy), "\n");
120
122 ok(hCopy != NULL, "\n");
123 ok(DestroyIcon(hCopy), "\n");
124 /* Unlike the original, this one is not shared */
125 ok(!DestroyIcon(hCopy), "\n");
126
128 ok(hCopy != NULL, "\n");
129 ok(DestroyIcon(hCopy), "\n");
130 /* This one is shared */
131 ok(DestroyIcon(hCopy), "\n");
132
133 hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, LR_SHARED);
134 ok(hCopy != NULL, "\n");
135 ok(DestroyIcon(hCopy), "DestroyIcon should succeed.\n");
136 /* This one is shared */
137 ok(DestroyIcon(hCopy) == 0, "DestroyIcon should fail.\n");
138
139 /* Try various usual functions */
140 hdcScreen = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
141 ok(hdcScreen != NULL, "\n");
142 hdc = CreateCompatibleDC(hdcScreen);
143 ok(hdc != NULL, "\n");
144 hbmp = CreateCompatibleBitmap(hdcScreen, 64, 64);
145 ok(hbmp != NULL, "\n");
147 ok(hbmp != NULL, "\n");
148
149 ok(DrawIcon(hdc, 0, 0, arg), "\n");
152 DeleteDC(hdc);
153 DeleteDC(hdcScreen);
154
155 ok(GetIconInfo(arg, &ii), "\n");
156 ok(ii.hbmMask != NULL, "\n");
158 if(ii.hbmColor) DeleteObject(ii.hbmColor);
159
160 /* LOAD_LIBRARY_AS_DATAFILE */
162
163 return;
164 }
165
166 /* Start child process */
167 sprintf( path, "%s LoadImage %Iu", test_argv[0], (ULONG_PTR)handle );
168 memset( &si, 0, sizeof(si) );
169 si.cb = sizeof(si);
170 CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi );
171 WaitForSingleObject (pi.hProcess, INFINITE);
172
174}
static void test_LoadImage_DataFile(void)
Definition: LoadImage.c:4
static void test_LoadIcon_SystemIds(void)
Definition: LoadImage.c:48
static int argc
Definition: ServiceArgs.c:12
#define ok(value,...)
Definition: atltest.h:57
HBITMAP hbmp
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4747
#define L(x)
Definition: resources.c:13
#define INFINITE
Definition: serial.h:102
pKey DeleteObject()
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define sprintf(buf, format,...)
Definition: sprintf.c:55
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
static HICON
Definition: imagelist.c:80
static refpint_t pi[]
Definition: server.c:96
static char ** test_argv
Definition: cursoricon.c:296
int winetest_get_mainargs(char ***pargv)
#define memset(x, y, z)
Definition: compat.h:39
HBITMAP hbmColor
Definition: winuser.h:3229
HBITMAP hbmMask
Definition: winuser.h:3228
DWORD cb
Definition: winbase.h:866
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define GetModuleHandle
Definition: winbase.h:3868
void * arg
Definition: msvc.h:10
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
BOOL WINAPI DeleteDC(_In_ HDC)
HDC WINAPI CreateDCW(_In_opt_ LPCWSTR pszDriver, _In_opt_ LPCWSTR pszDevice, _In_opt_ LPCWSTR psz, _In_opt_ const DEVMODEW *pdmInit)
BOOL WINAPI GetIconInfo(_In_ HICON, _Out_ PICONINFO)
Definition: cursoricon.c:2397
#define LR_COPYFROMRESOURCE
Definition: winuser.h:1110
BOOL WINAPI DrawIcon(_In_ HDC, _In_ int, _In_ int, _In_ HICON)
Definition: cursoricon.c:2370
HICON WINAPI CopyIcon(_In_ HICON)
Definition: cursoricon.c:2363
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE hInst, _In_ LPCWSTR name, _In_ UINT type, _In_ int cx, _In_ int cy, _In_ UINT fuLoad)
Definition: cursoricon.c:2555
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2290
#define LR_SHARED
Definition: winuser.h:1111
#define IMAGE_CURSOR
Definition: winuser.h:213
#define LR_DEFAULTSIZE
Definition: winuser.h:1105
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2405

◆ test_LoadIcon_SystemIds()

static void test_LoadIcon_SystemIds ( void  )
static

Definition at line 48 of file LoadImage.c.

49{
50 static const WORD icomap[][2] = {
51 { 100, (WORD)(SIZE_T)IDI_APPLICATION },
52 { 101, (WORD)(SIZE_T)IDI_WARNING },
53 { 102, (WORD)(SIZE_T)IDI_QUESTION },
54 { 103, (WORD)(SIZE_T)IDI_ERROR },
55 { 104, (WORD)(SIZE_T)IDI_INFORMATION },
56 { 105, (WORD)(SIZE_T)IDI_WINLOGO }
57 };
59 typedef BOOL (WINAPI*SHAIE)(HICON, HICON);
60 SHAIE pfnSHAreIconsEqual;
61 HMODULE hSHLWAPI = LoadLibraryA("SHLWAPI");
62 if (!hSHLWAPI)
63 {
64 skip("Could not initialize\n");
65 return;
66 }
67 pfnSHAreIconsEqual = (SHAIE)GetProcAddress(hSHLWAPI, MAKEINTRESOURCEA(548));
68 if (!pfnSHAreIconsEqual)
69 {
70 FreeLibrary(hSHLWAPI);
71 skip("Could not initialize\n");
72 return;
73 }
74
75 for (UINT i = 0; i < _countof(icomap); i++)
76 {
77 HICON hIcoRes = LoadIconW(hInst, MAKEINTRESOURCEW(icomap[i][0]));
78 HICON hIcoSys = LoadIconW(NULL, MAKEINTRESOURCEW(icomap[i][1]));
79 ok(hIcoRes && pfnSHAreIconsEqual(hIcoRes, hIcoSys), "SysIcon %d must be resource %d\n", icomap[i][1], icomap[i][0]);
80 }
81 FreeLibrary(hSHLWAPI);
82}
#define skip(...)
Definition: atltest.h:64
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned short WORD
Definition: ntddk_ex.h:93
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
#define BOOL
Definition: nt_native.h:43
#define _countof(array)
Definition: sndvol32.h:70
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define WINAPI
Definition: msvc.h:6
#define IDI_WARNING
Definition: winuser.h:729
#define IDI_QUESTION
Definition: winuser.h:714
#define IDI_ERROR
Definition: winuser.h:730
#define IDI_WINLOGO
Definition: winuser.h:717
#define IDI_APPLICATION
Definition: winuser.h:712
#define IDI_INFORMATION
Definition: winuser.h:731
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2427

Referenced by START_TEST().

◆ test_LoadImage_DataFile()

static void test_LoadImage_DataFile ( void  )
static

Definition at line 4 of file LoadImage.c.

5{
6 static const struct
7 {
8 int result;
10 int res_id;
11 UINT lr;
12 BOOL same_handle;
13 BOOL after_unload; /* LR_SHARED stays valid */
14 }
15 tests[] =
16 {
17 { 1, L"shell32.dll", 2, 0, 0, 0 },
18 { 1, L"shell32.dll", 2, LR_SHARED, 1, 1 },
19 { 0, L"shell32.dll", 0xfff0, 0, 1, 0 }, /* Icon should not exist */
20 { 1, L"regedit.exe", 100, 0, 0, 0 },
21 { 1, L"regedit.exe", 100, LR_SHARED, 1, 1 }
22 };
23
24 SIZE_T i;
25 for (i = 0; i < ARRAY_SIZE(tests); ++i)
26 {
27 HANDLE handle1, handle2;
29 if (!((SIZE_T)hMod & 3))
30 {
31 skip("Could not load library as datafile %ls\n", tests[i].file);
32 continue;
33 }
34
35 handle1 = LoadImage(hMod, MAKEINTRESOURCE(tests[i].res_id), IMAGE_ICON, 0, 0, tests[i].lr);
36 ok(!!handle1 == !!tests[i].result, "Failed to load %ls,-%d from %p\n", tests[i].file, tests[i].res_id, hMod);
37
38 handle2 = LoadImage(hMod, MAKEINTRESOURCE(tests[i].res_id), IMAGE_ICON, 0, 0, tests[i].lr);
39 ok(!!(handle1 == handle2) == !!tests[i].same_handle, "Shared handles don't match\n");
40
41 FreeLibrary(hMod);
42
43 handle1 = LoadImage(hMod, MAKEINTRESOURCE(tests[i].res_id), IMAGE_ICON, 0, 0, tests[i].lr);
44 ok(!!handle1 == !!tests[i].after_unload, "LR_%x handle should %sload after FreeLibrary\n", tests[i].lr, tests[i].after_unload ? "" : "not ");
45 }
46}
#define ARRAY_SIZE(A)
Definition: main.h:20
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint64EXT * result
Definition: glext.h:11304
static struct test_info tests[]
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
Definition: fci.c:127
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:375
#define IMAGE_ICON
Definition: winuser.h:212
#define LoadImage
Definition: winuser.h:5926
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by START_TEST().