e8512e6dde2f06cce8f8a64551848107e46f518a
[reactos.git] / modules / rostests / apitests / gdi32 / SetWorldTransform.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetWorldTransform
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include "precomp.h"
9
10 void Test_SetWorldTransform()
11 {
12 HDC hdcScreen, hdc;
13 XFORM xform;
14 BOOL result;
15 //PGDI_TABLE_ENTRY pEntry;
16 //DC_ATTR* pdcattr;
17
18 /* Create a DC */
19 hdcScreen = GetDC(NULL);
20 hdc = CreateCompatibleDC(hdcScreen);
21 ReleaseDC(NULL, hdcScreen);
22 SetGraphicsMode(hdc, GM_ADVANCED);
23
24 /* Set identity transform */
25 xform.eM11 = 1;
26 xform.eM12 = 0;
27 xform.eM21 = 0;
28 xform.eM22 = 1;
29 xform.eDx = 0;
30 xform.eDy = 0;
31 result = SetWorldTransform(hdc, &xform);
32 ok(result == 1, "SetWorldTransform should succeed\n");
33
34 /* Set eM11 to 0 */
35 xform.eM11 = 0;
36 result = SetWorldTransform(hdc, &xform);
37 ok(result == 0, "SetWorldTransform should fail\n");
38
39 /* Set eM22 to 0 */
40 xform.eM11 = 1;
41 xform.eM22 = 0;
42 result = SetWorldTransform(hdc, &xform);
43 ok(result == 0, "SetWorldTransform should fail\n");
44
45 /* Set values that result in the determinant being 0 */
46 xform.eM11 = 2;
47 xform.eM12 = 3;
48 xform.eM21 = 4;
49 xform.eM22 = 6;
50 result = SetWorldTransform(hdc, &xform);
51 ok(result == 0, "SetWorldTransform should fail\n");
52
53 /* Small modification to make the determinant != 0 */
54 xform.eM12 = (FLOAT)3.0001;
55 result = SetWorldTransform(hdc, &xform);
56 ok(result == 1, "SetWorldTransform should succeed\n");
57
58 /* Set values that result in the determinant being 0 due to rounding */
59 xform.eM11 = 1;
60 xform.eM12 = (FLOAT)0.9999999;
61 xform.eM21 = (FLOAT)1.0000001;
62 xform.eM22 = 1;
63 ok(xform.eM12 != (FLOAT)1.0, "xform.eM12 shouldn't be 1.0\n");
64 ok(xform.eM21 != (FLOAT)1.0, "xform.eM21 shouldn't be 1.0\n");
65 ok(xform.eM12 * xform.eM21 != (FLOAT)1.0, "xform.eM12 * xform.eM21 shouldn't be 1.0\n");
66 result = SetWorldTransform(hdc, &xform);
67 ok(result == 0, "SetWorldTransform should fail\n");
68
69 /* Test world transform (should be unchanged by previous failure) */
70 result = GetWorldTransform(hdc, &xform);
71 ok(result == 1, "GetWorldTransform should succeed\n");
72 ok(xform.eM11 == 2, "xform.eM11 should be 2\n");
73 ok(xform.eM12 == (FLOAT)3.0001, "xform.eM11 should be 3.0001\n");
74 ok(xform.eM21 == 4, "xform.eM11 should be 4\n");
75 ok(xform.eM22 == 6, "xform.eM11 should be 6\n");
76
77 /* Set smallest possible values */
78 xform.eM11 = (FLOAT)1.4e-45;
79 xform.eM12 = 0;
80 xform.eM21 = 0;
81 xform.eM22 = (FLOAT)1.4e-45;
82 ok(xform.eM11 != (FLOAT)0.0, "xform.eM11 shouldn't be 0.0\n");
83 ok(xform.eM22 != (FLOAT)0.0, "xform.eM22 shouldn't be 0.0\n");
84 ok(xform.eM11 * xform.eM22 != (FLOAT)0.0, "xform.eM12 * xform.eM21 shouldn't be 0.0\n");
85 result = SetWorldTransform(hdc, &xform);
86 ok(result == 1, "SetWorldTransform should succeed\n");
87
88 /* Test world transform */
89 result = GetWorldTransform(hdc, &xform);
90 ok(result == 1, "GetWorldTransform should succeed\n");
91 ok(xform.eM11 > 0, "xform.eM11 should not be 0\n");
92 ok(xform.eM12 == 0, "xform.eM11 should be 0\n");
93 ok(xform.eM21 == 0, "xform.eM11 should be 0\n");
94 ok(xform.eM22 > 0, "xform.eM11 should not be 0\n");
95
96 DeleteDC(hdc);
97 }
98
99 START_TEST(SetWorldTransform)
100 {
101 Test_SetWorldTransform();
102 }
103