2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for CPoint, CSize, CRect
5 * PROGRAMMER: Mark Jansen
7 * Code based on MSDN samples regarding CPoint, CSize, CRect
15 #define ok_size(x, y) \
16 ok(x == y, "Wrong size, expected '%s' to equal '%s'\n", wine_dbgstr_size(&x), wine_dbgstr_size(&y))
18 #define ok_point(x, y) \
19 ok(x == y, "Wrong point, expected '%s' to equal '%s'\n", wine_dbgstr_point(&x), wine_dbgstr_point(&y))
20 #define nok_point(x, y) \
21 ok(x != y, "Wrong point, expected '%s' NOT to equal '%s'\n", wine_dbgstr_point(&x), wine_dbgstr_point(&y))
23 #define ok_rect(x, y) \
24 ok(x == y, "Wrong rect, expected '%s' to equal '%s'\n", wine_dbgstr_rect(&x), wine_dbgstr_rect(&y))
25 #define nok_rect(x, y) \
26 ok(x != y, "Wrong rect, expected '%s' to NOT equal '%s'\n", wine_dbgstr_rect(&x), wine_dbgstr_rect(&y))
29 static void test_CSize()
32 ok(empty
.cx
== 0, "Expected cx to be 0, was %ld\n", empty
.cx
);
33 ok(empty
.cy
== 0, "Expected cy to be 0, was %ld\n", empty
.cy
);
35 CSize
szPointA(10, 25);
47 CPoint
ptObject(10, 25);
48 CSize
szPointD(ptObject
);
50 DWORD dw
= MAKELONG(10, 25);
53 ok_size(szPointA
, szPointB
);
54 ok_size(szPointB
, szPointC
);
55 ok_size(szPointC
, szPointD
);
56 ok_size(szPointD
, szPointE
);
58 ptObject
= szPointA
+ pt
;
60 ok_point(ptObject
, res
);
62 ptObject
= szPointA
- pt
;
64 ok_point(ptObject
, res
);
70 sz1
= CSize(222, 222);
71 sz2
= CSize(111, 111);
72 ok(sz1
!= sz2
, "Wrong size, expected '%s' NOT to equal '%s'\n", wine_dbgstr_size(&sz1
), wine_dbgstr_size(&sz2
));
74 sz1
= CSize(100, 100);
78 CSize
szResult(150, 125);
79 ok_size(sz1
, szResult
);
81 sz1
= CSize(100, 100);
87 ok_size(sz1
, szResult
);
89 sz1
= CSize(100, 100);
92 szResult
= CSize(50, 75);
93 ok_size(sz1
, szResult
);
98 sz1
= CSize(100, 100);
100 ok_size(sz1
, szResult
);
102 sz1
= CSize(100, 100);
106 szResult
= CSize(150, 125);
107 ok_size(szOut
, szResult
);
113 ok_size(szOut
, szResult
);
117 szResult
= CSize(50, 75);
118 ok_size(szOut
, szResult
);
124 ok_size(szOut
, szResult
);
126 szResult
= CSize(-50, -75);
129 ok_size(szOut
, szResult
);
131 RECT rc
= { 1, 2, 3, 4 };
133 CRect rcres
= sz1
+ &rc
;
134 CRect
rcexp(101, 102, 103, 104);
135 ok_rect(rcexp
, rcres
);
138 rcexp
= CRect(-99, -98, -97, -96);
139 ok_rect(rcexp
, rcres
);
143 static void test_CPoint()
147 ok(empty
.x
== 0, "Expected x to be 0, was %ld\n", empty
.x
);
148 ok(empty
.y
== 0, "Expected y to be 0, was %ld\n", empty
.y
);
150 CPoint
ptTopLeft(0, 0);
155 CPoint
ptMFCHere(ptHere
);
161 CPoint
ptMFCBig(sHowBig
);
163 dwSize
= MAKELONG(35, 95);
165 CPoint
ptFromDouble(dwSize
);
166 ok_point(ptFromDouble
, ptMFCHere
);
168 CPoint
ptStart(100, 100);
169 ptStart
.Offset(35, 35);
171 CPoint
ptResult(135, 135);
172 ok_point(ptStart
, ptResult
);
174 ptStart
= CPoint(100, 100);
181 ok_point(ptStart
, ptResult
);
183 ptStart
= CPoint(100, 100);
189 ptStart
.Offset(size
);
190 ok_point(ptStart
, ptResult
);
192 CPoint
ptFirst(256, 128);
193 CPoint
ptTest(256, 128);
194 ok_point(ptFirst
, ptTest
);
198 ok_point(ptTest
, pt
);
200 ptTest
= CPoint(111, 333);
201 nok_point(ptFirst
, ptTest
);
205 nok_point(ptTest
, pt
);
207 ptStart
= CPoint(100, 100);
208 CSize
szOffset(35, 35);
212 ok_point(ptResult
, ptStart
);
214 ptStart
= CPoint(100, 100);
217 ok_point(ptResult
, ptStart
);
219 ptStart
= CPoint(100, 100);
223 ptResult
= CPoint(65, 65);
224 ok_point(ptResult
, ptStart
);
227 ptStart
= CPoint(100, 100);
230 ok_point(ptResult
, ptStart
);
232 ptStart
= CPoint(100, 100);
235 ptEnd
= ptStart
+ szOffset
;
237 ptResult
= CPoint(135, 135);
238 ok_point(ptResult
, ptEnd
);
240 ptEnd
= ptStart
+ size
;
241 ok_point(ptResult
, ptEnd
);
243 ptEnd
= ptStart
+ pt
;
244 ptResult
= CPoint(433, 211);
245 ok_point(ptResult
, ptEnd
);
247 ptEnd
= ptStart
- szOffset
;
248 ptResult
= CPoint(65, 65);
249 ok_point(ptResult
, ptEnd
);
251 ptEnd
= ptStart
- size
;
252 ok_point(ptResult
, ptEnd
);
254 szOffset
= ptStart
- pt
;
255 CSize
expected(-233, -11);
256 ok_size(szOffset
, expected
);
259 ptResult
= CPoint(433, 211);
260 ok_point(ptResult
, ptStart
);
263 ptResult
= CPoint(100, 100);
264 ok_point(ptResult
, ptStart
);
266 ptTest
= CPoint(35, 35);
269 CPoint
ptNeg(-35, -35);
270 ok_point(ptTest
, ptNeg
);
272 RECT rc
= { 1, 2, 3, 4 };
274 CRect rcres
= ptStart
+ &rc
;
275 CRect
rcexp(101, 102, 103, 104);
276 ok_rect(rcexp
, rcres
);
278 rcres
= ptStart
- &rc
;
279 rcexp
= CRect(-99, -98, -97, -96);
280 ok_rect(rcexp
, rcres
);
284 static void test_CRect()
287 ok(empty
.left
== 0, "Expected left to be 0, was %ld\n", empty
.left
);
288 ok(empty
.top
== 0, "Expected top to be 0, was %ld\n", empty
.top
);
289 ok(empty
.Width() == 0, "Expected Width to be 0, was %i\n", empty
.Width());
290 ok(empty
.Height() == 0, "Expected Height to be 0, was %i\n", empty
.Height());
292 CRect
rect(0, 0, 100, 50);
293 ok(rect
.Width() == 100, "Expected Width to be 100, was %i\n", rect
.Width());
294 ok(rect
.Height() == 50, "Expected Height to be 50, was %i\n", rect
.Height());
302 CRect
rect2(sdkRect
);
303 CRect
rect3(&sdkRect
);
304 ok_rect(rect2
, rect
);
305 ok_rect(rect3
, rect
);
310 ok_rect(rect4
, rect2
);
312 CPoint
ptBottomRight(100, 50);
313 CRect
rect5(pt
, ptBottomRight
);
314 ok_rect(rect5
, rect4
);
316 rect
= CRect(210, 150, 350, 900);
319 ptDown
= rect
.BottomRight();
321 pt
= CPoint(350, 900);
322 ok_point(ptDown
, pt
);
324 rect2
= CRect(10, 10, 350, 350);
325 CPoint
ptLow(180, 180);
327 rect2
.BottomRight() = ptLow
;
329 rect
= CRect(10, 10, 180, 180);
330 ok_rect(rect2
, rect
);
333 CPoint pt2
= rect2
.CenterPoint();
336 pt2
= rect2
.BottomRight();
337 pt
= CPoint(180, 180);
340 pt2
= rect2
.TopLeft();
344 rect2
.TopLeft().Offset(3, 3);
345 rect3
= CRect(13, 13, 180, 180);
346 ok_rect(rect3
, rect2
);
348 CRect
rectSource(35, 10, 125, 10);
351 rectDest
.CopyRect(&rectSource
);
354 rectSource2
.left
= 0;
356 rectSource2
.bottom
= 480;
357 rectSource2
.right
= 640;
359 rectDest
.CopyRect(&rectSource2
);
361 rect
= CRect(10, 10, 50, 50);
363 rect
.DeflateRect(1, 2);
365 rect2
= CRect(11, 12, 49, 48);
366 ok_rect(rect2
, rect
);
368 rect2
= CRect(10, 10, 50, 50);
369 CRect
rectDeflate(1, 2, 3, 4);
371 rect2
.DeflateRect(&rectDeflate
);
372 rect
= CRect(11, 12, 47, 46);
373 ok_rect(rect2
, rect
);
375 rect2
.DeflateRect(sz
);
376 rect
= CRect(111, 62, -53, -4);
377 ok_rect(rect2
, rect
);
379 rect2
.OffsetRect(sz
);
380 rect
= CRect(211, 112, 47, 46);
381 ok_rect(rect2
, rect
);
383 CRect
rect1(35, 150, 10, 25);
384 rect2
= CRect(35, 150, 10, 25);
385 rect3
= CRect(98, 999, 6, 3);
387 ok(rect1
.EqualRect(rect2
), "Expected EqualRect to return TRUE for %s, %s\n", wine_dbgstr_rect(&rect1
), wine_dbgstr_rect(&rect2
));
388 ok(!rect1
.EqualRect(rect3
), "Expected EqualRect to return FALSE for %s, %s\n", wine_dbgstr_rect(&rect1
), wine_dbgstr_rect(&rect3
));
396 ok(rect1
.EqualRect(&test
), "Expected EqualRect to return TRUE for %s, %s\n", wine_dbgstr_rect(&rect1
), wine_dbgstr_rect(&test
));
399 rect2
= CRect(35, 150, 10, 25);
400 ok_rect(rect
, rect2
);
402 rect
= CRect(0, 0, 300, 300);
403 rect
.InflateRect(50, 200);
405 rect2
= CRect(-50, -200, 350, 500);
406 ok_rect(rect
, rect2
);
408 rect
.InflateRect(sz
);
409 rect2
= CRect(-150, -250, 450, 550);
410 ok_rect(rect
, rect2
);
412 rect
= CRect(20, 30, 80, 70);
414 int nHt
= rect
.Height();
416 ok(nHt
== 40, "Expected nHt to be 40, was %i\n", nHt
);
418 CRect
rectOne(125, 0, 150, 200);
419 CRect
rectTwo(0, 75, 350, 95);
422 rectInter
.IntersectRect(rectOne
, rectTwo
);
424 rect
= CRect(125, 75, 150, 95);
425 ok_rect(rectInter
, rect
);
427 CRect rectInter2
= rectOne
;
428 rectInter2
&= rectTwo
;
429 rect
= CRect(125, 75, 150, 95);
430 ok_rect(rectInter2
, rect
);
432 CRect
rectNone(0, 0, 0, 0);
433 CRect
rectSome(35, 50, 135, 150);
435 ok(rectNone
.IsRectEmpty(), "Expected IsRectEmpty to return TRUE for %s\n", wine_dbgstr_rect(&rectNone
));
436 ok(!rectSome
.IsRectEmpty(), "Expected IsRectEmpty to return FALSE for %s\n", wine_dbgstr_rect(&rectSome
));
438 CRect
rectEmpty(35, 35, 35, 35);
439 ok(rectEmpty
.IsRectEmpty(), "Expected IsRectEmpty to return TRUE for %s\n", wine_dbgstr_rect(&rectEmpty
));
441 ok(rectNone
.IsRectNull(), "Expected IsRectNull to return TRUE for %s\n", wine_dbgstr_rect(&rectNone
));
442 ok(!rectSome
.IsRectNull(), "Expected IsRectNull to return FALSE for %s\n", wine_dbgstr_rect(&rectSome
));
444 CRect
rectNotNull(0, 0, 35, 50);
445 ok(!rectNotNull
.IsRectNull(), "Expected IsRectNull to return FALSE for %s\n", wine_dbgstr_rect(&rectNotNull
));
447 rect1
= CRect(35, 150, 10, 25);
448 rect2
= CRect(35, 150, 10, 25);
449 rect3
= CRect(98, 999, 6, 3);
451 ok_rect(rect1
, rect2
);
458 ok_rect(rect1
, test
);
460 nok_rect(rect1
, rect3
);
461 nok_rect(rect3
, test
);
463 rect1
= CRect(100, 235, 200, 335);
465 rect2
= CRect(135, 300, 235, 400);
469 ok_rect(rect1
, rect2
);
471 rect1
= CRect(100, 235, 200, 335);
473 CRect
rectResult(135, 300, 235, 400);
474 ok_rect(rectResult
, rect2
);
476 rect2
= rect1
+ &test
;
477 rectResult
= CRect(65, 85, 210, 360);
478 ok_rect(rectResult
, rect2
);
480 rect2
= rect1
- (LPCRECT
)&test
;
481 rectResult
= CRect(135, 385, 190, 310);
482 ok_rect(rectResult
, rect2
);
485 rectResult
= CRect(65, 170, 165, 270);
487 ok_rect(rect2
, rectResult
);
490 ok_rect(rect1
, rectResult
);
492 rect1
= CRect(100, 0, 200, 300);
493 rect2
= CRect(0, 100, 300, 200);
495 rect3
= rect1
& rect2
;
497 rectResult
= CRect(100, 100, 200, 200);
498 ok_rect(rectResult
, rect3
);
500 rect3
= rect1
| rect2
;
501 rectResult
= CRect(0, 0, 300, 300);
502 ok_rect(rectResult
, rect3
);
505 ok_rect(rectResult
, rect1
);
508 rectResult
= CRect(100, 50, 400, 350);
509 ok_rect(rectResult
, rect1
);
512 rectResult
= CRect(65, -100, 410, 375);
513 ok_rect(rectResult
, rect1
);
516 rectResult
= CRect(-35, -150, 310, 325);
517 ok_rect(rectResult
, rect1
);
520 rectResult
= CRect(0, 0, 300, 300);
521 ok_rect(rectResult
, rect1
);
524 rectResult
= CRect(100, 50, 400, 350);
525 ok_rect(rectResult
, rect2
);
528 rectResult
= CRect(-100, -50, 200, 250);
529 ok_rect(rectResult
, rect2
);