ReactOS 0.4.15-dev-8344-g0574987
LoadImage.c
Go to the documentation of this file.
1
2#include "precomp.h"
3
4static void test_LoadImage_DataFile(void)
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}
47
49{
50 char path[MAX_PATH];
52 STARTUPINFO si;
54
55 char **test_argv;
57
58 /* Now check its behaviour regarding Shared icons/cursors */
60 ok(handle != 0, "\n");
61
62 if (argc >= 3)
63 {
64 HANDLE arg;
65 HICON hCopy;
67 HDC hdc, hdcScreen;
68 ICONINFO ii;
69
70 sscanf (test_argv[2], "%Iu", (ULONG_PTR*) &arg);
71
72 ok(handle != arg, "Got same handles\n");
73
74 /* Try copying it */
75 hCopy = CopyIcon(arg);
76 ok(hCopy != NULL, "\n");
77 ok(DestroyIcon(hCopy), "\n");
78
79 hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, 0);
80 ok(hCopy != NULL, "\n");
81 ok(DestroyIcon(hCopy), "\n");
82 /* Unlike the original, this one is not shared */
83 ok(!DestroyIcon(hCopy), "\n");
84
86 ok(hCopy != NULL, "\n");
87 ok(DestroyIcon(hCopy), "\n");
88 /* Unlike the original, this one is not shared */
89 ok(!DestroyIcon(hCopy), "\n");
90
92 ok(hCopy != NULL, "\n");
93 ok(DestroyIcon(hCopy), "\n");
94 /* This one is shared */
95 ok(DestroyIcon(hCopy), "\n");
96
97 hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, LR_SHARED);
98 ok(hCopy != NULL, "\n");
99 ok(DestroyIcon(hCopy), "DestroyIcon should succeed.\n");
100 /* This one is shared */
101 ok(DestroyIcon(hCopy) == 0, "DestroyIcon should fail.\n");
102
103 /* Try various usual functions */
104 hdcScreen = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
105 ok(hdcScreen != NULL, "\n");
106 hdc = CreateCompatibleDC(hdcScreen);
107 ok(hdc != NULL, "\n");
108 hbmp = CreateCompatibleBitmap(hdcScreen, 64, 64);
109 ok(hbmp != NULL, "\n");
111 ok(hbmp != NULL, "\n");
112
113 ok(DrawIcon(hdc, 0, 0, arg), "\n");
116 DeleteDC(hdc);
117 DeleteDC(hdcScreen);
118
119 ok(GetIconInfo(arg, &ii), "\n");
120 ok(ii.hbmMask != NULL, "\n");
122 if(ii.hbmColor) DeleteObject(ii.hbmColor);
123
124 /* LOAD_LIBRARY_AS_DATAFILE */
126
127 return;
128 }
129
130 /* Start child process */
131 sprintf( path, "%s LoadImage %Iu", test_argv[0], (ULONG_PTR)handle );
132 memset( &si, 0, sizeof(si) );
133 si.cb = sizeof(si);
134 CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi );
135 WaitForSingleObject (pi.hProcess, INFINITE);
136}
static void test_LoadImage_DataFile(void)
Definition: LoadImage.c:4
static int argc
Definition: ServiceArgs.c:12
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(A)
Definition: main.h:33
HBITMAP hbmp
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
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:4741
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
GLuint64EXT * result
Definition: glext.h:11304
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
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
static struct test_info tests[]
#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:92
static HICON
Definition: imagelist.c:84
static refpint_t pi[]
Definition: server.c:96
static char ** test_argv
Definition: cursoricon.c:296
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
int winetest_get_mainargs(char ***pargv)
#define memset(x, y, z)
Definition: compat.h:39
HBITMAP hbmColor
Definition: winuser.h:3127
HBITMAP hbmMask
Definition: winuser.h:3126
DWORD cb
Definition: winbase.h:831
Definition: fci.c:127
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:342
#define GetModuleHandle
Definition: winbase.h:3827
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)
#define IMAGE_ICON
Definition: winuser.h:212
BOOL WINAPI GetIconInfo(_In_ HICON, _Out_ PICONINFO)
Definition: cursoricon.c:2089
#define LR_COPYFROMRESOURCE
Definition: winuser.h:1099
BOOL WINAPI DrawIcon(_In_ HDC, _In_ int, _In_ int, _In_ HICON)
Definition: cursoricon.c:2062
HICON WINAPI CopyIcon(_In_ HICON)
Definition: cursoricon.c:2055
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:2247
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2024
#define LR_SHARED
Definition: winuser.h:1100
#define LoadImage
Definition: winuser.h:5824
#define IMAGE_CURSOR
Definition: winuser.h:213
#define LR_DEFAULTSIZE
Definition: winuser.h:1094
#define MAKEINTRESOURCE
Definition: winuser.h:591
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2097
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185