[WIN32K:NTUSER]
[reactos.git] / rostests / apitests / user32 / GetWindowPlacement.c
1 /*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for GetWindowPlacement
5 * PROGRAMMERS: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <apitest.h>
9 #include <winuser.h>
10
11 #define ALIGN_DOWN_BY(size, align) \
12 ((ULONG_PTR)(size) & ~((ULONG_PTR)(align) - 1))
13
14 #define ALIGN_UP_BY(size, align) \
15 (ALIGN_DOWN_BY(((ULONG_PTR)(size) + align - 1), align))
16
17 START_TEST(GetWindowPlacement)
18 {
19 BYTE buffer[sizeof(WINDOWPLACEMENT) + 16];
20 PWINDOWPLACEMENT wp = (PVOID)buffer;
21 DWORD error;
22 BOOL ret;
23
24 SetLastError(0xfeedfab1);
25 ret = GetWindowPlacement(NULL, NULL);
26 error = GetLastError();
27 ok(ret == FALSE, "ret = %d\n", ret);
28 ok(error == ERROR_INVALID_WINDOW_HANDLE, "error = %lu\n", error);
29
30 SetLastError(0xfeedfab1);
31 ret = GetWindowPlacement(GetDesktopWindow(), NULL);
32 error = GetLastError();
33 ok(ret == FALSE, "ret = %d\n", ret);
34 ok(error == ERROR_NOACCESS, "error = %lu\n", error);
35
36 SetLastError(0xfeedfab1);
37 ret = GetWindowPlacement(GetDesktopWindow(), (PVOID)(UINT_PTR)-4);
38 error = GetLastError();
39 ok(ret == FALSE, "ret = %d\n", ret);
40 ok(error == ERROR_NOACCESS, "error = %lu\n", error);
41
42 FillMemory(buffer, sizeof(buffer), 0x55);
43 SetLastError(0xfeedfab1);
44 ret = GetWindowPlacement(GetDesktopWindow(), (PVOID)(ALIGN_UP_BY(buffer, 16) + 1));
45 error = GetLastError();
46 ok(ret == TRUE, "ret = %d\n", ret);
47 ok(error == 0xfeedfab1, "error = %lu\n", error);
48
49 FillMemory(wp, sizeof(*wp), 0x55);
50 wp->length = 0;
51 SetLastError(0xfeedfab1);
52 ret = GetWindowPlacement(NULL, wp);
53 error = GetLastError();
54 ok(ret == FALSE, "ret = %d\n", ret);
55 ok(error == ERROR_INVALID_WINDOW_HANDLE, "error = %lu\n", error);
56 ok(wp->length == 0, "wp.length = %u\n", wp->length);
57
58 FillMemory(wp, sizeof(*wp), 0x55);
59 wp->length = 0;
60 SetLastError(0xfeedfab1);
61 ret = GetWindowPlacement(GetDesktopWindow(), wp);
62 error = GetLastError();
63 ok(ret == TRUE, "ret = %d\n", ret);
64 ok(error == 0xfeedfab1, "error = %lu\n", error);
65 ok(wp->length == sizeof(*wp), "wp.length = %u\n", wp->length);
66 ok(wp->flags == 0, "wp.flags = %x\n", wp->flags);
67
68 FillMemory(wp, sizeof(*wp), 0x55);
69 wp->length = 1;
70 SetLastError(0xfeedfab1);
71 ret = GetWindowPlacement(GetDesktopWindow(), wp);
72 error = GetLastError();
73 ok(ret == TRUE, "ret = %d\n", ret);
74 ok(error == 0xfeedfab1, "error = %lu\n", error);
75 ok(wp->length == sizeof(*wp), "wp.length = %u\n", wp->length);
76 ok(wp->flags == 0, "wp.flags = %x\n", wp->flags);
77
78 FillMemory(wp, sizeof(*wp), 0x55);
79 wp->length = sizeof(*wp) - 1;
80 SetLastError(0xfeedfab1);
81 ret = GetWindowPlacement(GetDesktopWindow(), wp);
82 error = GetLastError();
83 ok(ret == TRUE, "ret = %d\n", ret);
84 ok(error == 0xfeedfab1, "error = %lu\n", error);
85 ok(wp->length == sizeof(*wp), "wp.length = %u\n", wp->length);
86 ok(wp->flags == 0, "wp.flags = %x\n", wp->flags);
87
88 FillMemory(wp, sizeof(*wp), 0x55);
89 wp->length = sizeof(*wp) + 1;
90 SetLastError(0xfeedfab1);
91 ret = GetWindowPlacement(GetDesktopWindow(), wp);
92 error = GetLastError();
93 ok(ret == TRUE, "ret = %d\n", ret);
94 ok(error == 0xfeedfab1, "error = %lu\n", error);
95 ok(wp->length == sizeof(*wp), "wp.length = %u\n", wp->length);
96 ok(wp->flags == 0, "wp.flags = %x\n", wp->flags);
97
98 FillMemory(wp, sizeof(*wp), 0x55);
99 wp->length = sizeof(*wp);
100 SetLastError(0xfeedfab1);
101 ret = GetWindowPlacement(GetDesktopWindow(), wp);
102 error = GetLastError();
103 ok(ret == TRUE, "ret = %d\n", ret);
104 ok(error == 0xfeedfab1, "error = %lu\n", error);
105 ok(wp->length == sizeof(*wp), "wp.length = %u\n", wp->length);
106 ok(wp->flags == 0, "wp.flags = %x\n", wp->flags);
107 ok(wp->showCmd == SW_SHOWNORMAL, "wp.showCmd = %u\n", wp->showCmd);
108 ok(wp->ptMinPosition.x == -1, "wp.ptMinPosition.x = %ld\n", wp->ptMinPosition.x);
109 ok(wp->ptMinPosition.y == -1, "wp.ptMinPosition.x = %ld\n", wp->ptMinPosition.y);
110 ok(wp->ptMaxPosition.x == -1, "wp.ptMaxPosition.x = %ld\n", wp->ptMaxPosition.x);
111 ok(wp->ptMaxPosition.y == -1, "wp.ptMaxPosition.y = %ld\n", wp->ptMaxPosition.y);
112 ok(wp->rcNormalPosition.left == 0, "wp.rcNormalPosition.left = %ld\n", wp->rcNormalPosition.left);
113 ok(wp->rcNormalPosition.top == 0, "wp.rcNormalPosition.top = %ld\n", wp->rcNormalPosition.top);
114 ok(wp->rcNormalPosition.right != 0 &&
115 wp->rcNormalPosition.right != 0x55555555, "wp.rcNormalPosition.right = %ld\n", wp->rcNormalPosition.right);
116 ok(wp->rcNormalPosition.bottom != 0 &&
117 wp->rcNormalPosition.bottom != 0x55555555, "wp.rcNormalPosition.bottom = %ld\n", wp->rcNormalPosition.bottom);
118 }