2017-02-06 16:33:25 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS api tests
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Test for RegisterClassEx
|
|
|
|
* PROGRAMMERS: Giannis Adamopoulos
|
|
|
|
*/
|
|
|
|
|
2017-12-02 20:17:22 +00:00
|
|
|
#include "precomp.h"
|
2017-02-06 16:33:25 +00:00
|
|
|
|
|
|
|
static ATOM _RegisterClass(LPCWSTR lpwszClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
|
|
|
|
{
|
|
|
|
WNDCLASSEXW wcex = {sizeof(WNDCLASSEXW), style, lpfnWndProc};
|
|
|
|
wcex.lpszClassName = lpwszClassName;
|
|
|
|
wcex.hInstance = hInstance;
|
|
|
|
return RegisterClassExW(&wcex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ATOM _GetClassAtom(LPCWSTR lpwszClassName, HINSTANCE hInstance)
|
|
|
|
{
|
|
|
|
WNDCLASSEXW wcex = {sizeof(WNDCLASSEXW)};
|
2017-02-11 10:01:13 +00:00
|
|
|
return (ATOM)GetClassInfoExW(hInstance, lpwszClassName, &wcex);
|
2017-02-06 16:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static WNDPROC _GetWndproc(LPCWSTR lpwszClassName, HINSTANCE hInstance)
|
|
|
|
{
|
|
|
|
WNDCLASSEXW wcex = {sizeof(WNDCLASSEXW)};
|
2017-02-11 10:01:13 +00:00
|
|
|
BOOL ret = GetClassInfoExW(hInstance, lpwszClassName, &wcex);
|
|
|
|
return ret ? wcex.lpfnWndProc : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ATOM _RegisterClassA(LPCSTR lpzClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
|
|
|
|
{
|
|
|
|
WNDCLASSEXA wcex = {sizeof(WNDCLASSEX), style, lpfnWndProc};
|
|
|
|
wcex.lpszClassName = lpzClassName;
|
|
|
|
wcex.hInstance = hInstance;
|
|
|
|
return RegisterClassExA(&wcex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ATOM _GetClassAtomA(LPCSTR lpszClassName, HINSTANCE hInstance)
|
|
|
|
{
|
|
|
|
WNDCLASSEXA wcex = {sizeof(WNDCLASSEX)};
|
|
|
|
return (ATOM)GetClassInfoExA(hInstance, lpszClassName, &wcex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static WNDPROC _GetWndprocA(LPCSTR lpszClassName, HINSTANCE hInstance)
|
|
|
|
{
|
|
|
|
WNDCLASSEXA wcex = {sizeof(WNDCLASSEX)};
|
|
|
|
BOOL ret = GetClassInfoExA(hInstance, lpszClassName, &wcex);
|
|
|
|
return ret ? wcex.lpfnWndProc : NULL;
|
2017-02-06 16:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE _CreateActCtxFromFile(LPCWSTR FileName)
|
|
|
|
{
|
|
|
|
ACTCTXW ActCtx = {sizeof(ACTCTX)};
|
|
|
|
WCHAR buffer[MAX_PATH] , *separator;
|
|
|
|
|
|
|
|
ok (GetModuleFileNameW(NULL, buffer, MAX_PATH), "GetModuleFileName failed\n");
|
|
|
|
separator = wcsrchr(buffer, L'\\');
|
|
|
|
if (separator)
|
|
|
|
wcscpy(separator + 1, FileName);
|
|
|
|
|
|
|
|
ActCtx.lpSource = buffer;
|
|
|
|
|
|
|
|
return CreateActCtxW(&ActCtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID TestGlobalClasses(VOID)
|
|
|
|
{
|
|
|
|
HMODULE hmod = GetModuleHandle(NULL);
|
|
|
|
ATOM a,b,c,d,e;
|
|
|
|
|
|
|
|
a = _GetClassAtom(L"TestClass1", hmod);
|
|
|
|
b = _RegisterClass(L"TestClass1", hmod, 0, DefWindowProcW);
|
|
|
|
c = _GetClassAtom(L"TestClass1", hmod);
|
2017-03-15 00:06:42 +00:00
|
|
|
UnregisterClassW(L"TestClass1", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
d = _GetClassAtom(L"TestClass1", hmod);
|
|
|
|
ok( a == 0, "\n");
|
|
|
|
ok( b != 0, "\n");
|
|
|
|
ok( c != 0, "\n");
|
|
|
|
ok( d == 0, "\n");
|
|
|
|
ok (b == c, "\n");
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2017-02-06 16:33:25 +00:00
|
|
|
a = _GetClassAtom(L"TestClass2", hmod);
|
|
|
|
b = _RegisterClass(L"TestClass2", hmod, CS_GLOBALCLASS, DefWindowProcW);
|
|
|
|
c = _GetClassAtom(L"TestClass2", hmod);
|
2017-03-15 00:06:42 +00:00
|
|
|
UnregisterClassW(L"TestClass2", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
d = _GetClassAtom(L"TestClass2", hmod);
|
|
|
|
ok( a == 0, "\n");
|
|
|
|
ok( b != 0, "\n");
|
|
|
|
ok( c != 0, "\n");
|
|
|
|
ok( d == 0, "\n");
|
|
|
|
ok (b == c, "\n");
|
|
|
|
|
|
|
|
a = _RegisterClass(L"TestClass3", hmod, 0, DefWindowProcW);
|
|
|
|
b = _RegisterClass(L"TestClass3", hmod, 0, DefWindowProcW);
|
|
|
|
c = _RegisterClass(L"TestClass3", hmod, CS_GLOBALCLASS, DefWindowProcW);
|
2017-03-15 00:06:42 +00:00
|
|
|
UnregisterClassW(L"TestClass3", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
d = _GetClassAtom(L"TestClass3", hmod);
|
|
|
|
ok( a != 0, "\n");
|
|
|
|
ok( b == 0, "\n");
|
|
|
|
ok( c == 0, "\n");
|
|
|
|
ok( d == 0, "\n");
|
|
|
|
|
|
|
|
a = _RegisterClass(L"TestClass4", hmod, CS_GLOBALCLASS, DefWindowProcW);
|
|
|
|
b = _RegisterClass(L"TestClass4", hmod, 0, DefWindowProcW);
|
|
|
|
c = _RegisterClass(L"TestClass4", hmod, 0, DefWindowProcW);
|
2017-03-15 00:06:42 +00:00
|
|
|
UnregisterClassW(L"TestClass4", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
d = _GetClassAtom(L"TestClass4", hmod);
|
2017-03-15 00:06:42 +00:00
|
|
|
UnregisterClassW(L"TestClass4", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
e = _GetClassAtom(L"TestClass4", hmod);
|
|
|
|
ok( a != 0, "\n");
|
|
|
|
ok( b != 0, "\n");
|
|
|
|
ok( c == 0, "\n");
|
|
|
|
ok( d != 0, "\n");
|
|
|
|
ok( e == 0, "\n");
|
|
|
|
|
|
|
|
a = _GetClassAtom(L"ComboBox", hmod);
|
|
|
|
b = _RegisterClass(L"ComboBox", hmod, 0, DefWindowProcW);
|
|
|
|
c = _RegisterClass(L"ComboBox", hmod, CS_GLOBALCLASS, DefWindowProcW);
|
2017-03-15 00:06:42 +00:00
|
|
|
UnregisterClassW(L"ComboBox", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
d = _GetClassAtom(L"ComboBox", hmod);
|
2017-03-15 00:06:42 +00:00
|
|
|
UnregisterClassW(L"TestClass4", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
e = _GetClassAtom(L"TestClass4", hmod);
|
|
|
|
ok( a != 0, "\n");
|
|
|
|
ok( b != 0, "\n");
|
|
|
|
ok( c == 0, "\n");
|
|
|
|
ok( d != 0, "\n");
|
|
|
|
ok( e == 0, "\n");
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2017-02-06 16:33:25 +00:00
|
|
|
a = _GetClassAtom(L"ScrollBar", hmod);
|
2017-03-15 00:06:42 +00:00
|
|
|
UnregisterClassW(L"ScrollBar", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
b = _GetClassAtom(L"ScrollBar", hmod);
|
2017-02-07 12:11:26 +00:00
|
|
|
c = _RegisterClass(L"ScrollBar", hmod, CS_GLOBALCLASS, DefWindowProcW);
|
|
|
|
d = _GetClassAtom(L"ScrollBar", hmod);
|
2019-12-09 16:16:02 +00:00
|
|
|
ok( a != 0, "Wrong value for a. Expected != 0, got 0\n");
|
|
|
|
ok( b == 0, "Wrong value for b. Expected == 0, got %d\n", b);
|
|
|
|
//ok( c != 0, "Wrong value for c. Expected != 0, got 0\n");
|
|
|
|
//ok( d != 0, "Wrong value for d. Expected != 0, got 0\n");
|
|
|
|
//ok_int(a, c);
|
|
|
|
//ok_int(a, d); /* In Windows 10 and WHS testbot the last 4 tests fail */
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2017-02-06 16:33:25 +00:00
|
|
|
a = _GetClassAtom(L"ListBox", (HMODULE)0xdead);
|
2017-03-15 00:06:42 +00:00
|
|
|
UnregisterClassW(L"ListBox", (HMODULE)0xdead);
|
2017-02-06 16:33:25 +00:00
|
|
|
b = _GetClassAtom(L"ListBox", (HMODULE)0xdead);
|
|
|
|
ok( a != 0, "\n");
|
|
|
|
ok( b == 0, "\n");
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2017-02-06 16:33:25 +00:00
|
|
|
a = _RegisterClass(L"TestClass5", (HMODULE)0xdead, CS_GLOBALCLASS, DefWindowProcW);
|
|
|
|
b = _GetClassAtom(L"TestClass5", hmod);
|
2017-03-15 00:06:42 +00:00
|
|
|
UnregisterClassW(L"TestClass5", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
c = _GetClassAtom(L"TestClass5", (HMODULE)0xdead);
|
|
|
|
d = _GetClassAtom(L"TestClass5", hmod);
|
|
|
|
ok( a != 0, "\n");
|
2021-09-13 01:33:14 +00:00
|
|
|
ok( b != 0, "\n");
|
2017-02-06 16:33:25 +00:00
|
|
|
ok( c == 0, "\n");
|
2021-09-13 01:33:14 +00:00
|
|
|
ok( d == 0, "\n");
|
2017-02-06 16:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID TestVersionedClasses(VOID)
|
|
|
|
{
|
|
|
|
HMODULE hmod = GetModuleHandle(NULL);
|
|
|
|
HANDLE h1, h2;
|
2017-02-11 10:01:13 +00:00
|
|
|
ULONG_PTR cookie1, cookie2;
|
|
|
|
ATOM a,b,c,d;
|
2017-02-07 12:11:26 +00:00
|
|
|
WNDPROC proc1,proc2,proc3, proc4, proc5;
|
2017-02-11 10:01:13 +00:00
|
|
|
WCHAR buffer[50];
|
|
|
|
|
2017-02-06 16:33:25 +00:00
|
|
|
|
|
|
|
h1 = _CreateActCtxFromFile(L"verclasstest1.manifest");
|
|
|
|
h2 = _CreateActCtxFromFile(L"verclasstest2.manifest");
|
|
|
|
if (h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
skip("Loading manifests failed. Skipping TestVersionedClasses\n");
|
|
|
|
return;
|
|
|
|
}
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2017-02-06 16:33:25 +00:00
|
|
|
a = _RegisterClass(L"VersionTestClass1", hmod, 0, DefWindowProcA);
|
|
|
|
proc1 = _GetWndproc(L"VersionTestClass1", hmod);
|
|
|
|
b = _RegisterClass(L"VersionTestClass1", hmod, 0, DefWindowProcW);
|
|
|
|
ActivateActCtx(h1, &cookie1);
|
|
|
|
proc2 = _GetWndproc(L"VersionTestClass1", hmod);
|
|
|
|
c = _RegisterClass(L"VersionTestClass1", hmod, 0, DefWindowProcW);
|
2017-02-13 09:58:06 +00:00
|
|
|
d = _GetClassAtom(L"VersionTestClass1", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
proc3 = _GetWndproc(L"VersionTestClass1", hmod);
|
2017-02-07 12:11:26 +00:00
|
|
|
proc4 = _GetWndproc((LPCWSTR)(DWORD_PTR)a, hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
DeactivateActCtx(0, cookie1);
|
2017-02-07 12:11:26 +00:00
|
|
|
proc5 = _GetWndproc(L"VersionTestClass1", hmod);
|
2017-02-06 16:33:25 +00:00
|
|
|
ok( a != 0, "\n");
|
|
|
|
ok( b == 0, "\n");
|
|
|
|
ok( c != 0, "\n");
|
2017-02-13 09:58:06 +00:00
|
|
|
ok( d != 0, "\n");
|
2017-02-06 16:33:25 +00:00
|
|
|
ok( a == c, "\n");
|
2017-02-13 09:58:06 +00:00
|
|
|
ok( a == d, "\n");
|
2017-02-06 16:33:25 +00:00
|
|
|
ok (proc1 == DefWindowProcA, "\n");
|
2017-02-11 10:01:13 +00:00
|
|
|
ok (proc2 == NULL, "Got 0x%p, expected NULL\n", proc2);
|
|
|
|
ok (proc3 == DefWindowProcW, "Got 0x%p, expected 0x%p\n", proc3, DefWindowProcW);
|
|
|
|
ok (proc4 == DefWindowProcW, "Got 0x%p, expected 0x%p\n", proc4, DefWindowProcW);
|
2017-02-07 12:11:26 +00:00
|
|
|
ok (proc5 == DefWindowProcA, "\n");
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2017-02-06 16:33:25 +00:00
|
|
|
a = _GetClassAtom(L"Button", hmod);
|
|
|
|
b = _RegisterClass(L"Button", hmod, CS_GLOBALCLASS, DefWindowProcA);
|
|
|
|
proc1 = _GetWndproc(L"Button", (HMODULE)0xdead);
|
|
|
|
ActivateActCtx(h2, &cookie1);
|
|
|
|
c = _RegisterClass(L"Button", hmod, CS_GLOBALCLASS, DefWindowProcA);
|
|
|
|
proc2 = _GetWndproc(L"Button", (HMODULE)0xdead);
|
2017-02-11 10:01:13 +00:00
|
|
|
d = _GetClassAtom(L"3.3.3.3!Button", (HMODULE)0xdead);
|
|
|
|
proc3 = _GetWndproc(L"3.3.3.3!Button", (HMODULE)0xdead);
|
2017-02-06 16:33:25 +00:00
|
|
|
ok( a != 0, "\n");
|
|
|
|
ok( b == 0, "\n");
|
|
|
|
ok( c != 0, "\n");
|
2017-02-11 10:01:13 +00:00
|
|
|
ok( d != 0, "\n");
|
2017-02-06 16:33:25 +00:00
|
|
|
ok( a == c, "\n");
|
2017-02-11 10:01:13 +00:00
|
|
|
ok( d == a, "\n");
|
2017-02-06 16:33:25 +00:00
|
|
|
ok( proc1 != NULL, "\n");
|
2017-02-11 10:01:13 +00:00
|
|
|
ok( proc1 != DefWindowProcA, "Got 0x%p, expected not 0x%p\n", proc1, DefWindowProcA);
|
|
|
|
ok( proc2 == DefWindowProcA, "Got 0x%p, expected 0x%p\n", proc2, DefWindowProcA);
|
|
|
|
ok( proc3 == DefWindowProcA, "Got 0x%p, expected 0x%p\n", proc3, DefWindowProcA);
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2017-02-07 12:11:26 +00:00
|
|
|
a = _RegisterClass(L"VersionTestClass2", hmod, CS_GLOBALCLASS, DefWindowProcW);
|
|
|
|
proc1 = _GetWndproc(L"VersionTestClass2", (HMODULE)0xdead);
|
|
|
|
b = _RegisterClass(L"VersionTestClass2", hmod, 0, DefWindowProcA);
|
|
|
|
proc2 = _GetWndproc(L"VersionTestClass2", hmod);
|
2017-02-11 10:01:13 +00:00
|
|
|
proc3 = _GetWndproc(L"VersionTestClass2", (HMODULE)0xdead);
|
2017-02-07 12:11:26 +00:00
|
|
|
ok (a != 0, "\n");
|
|
|
|
ok (b != 0, "\n");
|
|
|
|
ok (a == b, "\n");
|
2017-02-11 10:01:13 +00:00
|
|
|
ok (proc1 == DefWindowProcW, "Got 0x%p, expected 0x%p\n", proc1, DefWindowProcW);
|
|
|
|
ok (proc2 == DefWindowProcA, "Got 0x%p, expected 0x%p\n", proc2, DefWindowProcA);
|
|
|
|
ok (proc3 == DefWindowProcW, "Got 0x%p, expected 0x%p\n", proc2, DefWindowProcA);
|
|
|
|
|
|
|
|
a = _RegisterClass(L"VersionTestClass3", hmod, 0, DefWindowProcW);
|
|
|
|
swprintf(buffer, L"#%d", a);
|
|
|
|
proc1 = _GetWndproc((LPCWSTR)(DWORD_PTR)a, hmod);
|
|
|
|
proc2 = _GetWndproc(buffer, hmod);
|
|
|
|
ok (a != 0, "\n");
|
2017-02-07 12:11:26 +00:00
|
|
|
ok (proc1 == DefWindowProcW, "\n");
|
2017-02-11 10:01:13 +00:00
|
|
|
ok (proc2 == 0, "Got 0x%p for %S, expected 0\n", proc2, buffer);
|
|
|
|
DeactivateActCtx(0, cookie1);
|
|
|
|
|
|
|
|
a = _RegisterClass(L"VersionTestClass3", hmod, 0, DefWindowProcW);
|
|
|
|
swprintf(buffer, L"#%d", a);
|
|
|
|
proc1 = _GetWndproc((LPCWSTR)(DWORD_PTR)a, hmod);
|
|
|
|
proc2 = _GetWndproc(buffer, hmod);
|
|
|
|
ok (a != 0, "\n");
|
|
|
|
ok (proc1 == DefWindowProcW, "\n");
|
|
|
|
ok (proc2 == 0, "Got 0x%p for %S, expected 0\n", proc2, buffer);
|
|
|
|
|
|
|
|
ActivateActCtx(h2, &cookie1);
|
|
|
|
a = _RegisterClassA("VersionTestClass7", hmod, 0, DefWindowProcW);
|
|
|
|
b = _GetClassAtomA("VersionTestClass7", hmod);
|
|
|
|
proc1 = _GetWndprocA("VersionTestClass7", hmod);
|
|
|
|
proc2 = _GetWndprocA((LPCSTR)(DWORD_PTR)a, hmod);
|
|
|
|
ok(a != 0, "\n");
|
|
|
|
ok(b != 0, "\n");
|
|
|
|
ok(a == b, "\n");
|
|
|
|
ok (proc1 == DefWindowProcW, "\n");
|
|
|
|
ok (proc2 == DefWindowProcW, "\n");
|
|
|
|
|
|
|
|
DeactivateActCtx(0, cookie1);
|
|
|
|
|
|
|
|
proc1 = _GetWndproc(L"Button", 0);
|
|
|
|
ActivateActCtx(h2, &cookie1);
|
|
|
|
ActivateActCtx(h1, &cookie2);
|
|
|
|
proc2 = _GetWndproc(L"Button", 0);
|
|
|
|
DeactivateActCtx(0, cookie2);
|
|
|
|
ActivateActCtx(0, &cookie2);
|
|
|
|
proc3 = _GetWndproc(L"Button", 0);
|
|
|
|
DeactivateActCtx(0, cookie2);
|
|
|
|
DeactivateActCtx(0, cookie1);
|
|
|
|
ok (proc1 != 0, "\n");
|
|
|
|
ok (proc2 != 0, "\n");
|
|
|
|
ok (proc4 != 0, "\n");
|
|
|
|
ok (proc1 == proc2, "\n");
|
|
|
|
ok (proc1 == proc3, "\n");
|
|
|
|
|
2017-02-06 16:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(RegisterClassEx)
|
|
|
|
{
|
|
|
|
TestGlobalClasses();
|
|
|
|
TestVersionedClasses();
|
|
|
|
}
|