[USER32_APITEST]
[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 SetLastError(0xfeedfab1);
43 ret = GetWindowPlacement(GetDesktopWindow(), (PVOID)(ALIGN_UP_BY(buffer, 16) + 1));
44 error = GetLastError();
45 ok(ret == TRUE, "ret = %d\n", ret);
46 ok(error == 0xfeedfab1, "error = %lu\n", error);
47
48 FillMemory(wp, sizeof(*wp), 0x55);
49 wp->length = 0;
50 SetLastError(0xfeedfab1);
51 ret = GetWindowPlacement(NULL, wp);
52 error = GetLastError();
53 ok(ret == FALSE, "ret = %d\n", ret);
54 ok(error == ERROR_INVALID_WINDOW_HANDLE, "error = %lu\n", error);
55 ok(wp->length == 0, "wp.length = %u\n", wp->length);
56
57 FillMemory(wp, sizeof(*wp), 0x55);
58 wp->length = 0;
59 SetLastError(0xfeedfab1);
60 ret = GetWindowPlacement(GetDesktopWindow(), wp);
61 error = GetLastError();
62 ok(ret == TRUE, "ret = %d\n", ret);
63 ok(error == 0xfeedfab1, "error = %lu\n", error);
64 ok(wp->length == sizeof(*wp), "wp.length = %u\n", wp->length);
65 ok(wp->flags == 0, "wp.flags = %x\n", wp->flags);
66
67 FillMemory(wp, sizeof(*wp), 0x55);
68 wp->length = 1;
69 SetLastError(0xfeedfab1);
70 ret = GetWindowPlacement(GetDesktopWindow(), wp);
71 error = GetLastError();
72 ok(ret == TRUE, "ret = %d\n", ret);
73 ok(error == 0xfeedfab1, "error = %lu\n", error);
74 ok(wp->length == sizeof(*wp), "wp.length = %u\n", wp->length);
75 ok(wp->flags == 0, "wp.flags = %x\n", wp->flags);
76
77 FillMemory(wp, sizeof(*wp), 0x55);
78 wp->length = sizeof(*wp) - 1;
79 SetLastError(0xfeedfab1);
80 ret = GetWindowPlacement(GetDesktopWindow(), wp);
81 error = GetLastError();
82 ok(ret == TRUE, "ret = %d\n", ret);
83 ok(error == 0xfeedfab1, "error = %lu\n", error);
84 ok(wp->length == sizeof(*wp), "wp.length = %u\n", wp->length);
85 ok(wp->flags == 0, "wp.flags = %x\n", wp->flags);
86
87 FillMemory(wp, sizeof(*wp), 0x55);
88 wp->length = sizeof(*wp) + 1;
89 SetLastError(0xfeedfab1);
90 ret = GetWindowPlacement(GetDesktopWindow(), wp);
91 error = GetLastError();
92 ok(ret == TRUE, "ret = %d\n", ret);
93 ok(error == 0xfeedfab1, "error = %lu\n", error);
94 ok(wp->length == sizeof(*wp), "wp.length = %u\n", wp->length);
95 ok(wp->flags == 0, "wp.flags = %x\n", wp->flags);
96
97 FillMemory(wp, sizeof(*wp), 0x55);
98 wp->length = sizeof(*wp);
99 SetLastError(0xfeedfab1);
100 ret = GetWindowPlacement(GetDesktopWindow(), wp);
101 error = GetLastError();
102 ok(ret == TRUE, "ret = %d\n", ret);
103 ok(error == 0xfeedfab1, "error = %lu\n", error);
104 ok(wp->length == sizeof(*wp), "wp.length = %u\n", wp->length);
105 ok(wp->flags == 0, "wp.flags = %x\n", wp->flags);
106 ok(wp->showCmd == SW_SHOWNORMAL, "wp.showCmd = %u\n", wp->showCmd);
107 ok(wp->ptMinPosition.x == -1, "wp.ptMinPosition.x = %ld\n", wp->ptMinPosition.x);
108 ok(wp->ptMinPosition.y == -1, "wp.ptMinPosition.x = %ld\n", wp->ptMinPosition.y);
109 ok(wp->ptMaxPosition.x == -1, "wp.ptMaxPosition.x = %ld\n", wp->ptMaxPosition.x);
110 ok(wp->ptMaxPosition.y == -1, "wp.ptMaxPosition.y = %ld\n", wp->ptMaxPosition.y);
111 ok(wp->rcNormalPosition.left == 0, "wp.rcNormalPosition.left = %ld\n", wp->rcNormalPosition.left);
112 ok(wp->rcNormalPosition.top == 0, "wp.rcNormalPosition.top = %ld\n", wp->rcNormalPosition.top);
113 ok(wp->rcNormalPosition.right != 0 &&
114 wp->rcNormalPosition.right != 0x55555555, "wp.rcNormalPosition.right = %ld\n", wp->rcNormalPosition.right);
115 ok(wp->rcNormalPosition.bottom != 0 &&
116 wp->rcNormalPosition.bottom != 0x55555555, "wp.rcNormalPosition.bottom = %ld\n", wp->rcNormalPosition.bottom);
117 }