[MSGINA_APITEST] Add a test for ShellDimScreen, used to fade out the background of...
[reactos.git] / rostests / apitests / msgina / ShellDimScreen.cpp
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for ShellDimScreen
5 * PROGRAMMER: Mark Jansen
6 */
7
8 #include <apitest.h>
9 #include <atlbase.h>
10 #include <atlcom.h>
11
12 #define INITGUID
13 #include <guiddef.h>
14 // stolen from com_apitest.h
15 DEFINE_GUID(CLSID_FadeTask, 0x7EB5FBE4, 0x2100, 0x49E6, 0x85, 0x93, 0x17, 0xE1, 0x30, 0x12, 0x2F, 0x91);
16
17
18 typedef HRESULT (__stdcall *tShellDimScreen) (IUnknown** Unknown, HWND* hWindow);
19
20 tShellDimScreen ShellDimScreen;
21
22 static void Test_Dim()
23 {
24 IUnknown* unk = (IUnknown*)0xdeadbeef;
25 HWND wnd = (HWND)0xdeadbeef;
26 ULONG count;
27
28 HRESULT hr = ShellDimScreen(NULL, NULL);
29 ok_hex(hr, E_INVALIDARG);
30
31 hr = ShellDimScreen(&unk, &wnd);
32 ok_hex(hr, S_OK);
33 ok(unk != ((IUnknown*)0xdeadbeef), "Expected a valid object\n");
34 ok(wnd != ((HWND)0xdeadbeef), "Expected a valid window ptr\n");
35 ok(IsWindow(wnd), "Expected a valid window\n");
36 ok(IsWindowVisible(wnd), "Expected the window to be visible\n");
37
38 if (unk != ((IUnknown*)0xdeadbeef) && unk)
39 {
40 count = unk->Release();
41 ok(count == 0, "Expected count to be 0, was: %lu\n", count);
42 ok(!IsWindow(wnd), "Expected the window to be destroyed\n");
43 }
44
45 unk = (IUnknown*)0xdeadbeef;
46 wnd = (HWND)0xdeadbeef;
47 hr = ShellDimScreen(&unk, &wnd);
48 ok_hex(hr, S_OK);
49 ok(unk != ((IUnknown*)0xdeadbeef), "Expected a valid object\n");
50 ok(wnd != ((HWND)0xdeadbeef), "Expected a valid window ptr\n");
51 ok(IsWindow(wnd), "Expected a valid window\n");
52 ok(IsWindowVisible(wnd), "Expected the window to be visible\n");
53 char classname[100] = {0};;
54 int nRet = GetClassNameA(wnd, classname, 100);
55 ok(nRet == 17, "Expected GetClassName to return 3 was %i\n", nRet);
56 ok(!strcmp(classname, "DimmedWindowClass"), "Expected classname to be DimmedWindowClass, was %s\n", classname);
57 LONG style = GetWindowLong(wnd, GWL_STYLE);
58 LONG expectedstyle = WS_POPUP | WS_VISIBLE | WS_DISABLED | WS_CLIPSIBLINGS;
59 ok(style == expectedstyle, "Expected style to be %lx, was %lx\n", expectedstyle, style);
60 style = GetWindowLong(wnd, GWL_EXSTYLE);
61 ok(style == WS_EX_TOPMOST, "Expected exstyle to be %x, was %lx\n", WS_EX_TOPMOST, style);
62
63 if (unk != ((IUnknown*)0xdeadbeef) && unk)
64 {
65 count = unk->AddRef();
66 ok(count == 2, "Expected count to be 2, was: %lu\n", count);
67 count = unk->Release();
68 ok(count == 1, "Expected count to be 1, was: %lu\n", count);
69
70 IUnknown* unk2;
71 hr = unk->QueryInterface(IID_IUnknown, (void**)&unk2);
72 ok_hex(hr, S_OK);
73 if (SUCCEEDED(hr))
74 {
75 ok(unk2 == unk, "Expected the object to be the same, was: %p, %p\n", unk, unk2);
76 unk2->Release();
77 }
78 hr = unk->QueryInterface(CLSID_FadeTask, (void**)&unk2);
79 ok_hex(hr, E_NOINTERFACE);
80 if (SUCCEEDED(hr))
81 {
82 ok(unk2 == unk, "Expected the object to be the same, was: %p, %p\n", unk, unk2);
83 unk2->Release();
84 }
85 }
86
87 RECT rc;
88 GetWindowRect(wnd, &rc);
89
90 ok(rc.left == GetSystemMetrics(SM_XVIRTUALSCREEN), "Expected rc.left to be %u, was %lu\n", GetSystemMetrics(SM_XVIRTUALSCREEN), rc.left);
91 ok(rc.top == GetSystemMetrics(SM_YVIRTUALSCREEN), "Expected rc.top to be %u, was %lu\n", GetSystemMetrics(SM_YVIRTUALSCREEN), rc.top);
92 ok((rc.right - rc.left) == GetSystemMetrics(SM_CXVIRTUALSCREEN), "Expected rc.left to be %u, was %lu\n", GetSystemMetrics(SM_CXVIRTUALSCREEN), (rc.right - rc.left));
93 ok((rc.bottom - rc.top) == GetSystemMetrics(SM_CYVIRTUALSCREEN), "Expected rc.top to be %u, was %lu\n", GetSystemMetrics(SM_CYVIRTUALSCREEN), (rc.bottom - rc.top));
94
95 if (unk != ((IUnknown*)0xdeadbeef) && unk)
96 {
97 count = unk->Release();
98 ok(count == 0, "Expected count to be 0, was: %lu\n", count);
99 ok(!IsWindow(wnd), "Expected the window to be destroyed\n");
100 }
101 }
102
103
104 START_TEST(ShellDimScreen)
105 {
106 HMODULE dll = LoadLibraryA("msgina.dll");
107 ShellDimScreen = (tShellDimScreen)GetProcAddress(dll, MAKEINTRESOURCEA(16));
108 if (!dll || !ShellDimScreen)
109 {
110 skip("msgina!#16 not found, skipping tests\n");
111 return;
112 }
113 Test_Dim();
114 }