[COM_APITEST] Add a test for CLSID_ActiveDesktop
[reactos.git] / modules / 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 "precomp.h"
9
10 void Test_CreateCompatibleDC()
11 {
12 HDC hdcScreen, hOldDC, hdc, hdc2;
13 HPEN hOldPen;
14 COLORREF color;
15
16 /* Get screen DC */
17 hdcScreen = GetDC(NULL);
18
19 /* Test NULL DC handle */
20 SetLastError(ERROR_SUCCESS);
21 hdc = CreateCompatibleDC(NULL);
22 ok(hdc != NULL, "CreateCompatibleDC(NULL) failed\n");
23 ok(GetLastError() == ERROR_SUCCESS, "GetLastError() == %ld\n", GetLastError());
24 if(hdc) DeleteDC(hdc);
25
26 /* Test invalid DC handle */
27 SetLastError(ERROR_SUCCESS);
28 hdc = CreateCompatibleDC((HDC)0x123456);
29 ok(hdc == NULL, "Expected NULL, got %p\n", hdc);
30 ok(GetLastError() == ERROR_SUCCESS, "GetLastError() == %ld\n", GetLastError());
31 if(hdc) DeleteDC(hdc);
32
33 hdc = CreateCompatibleDC(hdcScreen);
34 ok(hdc != NULL, "CreateCompatibleDC failed\n");
35
36 // Test if first selected pen is BLACK_PEN (? or same as screen DC's pen?)
37 hOldPen = SelectObject(hdc, GetStockObject(DC_PEN));
38 ok (hOldPen == GetStockObject(BLACK_PEN), "hOldPen == %p\n", hOldPen);
39 hOldPen = SelectObject(hdc, GetStockObject(BLACK_PEN));
40 ok (hOldPen == GetStockObject(DC_PEN), "hOldPen == %p\n", hOldPen);
41
42 /* Test for the starting Color == RGB(0,0,0) */
43 color = SetDCPenColor(hdc, RGB(1,2,3));
44 ok(color == RGB(0,0,0), "color == %lx\n", color);
45
46 /* Check for reuse counter */
47 hOldDC = hdc;
48 DeleteDC(hdc);
49 hdc = CreateCompatibleDC(hdcScreen);
50 hdc2 = CreateCompatibleDC(hOldDC);
51 ok(hdc2 == NULL, "Expected NULL, got %p\n", hdc);
52 if (hdc2 != NULL) DeleteDC(hdc2);
53
54 /* Check map mode */
55 hdc = CreateCompatibleDC(hdcScreen);
56 SetMapMode(hdc, MM_ISOTROPIC);
57 hdc2 = CreateCompatibleDC(hdc);
58 ok(GetMapMode(hdc2) == MM_TEXT, "GetMapMode(hdc2)==%d\n", GetMapMode(hdc2));
59
60 /* cleanup */
61 DeleteDC(hdc);
62
63 ReleaseDC(NULL, hdcScreen);
64 }
65
66 START_TEST(CreateCompatibleDC)
67 {
68 Test_CreateCompatibleDC();
69 }
70