1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for NtGdiSaveDC
5  * PROGRAMMERS:
6  */
7 
8 #include "../win32nt.h"
9 
10 START_TEST(NtGdiSaveDC)
11 {
12     HINSTANCE hinst = GetModuleHandle(NULL);
13     HDC hdc, hdc2;
14     HWND hwnd;
15     HBITMAP hbmp1, hbmp2, hOldBmp;
16 
17     /* Test 0 hdc */
18     TEST(NtGdiSaveDC(0) == 0);
19 
20     /* Test info dc */
21     hdc = CreateICW(L"DISPLAY",NULL,NULL,NULL);
22     TEST(hdc != NULL);
23     TEST(NtGdiSaveDC(hdc) == 1);
24     TEST(NtGdiSaveDC(hdc) == 2);
25     DeleteDC(hdc);
26 
27     /* Test display dc */
28     hdc = GetDC(0);
29     TEST(hdc != NULL);
30     TEST(NtGdiSaveDC(hdc) == 1);
31     TEST(NtGdiSaveDC(hdc) == 2);
32     ReleaseDC(0, hdc);
33 
34     /* Test a mem DC */
35     hdc = CreateCompatibleDC(0);
36     TEST(hdc != NULL);
37     TEST(NtGdiSaveDC(hdc) == 1);
38     TEST(NtGdiSaveDC(hdc) == 2);
39     DeleteDC(hdc);
40 
41     /* Create a window */
42     hwnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
43                         10, 10, 100, 100,
44                         NULL, NULL, hinst, 0);
45     hdc = GetDC(hwnd);
46     TEST(hdc != NULL);
47     TEST(NtGdiSaveDC(hdc) == 1);
48     NtGdiRestoreDC(hdc, 1);
49     ReleaseDC(hwnd, hdc);
50     DestroyWindow(hwnd);
51 
52     /* test behaviour when a bitmap is selected */
53     hbmp1 = CreateBitmap(2, 2, 1, 1, NULL);
54     TEST(hbmp1 != NULL);
55     hbmp2 = CreateBitmap(2, 2, 1, 1, NULL);
56     TEST(hbmp2 != NULL);
57     hdc = CreateCompatibleDC(0);
58     TEST(hdc != NULL);
59     hdc2 = CreateCompatibleDC(0);
60     TEST(hdc2 != NULL);
61     hOldBmp = SelectObject(hdc, hbmp1);
62     TEST(hOldBmp != NULL);
63     TEST(NtGdiSaveDC(hdc) == 1);
64     TEST(SelectObject(hdc, hbmp2) == hbmp1);
65     TEST(SelectObject(hdc2, hbmp1) == NULL);
66     SelectObject(hdc, hOldBmp);
67     NtGdiRestoreDC(hdc, 1);
68     TEST(GetCurrentObject(hdc, OBJ_BITMAP) == hbmp1);
69     /* Again, just to be sure */
70     TEST(NtGdiSaveDC(hdc) == 1);
71     TEST(NtGdiSaveDC(hdc) == 2);
72     TEST(SelectObject(hdc, hbmp2) == hbmp1);
73     TEST(SelectObject(hdc2, hbmp1) == NULL);
74     SelectObject(hdc, hOldBmp);
75     NtGdiRestoreDC(hdc, 2);
76     TEST(GetCurrentObject(hdc, OBJ_BITMAP) == hbmp1);
77     /*Cleanup */
78     SelectObject(hdc, hOldBmp);
79     DeleteDC(hdc);
80     DeleteDC(hdc2);
81     DeleteObject(hbmp1);
82     DeleteObject(hbmp2);
83 
84 }
85 
86