1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for NtGdiGetRandomRgn
5  * PROGRAMMERS:
6  */
7 
8 #include <win32nt.h>
9 
10 START_TEST(NtGdiGetRandomRgn)
11 {
12     HINSTANCE hinst = GetModuleHandle(NULL);
13     HWND hWnd;
14     HDC hDC;
15     HRGN hrgn, hrgn2;
16 
17     /* Create a window */
18     hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
19                         CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
20                         NULL, NULL, hinst, 0);
21 //  UpdateWindow(hWnd);
22     hDC = GetDC(hWnd);
23 
24     ok(hDC != NULL, "hDC was NULL.\n");
25 
26     hrgn = CreateRectRgn(0,0,0,0);
27     hrgn2 = CreateRectRgn(3,3,10,10);
28     SetLastError(ERROR_SUCCESS);
29     ok_int(NtGdiGetRandomRgn(0, hrgn, 0), -1);
30     ok_long(GetLastError(), ERROR_INVALID_HANDLE);
31 
32     SetLastError(ERROR_SUCCESS);
33     ok_int(NtGdiGetRandomRgn((HDC)2345, hrgn, 1), -1);
34     ok_long(GetLastError(), ERROR_INVALID_HANDLE);
35 
36     SetLastError(ERROR_SUCCESS);
37     ok_int(NtGdiGetRandomRgn((HDC)2345, hrgn, 10), -1);
38     ok_long(GetLastError(), ERROR_INVALID_HANDLE);
39 
40     SetLastError(ERROR_SUCCESS);
41     ok_int(NtGdiGetRandomRgn((HDC)2345, (HRGN)10, 10), -1);
42     ok_long(GetLastError(), ERROR_INVALID_HANDLE);
43 
44     SetLastError(ERROR_SUCCESS);
45     ok_int(NtGdiGetRandomRgn((HDC)2345, 0, 1), -1);
46     ok_long(GetLastError(), ERROR_INVALID_HANDLE);
47 
48     SetLastError(ERROR_SUCCESS);
49     ok_int(NtGdiGetRandomRgn(hDC, 0, 0), 0);
50     ok_int(NtGdiGetRandomRgn(hDC, 0, 1), 0);
51     ok_int(NtGdiGetRandomRgn(hDC, (HRGN)-5, 0), 0);
52     ok_int(NtGdiGetRandomRgn(hDC, (HRGN)-5, 1), 0);
53     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 0), 0);
54     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 1), 0);
55     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 2), 0);
56     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 3), 0);
57     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 4), 1);
58     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 5), 0);
59     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 10), 0);
60     ok_int(NtGdiGetRandomRgn(hDC, hrgn, -10), 0);
61     ok_long(GetLastError(), ERROR_SUCCESS);
62 
63     SelectClipRgn(hDC, hrgn2);
64     ok_int(NtGdiGetRandomRgn(hDC, 0, 1), -1);
65     ok_long(GetLastError(), ERROR_SUCCESS);
66     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 1), 1);
67     ok_int(CombineRgn(hrgn, hrgn, hrgn, RGN_OR), SIMPLEREGION);
68     ok_int(CombineRgn(hrgn, hrgn, hrgn2, RGN_XOR), NULLREGION);
69 
70     SetRectRgn(hrgn2,0,0,0,0);
71     SelectClipRgn(hDC, hrgn2);
72     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 1), 1);
73 
74     ok_int(CombineRgn(hrgn2, hrgn, hrgn2, RGN_XOR), NULLREGION);
75     ok_int(CombineRgn(hrgn2, hrgn, hrgn, RGN_OR), NULLREGION);
76 
77     SelectClipRgn(hDC, NULL);
78     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 1), 0);
79 
80 
81     ok_int(NtGdiGetRandomRgn(hDC, hrgn, 4), 1);
82 
83     ok_long(GetLastError(), ERROR_SUCCESS);
84 
85     ReleaseDC(hWnd, hDC);
86     DestroyWindow(hWnd);
87 
88 }
89