[ATL][ATL_APITEST] Add implementation + tests for most functions from CPoint, CSize...
[reactos.git] / rostests / apitests / atl / atltypes.cpp
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 #include <apitest.h>
11 #include <windows.h>
12 #include <atltypes.h>
13
14
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))
17
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))
22
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))
27
28
29 static void test_CSize()
30 {
31 CSize empty;
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);
34
35 CSize szPointA(10, 25);
36
37 SIZE sz;
38 sz.cx = 10;
39 sz.cy = 25;
40 CSize szPointB(sz);
41
42 POINT pt;
43 pt.x = 10;
44 pt.y = 25;
45 CSize szPointC(pt);
46
47 CPoint ptObject(10, 25);
48 CSize szPointD(ptObject);
49
50 DWORD dw = MAKELONG(10, 25);
51 CSize szPointE(dw);
52
53 ok_size(szPointA, szPointB);
54 ok_size(szPointB, szPointC);
55 ok_size(szPointC, szPointD);
56 ok_size(szPointD, szPointE);
57
58 ptObject = szPointA + pt;
59 CPoint res(20,50);
60 ok_point(ptObject, res);
61
62 ptObject = szPointA - pt;
63 res = CPoint(0, 0);
64 ok_point(ptObject, res);
65
66 CSize sz1(135, 135);
67 CSize sz2(135, 135);
68 ok_size(sz1, sz2);
69
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));
73
74 sz1 = CSize(100, 100);
75 sz2 = CSize(50, 25);
76 sz1 += sz2;
77
78 CSize szResult(150, 125);
79 ok_size(sz1, szResult);
80
81 sz1 = CSize(100, 100);
82 SIZE sz3;
83 sz3.cx = 50;
84 sz3.cy = 25;
85
86 sz1 += sz3;
87 ok_size(sz1, szResult);
88
89 sz1 = CSize(100, 100);
90 sz1 -= sz2;
91
92 szResult = CSize(50, 75);
93 ok_size(sz1, szResult);
94
95 sz3.cx = 50;
96 sz3.cy = 25;
97
98 sz1 = CSize(100, 100);
99 sz1 -= sz3;
100 ok_size(sz1, szResult);
101
102 sz1 = CSize(100, 100);
103 CSize szOut;
104 szOut = sz1 + sz2;
105
106 szResult = CSize(150, 125);
107 ok_size(szOut, szResult);
108
109 sz3.cx = 50;
110 sz3.cy = 25;
111
112 szOut = sz1 + sz3;
113 ok_size(szOut, szResult);
114
115 szOut = sz1 - sz2;
116
117 szResult = CSize(50, 75);
118 ok_size(szOut, szResult);
119
120 sz3.cx = 50;
121 sz3.cy = 25;
122
123 szOut = sz1 - sz3;
124 ok_size(szOut, szResult);
125
126 szResult = CSize(-50, -75);
127
128 szOut = -szOut;
129 ok_size(szOut, szResult);
130
131 RECT rc = { 1, 2, 3, 4 };
132
133 CRect rcres = sz1 + &rc;
134 CRect rcexp(101, 102, 103, 104);
135 ok_rect(rcexp, rcres);
136
137 rcres = sz1 - &rc;
138 rcexp = CRect(-99, -98, -97, -96);
139 ok_rect(rcexp, rcres);
140 }
141
142
143 static void test_CPoint()
144 {
145 CPoint empty;
146
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);
149
150 CPoint ptTopLeft(0, 0);
151 POINT ptHere;
152 ptHere.x = 35;
153 ptHere.y = 95;
154
155 CPoint ptMFCHere(ptHere);
156
157 SIZE sHowBig;
158 sHowBig.cx = 300;
159 sHowBig.cy = 10;
160
161 CPoint ptMFCBig(sHowBig);
162 DWORD dwSize;
163 dwSize = MAKELONG(35, 95);
164
165 CPoint ptFromDouble(dwSize);
166 ok_point(ptFromDouble, ptMFCHere);
167
168 CPoint ptStart(100, 100);
169 ptStart.Offset(35, 35);
170
171 CPoint ptResult(135, 135);
172 ok_point(ptStart, ptResult);
173
174 ptStart = CPoint(100, 100);
175 POINT pt;
176
177 pt.x = 35;
178 pt.y = 35;
179
180 ptStart.Offset(pt);
181 ok_point(ptStart, ptResult);
182
183 ptStart = CPoint(100, 100);
184 SIZE size;
185
186 size.cx = 35;
187 size.cy = 35;
188
189 ptStart.Offset(size);
190 ok_point(ptStart, ptResult);
191
192 CPoint ptFirst(256, 128);
193 CPoint ptTest(256, 128);
194 ok_point(ptFirst, ptTest);
195
196 pt.x = 256;
197 pt.y = 128;
198 ok_point(ptTest, pt);
199
200 ptTest = CPoint(111, 333);
201 nok_point(ptFirst, ptTest);
202
203 pt.x = 333;
204 pt.y = 111;
205 nok_point(ptTest, pt);
206
207 ptStart = CPoint(100, 100);
208 CSize szOffset(35, 35);
209
210 ptStart += szOffset;
211
212 ok_point(ptResult, ptStart);
213
214 ptStart = CPoint(100, 100);
215
216 ptStart += size;
217 ok_point(ptResult, ptStart);
218
219 ptStart = CPoint(100, 100);
220
221 ptStart -= szOffset;
222
223 ptResult = CPoint(65, 65);
224 ok_point(ptResult, ptStart);
225
226
227 ptStart = CPoint(100, 100);
228
229 ptStart -= size;
230 ok_point(ptResult, ptStart);
231
232 ptStart = CPoint(100, 100);
233 CPoint ptEnd;
234
235 ptEnd = ptStart + szOffset;
236
237 ptResult = CPoint(135, 135);
238 ok_point(ptResult, ptEnd);
239
240 ptEnd = ptStart + size;
241 ok_point(ptResult, ptEnd);
242
243 ptEnd = ptStart + pt;
244 ptResult = CPoint(433, 211);
245 ok_point(ptResult, ptEnd);
246
247 ptEnd = ptStart - szOffset;
248 ptResult = CPoint(65, 65);
249 ok_point(ptResult, ptEnd);
250
251 ptEnd = ptStart - size;
252 ok_point(ptResult, ptEnd);
253
254 szOffset = ptStart - pt;
255 CSize expected(-233, -11);
256 ok_size(szOffset, expected);
257
258 ptStart += pt;
259 ptResult = CPoint(433, 211);
260 ok_point(ptResult, ptStart);
261
262 ptStart -= pt;
263 ptResult = CPoint(100, 100);
264 ok_point(ptResult, ptStart);
265
266 ptTest = CPoint(35, 35);
267 ptTest = -ptTest;
268
269 CPoint ptNeg(-35, -35);
270 ok_point(ptTest, ptNeg);
271
272 RECT rc = { 1, 2, 3, 4 };
273
274 CRect rcres = ptStart + &rc;
275 CRect rcexp(101, 102, 103, 104);
276 ok_rect(rcexp, rcres);
277
278 rcres = ptStart - &rc;
279 rcexp = CRect(-99, -98, -97, -96);
280 ok_rect(rcexp, rcres);
281 }
282
283
284 static void test_CRect()
285 {
286 CRect empty;
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());
291
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());
295
296 RECT sdkRect;
297 sdkRect.left = 0;
298 sdkRect.top = 0;
299 sdkRect.right = 100;
300 sdkRect.bottom = 50;
301
302 CRect rect2(sdkRect);
303 CRect rect3(&sdkRect);
304 ok_rect(rect2, rect);
305 ok_rect(rect3, rect);
306
307 CPoint pt(0, 0);
308 CSize sz(100, 50);
309 CRect rect4(pt, sz);
310 ok_rect(rect4, rect2);
311
312 CPoint ptBottomRight(100, 50);
313 CRect rect5(pt, ptBottomRight);
314 ok_rect(rect5, rect4);
315
316 rect = CRect(210, 150, 350, 900);
317 CPoint ptDown;
318
319 ptDown = rect.BottomRight();
320
321 pt = CPoint(350, 900);
322 ok_point(ptDown, pt);
323
324 rect2 = CRect(10, 10, 350, 350);
325 CPoint ptLow(180, 180);
326
327 rect2.BottomRight() = ptLow;
328
329 rect = CRect(10, 10, 180, 180);
330 ok_rect(rect2, rect);
331
332 pt = CPoint(95, 95);
333 CPoint pt2 = rect2.CenterPoint();
334 ok_point(pt2, pt);
335
336 pt2 = rect2.BottomRight();
337 pt = CPoint(180, 180);
338 ok_point(pt2, pt);
339
340 pt2 = rect2.TopLeft();
341 pt = CPoint(10, 10);
342 ok_point(pt2, pt);
343
344 rect2.TopLeft().Offset(3, 3);
345 rect3 = CRect(13, 13, 180, 180);
346 ok_rect(rect3, rect2);
347
348 CRect rectSource(35, 10, 125, 10);
349 CRect rectDest;
350
351 rectDest.CopyRect(&rectSource);
352
353 RECT rectSource2;
354 rectSource2.left = 0;
355 rectSource2.top = 0;
356 rectSource2.bottom = 480;
357 rectSource2.right = 640;
358
359 rectDest.CopyRect(&rectSource2);
360
361 rect = CRect(10, 10, 50, 50);
362
363 rect.DeflateRect(1, 2);
364
365 rect2 = CRect(11, 12, 49, 48);
366 ok_rect(rect2, rect);
367
368 rect2 = CRect(10, 10, 50, 50);
369 CRect rectDeflate(1, 2, 3, 4);
370
371 rect2.DeflateRect(&rectDeflate);
372 rect = CRect(11, 12, 47, 46);
373 ok_rect(rect2, rect);
374
375 rect2.DeflateRect(sz);
376 rect = CRect(111, 62, -53, -4);
377 ok_rect(rect2, rect);
378
379 rect2.OffsetRect(sz);
380 rect = CRect(211, 112, 47, 46);
381 ok_rect(rect2, rect);
382
383 CRect rect1(35, 150, 10, 25);
384 rect2 = CRect(35, 150, 10, 25);
385 rect3 = CRect(98, 999, 6, 3);
386
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));
389
390 RECT test;
391 test.left = 35;
392 test.top = 150;
393 test.right = 10;
394 test.bottom = 25;
395
396 ok(rect1.EqualRect(&test), "Expected EqualRect to return TRUE for %s, %s\n", wine_dbgstr_rect(&rect1), wine_dbgstr_rect(&test));
397
398 rect = test;
399 rect2 = CRect(35, 150, 10, 25);
400 ok_rect(rect, rect2);
401
402 rect = CRect(0, 0, 300, 300);
403 rect.InflateRect(50, 200);
404
405 rect2 = CRect(-50, -200, 350, 500);
406 ok_rect(rect, rect2);
407
408 rect.InflateRect(sz);
409 rect2 = CRect(-150, -250, 450, 550);
410 ok_rect(rect, rect2);
411
412 rect = CRect(20, 30, 80, 70);
413
414 int nHt = rect.Height();
415
416 ok(nHt == 40, "Expected nHt to be 40, was %i\n", nHt);
417
418 CRect rectOne(125, 0, 150, 200);
419 CRect rectTwo(0, 75, 350, 95);
420 CRect rectInter;
421
422 rectInter.IntersectRect(rectOne, rectTwo);
423
424 rect = CRect(125, 75, 150, 95);
425 ok_rect(rectInter, rect);
426
427 CRect rectInter2 = rectOne;
428 rectInter2 &= rectTwo;
429 rect = CRect(125, 75, 150, 95);
430 ok_rect(rectInter2, rect);
431
432 CRect rectNone(0, 0, 0, 0);
433 CRect rectSome(35, 50, 135, 150);
434
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));
437
438 CRect rectEmpty(35, 35, 35, 35);
439 ok(rectEmpty.IsRectEmpty(), "Expected IsRectEmpty to return TRUE for %s\n", wine_dbgstr_rect(&rectEmpty));
440
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));
443
444 CRect rectNotNull(0, 0, 35, 50);
445 ok(!rectNotNull.IsRectNull(), "Expected IsRectNull to return FALSE for %s\n", wine_dbgstr_rect(&rectNotNull));
446
447 rect1 = CRect(35, 150, 10, 25);
448 rect2 = CRect(35, 150, 10, 25);
449 rect3 = CRect(98, 999, 6, 3);
450
451 ok_rect(rect1, rect2);
452
453 test.left = 35;
454 test.top = 150;
455 test.right = 10;
456 test.bottom = 25;
457
458 ok_rect(rect1, test);
459
460 nok_rect(rect1, rect3);
461 nok_rect(rect3, test);
462
463 rect1 = CRect(100, 235, 200, 335);
464 pt = CPoint(35, 65);
465 rect2 = CRect(135, 300, 235, 400);
466
467 rect1 += pt;
468
469 ok_rect(rect1, rect2);
470
471 rect1 = CRect(100, 235, 200, 335);
472 rect2 = rect1 + pt;
473 CRect rectResult(135, 300, 235, 400);
474 ok_rect(rectResult, rect2);
475
476 rect2 = rect1 + &test;
477 rectResult = CRect(65, 85, 210, 360);
478 ok_rect(rectResult, rect2);
479
480 rect2 = rect1 - (LPCRECT)&test;
481 rectResult = CRect(135, 385, 190, 310);
482 ok_rect(rectResult, rect2);
483
484 rect2 = rect1 - pt;
485 rectResult = CRect(65, 170, 165, 270);
486
487 ok_rect(rect2, rectResult);
488
489 rect1 -= pt;
490 ok_rect(rect1, rectResult);
491
492 rect1 = CRect(100, 0, 200, 300);
493 rect2 = CRect(0, 100, 300, 200);
494
495 rect3 = rect1 & rect2;
496
497 rectResult = CRect(100, 100, 200, 200);
498 ok_rect(rectResult, rect3);
499
500 rect3 = rect1 | rect2;
501 rectResult = CRect(0, 0, 300, 300);
502 ok_rect(rectResult, rect3);
503
504 rect1 |= rect2;
505 ok_rect(rectResult, rect1);
506
507 rect1 += sz;
508 rectResult = CRect(100, 50, 400, 350);
509 ok_rect(rectResult, rect1);
510
511 rect1 += &test;
512 rectResult = CRect(65, -100, 410, 375);
513 ok_rect(rectResult, rect1);
514
515 rect1 -= sz;
516 rectResult = CRect(-35, -150, 310, 325);
517 ok_rect(rectResult, rect1);
518
519 rect1 -= &test;
520 rectResult = CRect(0, 0, 300, 300);
521 ok_rect(rectResult, rect1);
522
523 rect2 = rect1 + sz;
524 rectResult = CRect(100, 50, 400, 350);
525 ok_rect(rectResult, rect2);
526
527 rect2 = rect1 - sz;
528 rectResult = CRect(-100, -50, 200, 250);
529 ok_rect(rectResult, rect2);
530 }
531
532
533 START_TEST(atltypes)
534 {
535 test_CSize();
536 test_CPoint();
537 test_CRect();
538 }