[SPIDER]
[reactos.git] / rostests / apitests / gdi32 / CreateCompatibleDC.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for CreateCompatibleDC
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <apitest.h>
9
10 #include <wingdi.h>
11 #include <winuser.h>
12
13 void Test_CreateCompatibleDC()
14 {
15 HDC hdcScreen, hOldDC, hdc, hdc2;
16 HPEN hOldPen;
17 COLORREF color;
18
19 /* Get screen DC */
20 hdcScreen = GetDC(NULL);
21
22 /* Test NULL DC handle */
23 SetLastError(ERROR_SUCCESS);
24 hdc = CreateCompatibleDC(NULL);
25 ok(hdc != NULL, "CreateCompatibleDC(NULL) failed\n");
26 ok(GetLastError() == ERROR_SUCCESS, "GetLastError() == %ld\n", GetLastError());
27 if(hdc) DeleteDC(hdc);
28
29 /* Test invalid DC handle */
30 SetLastError(ERROR_SUCCESS);
31 hdc = CreateCompatibleDC((HDC)0x123456);
32 ok(hdc == NULL, "Expected NULL, got %p\n", hdc);
33 ok(GetLastError() == ERROR_SUCCESS, "GetLastError() == %ld\n", GetLastError());
34 if(hdc) DeleteDC(hdc);
35
36 hdc = CreateCompatibleDC(hdcScreen);
37 ok(hdc != NULL, "CreateCompatibleDC failed\n");
38
39 // Test if first selected pen is BLACK_PEN (? or same as screen DC's pen?)
40 hOldPen = SelectObject(hdc, GetStockObject(DC_PEN));
41 ok (hOldPen == GetStockObject(BLACK_PEN), "hOldPen == %p\n", hOldPen);
42 hOldPen = SelectObject(hdc, GetStockObject(BLACK_PEN));
43 ok (hOldPen == GetStockObject(DC_PEN), "hOldPen == %p\n", hOldPen);
44
45 /* Test for the starting Color == RGB(0,0,0) */
46 color = SetDCPenColor(hdc, RGB(1,2,3));
47 ok(color == RGB(0,0,0), "color == %lx\n", color);
48
49 /* Check for reuse counter */
50 hOldDC = hdc;
51 DeleteDC(hdc);
52 hdc = CreateCompatibleDC(hdcScreen);
53 hdc2 = CreateCompatibleDC(hOldDC);
54 ok(hdc2 == NULL, "Expected NULL, got %p\n", hdc);
55 if (hdc2 != NULL) DeleteDC(hdc2);
56
57 /* Check map mode */
58 hdc = CreateCompatibleDC(hdcScreen);
59 SetMapMode(hdc, MM_ISOTROPIC);
60 hdc2 = CreateCompatibleDC(hdc);
61 ok(GetMapMode(hdc2) == MM_TEXT, "GetMapMode(hdc2)==%d\n", GetMapMode(hdc2));
62
63 /* cleanup */
64 DeleteDC(hdc);
65
66 ReleaseDC(NULL, hdcScreen);
67 }
68
69 START_TEST(CreateCompatibleDC)
70 {
71 Test_CreateCompatibleDC();
72 }
73