ReactOS 0.4.16-dev-320-g3bd9ddc
atltypes.cpp
Go to the documentation of this file.
1/*
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
6 *
7 * Code based on MSDN samples regarding CPoint, CSize, CRect
8 */
9
10#ifdef HAVE_APITEST
11 #include <apitest.h>
12#else
13 #include "atltest.h"
14#endif
15#include <windows.h>
16#include <atltypes.h>
17
18
19#define ok_size(x, y) \
20 ok(x == y, "Wrong size, expected '%s' to equal '%s'\n", wine_dbgstr_size(&x), wine_dbgstr_size(&y))
21
22#define ok_point(x, y) \
23 ok(x == y, "Wrong point, expected '%s' to equal '%s'\n", wine_dbgstr_point(&x), wine_dbgstr_point(&y))
24#define nok_point(x, y) \
25 ok(x != y, "Wrong point, expected '%s' NOT to equal '%s'\n", wine_dbgstr_point(&x), wine_dbgstr_point(&y))
26
27#define ok_rect(x, y) \
28 ok(x == y, "Wrong rect, expected '%s' to equal '%s'\n", wine_dbgstr_rect(&x), wine_dbgstr_rect(&y))
29#define nok_rect(x, y) \
30 ok(x != y, "Wrong rect, expected '%s' to NOT equal '%s'\n", wine_dbgstr_rect(&x), wine_dbgstr_rect(&y))
31
32
33static void test_CSize()
34{
36 ok(empty.cx == 0, "Expected cx to be 0, was %ld\n", empty.cx);
37 ok(empty.cy == 0, "Expected cy to be 0, was %ld\n", empty.cy);
38
39 CSize szPointA(10, 25);
40
41 SIZE sz;
42 sz.cx = 10;
43 sz.cy = 25;
44 CSize szPointB(sz);
45
46 POINT pt;
47 pt.x = 10;
48 pt.y = 25;
49 CSize szPointC(pt);
50
51 CPoint ptObject(10, 25);
52 CSize szPointD(ptObject);
53
54 DWORD dw = MAKELONG(10, 25);
55 CSize szPointE(dw);
56
57 ok_size(szPointA, szPointB);
58 ok_size(szPointB, szPointC);
59 ok_size(szPointC, szPointD);
60 ok_size(szPointD, szPointE);
61
62 ptObject = szPointA + pt;
63 CPoint res(20,50);
64 ok_point(ptObject, res);
65
66 ptObject = szPointA - pt;
67 res = CPoint(0, 0);
68 ok_point(ptObject, res);
69
70 CSize sz1(135, 135);
71 CSize sz2(135, 135);
72 ok_size(sz1, sz2);
73
74 sz1 = CSize(222, 222);
75 sz2 = CSize(111, 111);
76 ok(sz1 != sz2, "Wrong size, expected '%s' NOT to equal '%s'\n", wine_dbgstr_size(&sz1), wine_dbgstr_size(&sz2));
77
78 sz1 = CSize(100, 100);
79 sz2 = CSize(50, 25);
80 sz1 += sz2;
81
82 CSize szResult(150, 125);
83 ok_size(sz1, szResult);
84
85 sz1 = CSize(100, 100);
86 SIZE sz3;
87 sz3.cx = 50;
88 sz3.cy = 25;
89
90 sz1 += sz3;
91 ok_size(sz1, szResult);
92
93 sz1 = CSize(100, 100);
94 sz1 -= sz2;
95
96 szResult = CSize(50, 75);
97 ok_size(sz1, szResult);
98
99 sz3.cx = 50;
100 sz3.cy = 25;
101
102 sz1 = CSize(100, 100);
103 sz1 -= sz3;
104 ok_size(sz1, szResult);
105
106 sz1 = CSize(100, 100);
107 CSize szOut;
108 szOut = sz1 + sz2;
109
110 szResult = CSize(150, 125);
111 ok_size(szOut, szResult);
112
113 sz3.cx = 50;
114 sz3.cy = 25;
115
116 szOut = sz1 + sz3;
117 ok_size(szOut, szResult);
118
119 szOut = sz1 - sz2;
120
121 szResult = CSize(50, 75);
122 ok_size(szOut, szResult);
123
124 sz3.cx = 50;
125 sz3.cy = 25;
126
127 szOut = sz1 - sz3;
128 ok_size(szOut, szResult);
129
130 szResult = CSize(-50, -75);
131
132 szOut = -szOut;
133 ok_size(szOut, szResult);
134
135 RECT rc = { 1, 2, 3, 4 };
136
137 CRect rcres = sz1 + &rc;
138 CRect rcexp(101, 102, 103, 104);
139 ok_rect(rcexp, rcres);
140
141 rcres = sz1 - &rc;
142 rcexp = CRect(-99, -98, -97, -96);
143 ok_rect(rcexp, rcres);
144}
145
146
147static void test_CPoint()
148{
150
151 ok(empty.x == 0, "Expected x to be 0, was %ld\n", empty.x);
152 ok(empty.y == 0, "Expected y to be 0, was %ld\n", empty.y);
153
154 CPoint ptTopLeft(0, 0);
155 POINT ptHere;
156 ptHere.x = 35;
157 ptHere.y = 95;
158
159 CPoint ptMFCHere(ptHere);
160
161 SIZE sHowBig;
162 sHowBig.cx = 300;
163 sHowBig.cy = 10;
164
165 CPoint ptMFCBig(sHowBig);
167 dwSize = MAKELONG(35, 95);
168
169 CPoint ptFromDouble(dwSize);
170 ok_point(ptFromDouble, ptMFCHere);
171
172 CPoint ptStart(100, 100);
173 ptStart.Offset(35, 35);
174
175 CPoint ptResult(135, 135);
176 ok_point(ptStart, ptResult);
177
178 ptStart = CPoint(100, 100);
179 POINT pt;
180
181 pt.x = 35;
182 pt.y = 35;
183
184 ptStart.Offset(pt);
185 ok_point(ptStart, ptResult);
186
187 ptStart = CPoint(100, 100);
188 SIZE size;
189
190 size.cx = 35;
191 size.cy = 35;
192
193 ptStart.Offset(size);
194 ok_point(ptStart, ptResult);
195
196 CPoint ptFirst(256, 128);
197 CPoint ptTest(256, 128);
198 ok_point(ptFirst, ptTest);
199
200 pt.x = 256;
201 pt.y = 128;
202 ok_point(ptTest, pt);
203
204 ptTest = CPoint(111, 333);
205 nok_point(ptFirst, ptTest);
206
207 pt.x = 333;
208 pt.y = 111;
209 nok_point(ptTest, pt);
210
211 ptStart = CPoint(100, 100);
212 CSize szOffset(35, 35);
213
214 ptStart += szOffset;
215
216 ok_point(ptResult, ptStart);
217
218 ptStart = CPoint(100, 100);
219
220 ptStart += size;
221 ok_point(ptResult, ptStart);
222
223 ptStart = CPoint(100, 100);
224
225 ptStart -= szOffset;
226
227 ptResult = CPoint(65, 65);
228 ok_point(ptResult, ptStart);
229
230
231 ptStart = CPoint(100, 100);
232
233 ptStart -= size;
234 ok_point(ptResult, ptStart);
235
236 ptStart = CPoint(100, 100);
237 CPoint ptEnd;
238
239 ptEnd = ptStart + szOffset;
240
241 ptResult = CPoint(135, 135);
242 ok_point(ptResult, ptEnd);
243
244 ptEnd = ptStart + size;
245 ok_point(ptResult, ptEnd);
246
247 ptEnd = ptStart + pt;
248 ptResult = CPoint(433, 211);
249 ok_point(ptResult, ptEnd);
250
251 ptEnd = ptStart - szOffset;
252 ptResult = CPoint(65, 65);
253 ok_point(ptResult, ptEnd);
254
255 ptEnd = ptStart - size;
256 ok_point(ptResult, ptEnd);
257
258 szOffset = ptStart - pt;
259 CSize expected(-233, -11);
260 ok_size(szOffset, expected);
261
262 ptStart += pt;
263 ptResult = CPoint(433, 211);
264 ok_point(ptResult, ptStart);
265
266 ptStart -= pt;
267 ptResult = CPoint(100, 100);
268 ok_point(ptResult, ptStart);
269
270 ptTest = CPoint(35, 35);
271 ptTest = -ptTest;
272
273 CPoint ptNeg(-35, -35);
274 ok_point(ptTest, ptNeg);
275
276 RECT rc = { 1, 2, 3, 4 };
277
278 CRect rcres = ptStart + &rc;
279 CRect rcexp(101, 102, 103, 104);
280 ok_rect(rcexp, rcres);
281
282 rcres = ptStart - &rc;
283 rcexp = CRect(-99, -98, -97, -96);
284 ok_rect(rcexp, rcres);
285}
286
287
288static void test_CRect()
289{
290 CRect empty;
291 ok(empty.left == 0, "Expected left to be 0, was %ld\n", empty.left);
292 ok(empty.top == 0, "Expected top to be 0, was %ld\n", empty.top);
293 ok(empty.Width() == 0, "Expected Width to be 0, was %i\n", empty.Width());
294 ok(empty.Height() == 0, "Expected Height to be 0, was %i\n", empty.Height());
295
296 CRect rect(0, 0, 100, 50);
297 ok(rect.Width() == 100, "Expected Width to be 100, was %i\n", rect.Width());
298 ok(rect.Height() == 50, "Expected Height to be 50, was %i\n", rect.Height());
299
300 RECT sdkRect;
301 sdkRect.left = 0;
302 sdkRect.top = 0;
303 sdkRect.right = 100;
304 sdkRect.bottom = 50;
305
306 CRect rect2(sdkRect);
307 CRect rect3(&sdkRect);
309 ok_rect(rect3, rect);
310
311 CPoint pt(0, 0);
312 CSize sz(100, 50);
313 CRect rect4(pt, sz);
314 ok_rect(rect4, rect2);
315
316 CPoint ptBottomRight(100, 50);
317 CRect rect5(pt, ptBottomRight);
318 ok_rect(rect5, rect4);
319
320 rect = CRect(210, 150, 350, 900);
321 CPoint ptDown;
322
323 ptDown = rect.BottomRight();
324
325 pt = CPoint(350, 900);
326 ok_point(ptDown, pt);
327
328 rect2 = CRect(10, 10, 350, 350);
329 CPoint ptLow(180, 180);
330
331 rect2.BottomRight() = ptLow;
332
333 rect = CRect(10, 10, 180, 180);
335
336 pt = CPoint(95, 95);
337 CPoint pt2 = rect2.CenterPoint();
338 ok_point(pt2, pt);
339
340 pt2 = rect2.BottomRight();
341 pt = CPoint(180, 180);
342 ok_point(pt2, pt);
343
344 pt2 = rect2.TopLeft();
345 pt = CPoint(10, 10);
346 ok_point(pt2, pt);
347
348 rect2.TopLeft().Offset(3, 3);
349 rect3 = CRect(13, 13, 180, 180);
350 ok_rect(rect3, rect2);
351
352 CRect rectSource(35, 10, 125, 10);
353 CRect rectDest;
354
355 rectDest.CopyRect(&rectSource);
356
357 RECT rectSource2;
358 rectSource2.left = 0;
359 rectSource2.top = 0;
360 rectSource2.bottom = 480;
361 rectSource2.right = 640;
362
363 rectDest.CopyRect(&rectSource2);
364
365 rect = CRect(10, 10, 50, 50);
366
367 rect.DeflateRect(1, 2);
368
369 rect2 = CRect(11, 12, 49, 48);
371
372 rect2 = CRect(10, 10, 50, 50);
373 CRect rectDeflate(1, 2, 3, 4);
374
375 rect2.DeflateRect(&rectDeflate);
376 rect = CRect(11, 12, 47, 46);
378
379 rect2.DeflateRect(sz);
380 rect = CRect(111, 62, -53, -4);
382
383 rect2.OffsetRect(sz);
384 rect = CRect(211, 112, 47, 46);
386
387 CRect rect1(35, 150, 10, 25);
388 rect2 = CRect(35, 150, 10, 25);
389 rect3 = CRect(98, 999, 6, 3);
390
391 ok(rect1.EqualRect(rect2), "Expected EqualRect to return TRUE for %s, %s\n", wine_dbgstr_rect(&rect1), wine_dbgstr_rect(&rect2));
392 ok(!rect1.EqualRect(rect3), "Expected EqualRect to return FALSE for %s, %s\n", wine_dbgstr_rect(&rect1), wine_dbgstr_rect(&rect3));
393
394 RECT test;
395 test.left = 35;
396 test.top = 150;
397 test.right = 10;
398 test.bottom = 25;
399
400 ok(rect1.EqualRect(&test), "Expected EqualRect to return TRUE for %s, %s\n", wine_dbgstr_rect(&rect1), wine_dbgstr_rect(&test));
401
402 rect = test;
403 rect2 = CRect(35, 150, 10, 25);
405
406 rect = CRect(0, 0, 300, 300);
407 rect.InflateRect(50, 200);
408
409 rect2 = CRect(-50, -200, 350, 500);
411
412 rect.InflateRect(sz);
413 rect2 = CRect(-150, -250, 450, 550);
415
416 rect = CRect(20, 30, 80, 70);
417
418 int nHt = rect.Height();
419
420 ok(nHt == 40, "Expected nHt to be 40, was %i\n", nHt);
421
422 CRect rectOne(125, 0, 150, 200);
423 CRect rectTwo(0, 75, 350, 95);
424 CRect rectInter;
425
426 rectInter.IntersectRect(rectOne, rectTwo);
427
428 rect = CRect(125, 75, 150, 95);
429 ok_rect(rectInter, rect);
430
431 CRect rectInter2 = rectOne;
432 rectInter2 &= rectTwo;
433 rect = CRect(125, 75, 150, 95);
434 ok_rect(rectInter2, rect);
435
436 CRect rectNone(0, 0, 0, 0);
437 CRect rectSome(35, 50, 135, 150);
438
439 ok(rectNone.IsRectEmpty(), "Expected IsRectEmpty to return TRUE for %s\n", wine_dbgstr_rect(&rectNone));
440 ok(!rectSome.IsRectEmpty(), "Expected IsRectEmpty to return FALSE for %s\n", wine_dbgstr_rect(&rectSome));
441
442 CRect rectEmpty(35, 35, 35, 35);
443 ok(rectEmpty.IsRectEmpty(), "Expected IsRectEmpty to return TRUE for %s\n", wine_dbgstr_rect(&rectEmpty));
444
445 ok(rectNone.IsRectNull(), "Expected IsRectNull to return TRUE for %s\n", wine_dbgstr_rect(&rectNone));
446 ok(!rectSome.IsRectNull(), "Expected IsRectNull to return FALSE for %s\n", wine_dbgstr_rect(&rectSome));
447
448 CRect rectNotNull(0, 0, 35, 50);
449 ok(!rectNotNull.IsRectNull(), "Expected IsRectNull to return FALSE for %s\n", wine_dbgstr_rect(&rectNotNull));
450
451 rect1 = CRect(35, 150, 10, 25);
452 rect2 = CRect(35, 150, 10, 25);
453 rect3 = CRect(98, 999, 6, 3);
454
455 ok_rect(rect1, rect2);
456
457 test.left = 35;
458 test.top = 150;
459 test.right = 10;
460 test.bottom = 25;
461
462 ok_rect(rect1, test);
463
464 nok_rect(rect1, rect3);
465 nok_rect(rect3, test);
466
467 rect1 = CRect(100, 235, 200, 335);
468 pt = CPoint(35, 65);
469 rect2 = CRect(135, 300, 235, 400);
470
471 rect1 += pt;
472
473 ok_rect(rect1, rect2);
474
475 rect1 = CRect(100, 235, 200, 335);
476 rect2 = rect1 + pt;
477 CRect rectResult(135, 300, 235, 400);
478 ok_rect(rectResult, rect2);
479
480 rect2 = rect1 + &test;
481 rectResult = CRect(65, 85, 210, 360);
482 ok_rect(rectResult, rect2);
483
484 rect2 = rect1 - (LPCRECT)&test;
485 rectResult = CRect(135, 385, 190, 310);
486 ok_rect(rectResult, rect2);
487
488 rect2 = rect1 - pt;
489 rectResult = CRect(65, 170, 165, 270);
490
491 ok_rect(rect2, rectResult);
492
493 rect1 -= pt;
494 ok_rect(rect1, rectResult);
495
496 rect1 = CRect(100, 0, 200, 300);
497 rect2 = CRect(0, 100, 300, 200);
498
499 rect3 = rect1 & rect2;
500
501 rectResult = CRect(100, 100, 200, 200);
502 ok_rect(rectResult, rect3);
503
504 rect3 = rect1 | rect2;
505 rectResult = CRect(0, 0, 300, 300);
506 ok_rect(rectResult, rect3);
507
508 rect1 |= rect2;
509 ok_rect(rectResult, rect1);
510
511 rect1 += sz;
512 rectResult = CRect(100, 50, 400, 350);
513 ok_rect(rectResult, rect1);
514
515 rect1 += &test;
516 rectResult = CRect(65, -100, 410, 375);
517 ok_rect(rectResult, rect1);
518
519 rect1 -= sz;
520 rectResult = CRect(-35, -150, 310, 325);
521 ok_rect(rectResult, rect1);
522
523 rect1 -= &test;
524 rectResult = CRect(0, 0, 300, 300);
525 ok_rect(rectResult, rect1);
526
527 rect2 = rect1 + sz;
528 rectResult = CRect(100, 50, 400, 350);
529 ok_rect(rectResult, rect2);
530
531 rect2 = rect1 - sz;
532 rectResult = CRect(-100, -50, 200, 250);
533 ok_rect(rectResult, rect2);
534
535 SetRect(&rect2, 10, 20, 300, 120);
536 rect2.MoveToX(30);
537 rectResult = CRect(30, 20, 320, 120);
538 ok_rect(rectResult, rect2);
539
540 SetRect(&rect2, 10, 20, 300, 120);
541 rect2.MoveToY(40);
542 rectResult = CRect(10, 40, 300, 140);
543 ok_rect(rectResult, rect2);
544
545 SetRect(&rect2, 10, 20, 300, 120);
546 rect2.MoveToXY(30, 40);
547 rectResult = CRect(30, 40, 320, 140);
548 ok_rect(rectResult, rect2);
549
550 SetRect(&rect2, 100, 80, -100, -50);
551 rectResult = CRect(-100, -50, 100, 80);
552 rect2.NormalizeRect();
553 ok_rect(rectResult, rect2);
554
555 rect2.SetRectEmpty();
556 rectResult = CRect(0, 0, 0, 0);
557 ok_rect(rectResult, rect2);
558
559 BOOL ret;
560
561 rect1 = CRect(5, 40, 40, 120);
562 rect2 = CRect(10, 30, 80, 100);
563 ret = rect.SubtractRect(rect1, rect2);
564 rectResult = CRect(10, 30, 80, 100);
565 ok_int(ret, TRUE);
566 ok_rect(rectResult, rect2);
567
568 rect1 = CRect(10, 40, 70, 110);
569 rect2 = CRect(8, 20, 40, 130);
570 ret = rect.SubtractRect(rect1, rect2);
571 rectResult = CRect(8, 20, 40, 130);
572 ok_int(ret, TRUE);
573 ok_rect(rect2, rectResult);
574}
575
576
577START_TEST(atltypes)
578{
579 test_CSize();
580 test_CPoint();
581 test_CRect();
582}
POINT ptStart
Definition: appswitch.c:60
#define ok(value,...)
Definition: atltest.h:57
static const char * wine_dbgstr_size(const SIZE *psize)
Definition: atltest.h:155
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
static const char * wine_dbgstr_rect(const RECT *prc)
Definition: atltest.h:160
#define ok_size(x, y)
Definition: atltypes.cpp:19
#define nok_point(x, y)
Definition: atltypes.cpp:24
#define ok_point(x, y)
Definition: atltypes.cpp:22
static void test_CSize()
Definition: atltypes.cpp:33
static void test_CPoint()
Definition: atltypes.cpp:147
#define nok_rect(x, y)
Definition: atltypes.cpp:29
#define ok_rect(x, y)
Definition: atltypes.cpp:27
static void test_CRect()
Definition: atltypes.cpp:288
BOOL IsRectNull() const noexcept
Definition: atltypes.h:356
BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2) noexcept
Definition: atltypes.h:346
void CopyRect(LPCRECT lpSrcRect) noexcept
Definition: atltypes.h:284
BOOL IsRectEmpty() const noexcept
Definition: atltypes.h:351
BOOL EqualRect(LPCRECT lpRect) const noexcept
Definition: atltypes.h:312
#define TRUE
Definition: types.h:120
static const WCHAR empty[]
Definition: main.c:47
#define pt(x, y)
Definition: drawing.c:79
RECT rect2
Definition: edittest.c:51
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLuint res
Definition: glext.h:9613
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
BOOL expected
Definition: store.c:2063
#define test
Definition: rosglue.h:37
& rect
Definition: startmenu.cpp:1413
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define MAKELONG(a, b)
Definition: typedefs.h:249
int ret
#define LPCRECT
Definition: precomp.h:29
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)