[ROSTESTS]
[reactos.git] / rostests / apitests / w32knapi / ntgdi / NtGdiSaveDC.c
1
2 INT
3 Test_NtGdiSaveDC(PTESTINFO pti)
4 {
5 HDC hdc, hdc2;
6 HWND hwnd;
7 HBITMAP hbmp1, hbmp2, hOldBmp;
8
9 /* Test 0 hdc */
10 TEST(NtGdiSaveDC(0) == 0);
11
12 /* Test info dc */
13 hdc = CreateICW(L"DISPLAY",NULL,NULL,NULL);
14 TEST(hdc);
15 TEST(NtGdiSaveDC(hdc) == 1);
16 TEST(NtGdiSaveDC(hdc) == 2);
17 DeleteDC(hdc);
18
19 /* Test display dc */
20 hdc = GetDC(0);
21 TEST(hdc);
22 TEST(NtGdiSaveDC(hdc) == 1);
23 TEST(NtGdiSaveDC(hdc) == 2);
24 ReleaseDC(0, hdc);
25
26 /* Test a mem DC */
27 hdc = CreateCompatibleDC(0);
28 TEST(hdc);
29 TEST(NtGdiSaveDC(hdc) == 1);
30 TEST(NtGdiSaveDC(hdc) == 2);
31 DeleteDC(hdc);
32
33 /* Create a window */
34 hwnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
35 10, 10, 100, 100,
36 NULL, NULL, g_hInstance, 0);
37 hdc = GetDC(hwnd);
38 TEST(hdc);
39 TEST(NtGdiSaveDC(hdc) == 1);
40 NtGdiRestoreDC(hdc, 1);
41 ReleaseDC(hwnd, hdc);
42 DestroyWindow(hwnd);
43
44 /* test behaviour when a bitmap is selected */
45 hbmp1 = CreateBitmap(2, 2, 1, 1, NULL);
46 TEST(hbmp1);
47 hbmp2 = CreateBitmap(2, 2, 1, 1, NULL);
48 TEST(hbmp2);
49 hdc = CreateCompatibleDC(0);
50 TEST(hdc);
51 hdc2 = CreateCompatibleDC(0);
52 TEST(hdc2);
53 hOldBmp = SelectObject(hdc, hbmp1);
54 TEST(hOldBmp);
55 TEST(NtGdiSaveDC(hdc) == 1);
56 TEST(SelectObject(hdc, hbmp2) == hbmp1);
57 TEST(SelectObject(hdc2, hbmp1) == NULL);
58 SelectObject(hdc, hOldBmp);
59 NtGdiRestoreDC(hdc, 1);
60 TEST(GetCurrentObject(hdc, OBJ_BITMAP) == hbmp1);
61 /* Again, just to be sure */
62 TEST(NtGdiSaveDC(hdc) == 1);
63 TEST(NtGdiSaveDC(hdc) == 2);
64 TEST(SelectObject(hdc, hbmp2) == hbmp1);
65 TEST(SelectObject(hdc2, hbmp1) == NULL);
66 SelectObject(hdc, hOldBmp);
67 NtGdiRestoreDC(hdc, 2);
68 TEST(GetCurrentObject(hdc, OBJ_BITMAP) == hbmp1);
69 /*Cleanup */
70 SelectObject(hdc, hOldBmp);
71 DeleteDC(hdc);
72 DeleteDC(hdc2);
73 DeleteObject(hbmp1);
74 DeleteObject(hbmp2);
75
76 return APISTATUS_NORMAL;
77 }
78