ReactOS 0.4.15-dev-5666-gc548b97
graphics.c
Go to the documentation of this file.
1/*
2 * Unit test suite for graphics objects
3 *
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22#include <math.h>
23
24#include "objbase.h"
25#include "gdiplus.h"
26#include "wine/test.h"
27
28#define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (INT)(expected), (INT)(got))
29#define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
30#define expectf(expected, got) expectf_((expected), (got), 0.001)
31
32static GpStatus (WINAPI *pGdipGraphicsSetAbort)(GpGraphics*,GdiplusAbort*);
33
34static const REAL mm_per_inch = 25.4;
35static const REAL point_per_inch = 72.0;
36static HWND hwnd;
37
38static void set_rect_empty(RectF *rc)
39{
40 rc->X = 0.0;
41 rc->Y = 0.0;
42 rc->Width = 0.0;
43 rc->Height = 0.0;
44}
45
46/* converts a given unit to its value in pixels */
48{
49 switch (unit)
50 {
51 case UnitPixel:
52 case UnitDisplay:
53 return units;
54 case UnitPoint:
55 return units * dpi / point_per_inch;
56 case UnitInch:
57 return units * dpi;
58 case UnitDocument:
59 return units * dpi / 300.0; /* Per MSDN */
60 case UnitMillimeter:
61 return units * dpi / mm_per_inch;
62 default:
63 ok(0, "Unsupported unit: %d\n", unit);
64 return 0;
65 }
66}
67
68/* converts value in pixels to a given unit */
70{
71 switch (unit)
72 {
73 case UnitPixel:
74 case UnitDisplay:
75 return pixels;
76 case UnitPoint:
77 return pixels * point_per_inch / dpi;
78 case UnitInch:
79 return pixels / dpi;
80 case UnitDocument:
81 return pixels * 300.0 / dpi;
82 case UnitMillimeter:
83 return pixels * mm_per_inch / dpi;
84 default:
85 ok(0, "Unsupported unit: %d\n", unit);
86 return 0;
87 }
88}
89
91{
93 return pixels_to_units(pixels, to, dpi);
94}
95
97{
99 union
100 {
102 GpImage *image;
103 } u;
104 GpGraphics *graphics = NULL;
105 REAL res;
106
108 expect(Ok, status);
109
110 status = GdipBitmapSetResolution(u.bitmap, res_x, res_y);
111 expect(Ok, status);
113 expect(Ok, status);
114 expectf(res_x, res);
116 expect(Ok, status);
117 expectf(res_y, res);
118
119 status = GdipGetImageGraphicsContext(u.image, &graphics);
120 expect(Ok, status);
121
122 *image = u.image;
123
124 status = GdipGetDpiX(graphics, &res);
125 expect(Ok, status);
126 expectf(res_x, res);
127 status = GdipGetDpiY(graphics, &res);
128 expect(Ok, status);
129 expectf(res_y, res);
130
131 status = GdipSetPageUnit(graphics, unit);
132 expect(Ok, status);
133 status = GdipSetPageScale(graphics, scale);
134 expect(Ok, status);
135
136 return graphics;
137}
138
140{
142 GpGraphics *graphics = NULL;
143 HDC hdc = GetDC( hwnd );
144
145 stat = GdipCreateFromHDC(NULL, &graphics);
147 stat = GdipDeleteGraphics(graphics);
149
150 stat = GdipCreateFromHDC(hdc, &graphics);
151 expect(Ok, stat);
152 stat = GdipDeleteGraphics(graphics);
153 expect(Ok, stat);
154
155 stat = GdipCreateFromHWND(NULL, &graphics);
156 expect(Ok, stat);
157 stat = GdipDeleteGraphics(graphics);
158 expect(Ok, stat);
159
160 stat = GdipCreateFromHWNDICM(NULL, &graphics);
161 expect(Ok, stat);
162 stat = GdipDeleteGraphics(graphics);
163 expect(Ok, stat);
164
168}
169
170typedef struct node{
172 struct node * next;
174
175/* Linked list prepend function. */
177{
178 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
179
180 new_entry->data = data;
181 new_entry->next = *log;
182 *log = new_entry;
183}
184
185/* Checks if there are duplicates in the list, and frees it. */
187{
188 INT dups = 0;
189 node * temp = NULL;
190 node * temp2 = NULL;
191 node * orig = log;
192
193 if(!log)
194 goto end;
195
196 do{
197 temp = log;
198 while((temp = temp->next)){
199 if(log->data == temp->data){
200 dups++;
201 break;
202 }
203 if(dups > 0)
204 break;
205 }
206 }while((log = log->next));
207
208 temp = orig;
209 do{
210 temp2 = temp->next;
212 temp = temp2;
213 }while(temp);
214
215end:
216 expect(0, dups);
217}
218
219static void test_save_restore(void)
220{
222 GraphicsState state_a, state_b, state_c;
224 GpGraphics *graphics1, *graphics2;
225 node * state_log = NULL;
226 HDC hdc = GetDC( hwnd );
227 state_a = state_b = state_c = 0xdeadbeef;
228
229 /* Invalid saving. */
230 GdipCreateFromHDC(hdc, &graphics1);
231 stat = GdipSaveGraphics(graphics1, NULL);
233 stat = GdipSaveGraphics(NULL, &state_a);
235 GdipDeleteGraphics(graphics1);
236
237 log_state(state_a, &state_log);
238
239 /* Basic save/restore. */
240 GdipCreateFromHDC(hdc, &graphics1);
242 stat = GdipSaveGraphics(graphics1, &state_a);
243 expect(Ok, stat);
245 stat = GdipRestoreGraphics(graphics1, state_a);
246 expect(Ok, stat);
247 GdipGetInterpolationMode(graphics1, &mode);
249 GdipDeleteGraphics(graphics1);
250
251 log_state(state_a, &state_log);
252
253 /* Restoring garbage doesn't affect saves. */
254 GdipCreateFromHDC(hdc, &graphics1);
256 GdipSaveGraphics(graphics1, &state_a);
258 GdipSaveGraphics(graphics1, &state_b);
260 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
261 expect(Ok, stat);
262 GdipRestoreGraphics(graphics1, state_b);
263 GdipGetInterpolationMode(graphics1, &mode);
265 GdipRestoreGraphics(graphics1, state_a);
266 GdipGetInterpolationMode(graphics1, &mode);
268 GdipDeleteGraphics(graphics1);
269
270 log_state(state_a, &state_log);
271 log_state(state_b, &state_log);
272
273 /* Restoring older state invalidates newer saves (but not older saves). */
274 GdipCreateFromHDC(hdc, &graphics1);
276 GdipSaveGraphics(graphics1, &state_a);
278 GdipSaveGraphics(graphics1, &state_b);
280 GdipSaveGraphics(graphics1, &state_c);
282 GdipRestoreGraphics(graphics1, state_b);
283 GdipGetInterpolationMode(graphics1, &mode);
285 GdipRestoreGraphics(graphics1, state_c);
286 GdipGetInterpolationMode(graphics1, &mode);
288 GdipRestoreGraphics(graphics1, state_a);
289 GdipGetInterpolationMode(graphics1, &mode);
291 GdipDeleteGraphics(graphics1);
292
293 log_state(state_a, &state_log);
294 log_state(state_b, &state_log);
295 log_state(state_c, &state_log);
296
297 /* Restoring older save from one graphics object does not invalidate
298 * newer save from other graphics object. */
299 GdipCreateFromHDC(hdc, &graphics1);
300 GdipCreateFromHDC(hdc, &graphics2);
302 GdipSaveGraphics(graphics1, &state_a);
304 GdipSaveGraphics(graphics2, &state_b);
307 GdipRestoreGraphics(graphics1, state_a);
308 GdipGetInterpolationMode(graphics1, &mode);
310 GdipRestoreGraphics(graphics2, state_b);
311 GdipGetInterpolationMode(graphics2, &mode);
313 GdipDeleteGraphics(graphics1);
314 GdipDeleteGraphics(graphics2);
315
316 /* You can't restore a state to a graphics object that didn't save it. */
317 GdipCreateFromHDC(hdc, &graphics1);
318 GdipCreateFromHDC(hdc, &graphics2);
320 GdipSaveGraphics(graphics1, &state_a);
323 GdipRestoreGraphics(graphics2, state_a);
324 GdipGetInterpolationMode(graphics2, &mode);
326 GdipDeleteGraphics(graphics1);
327 GdipDeleteGraphics(graphics2);
328
329 log_state(state_a, &state_log);
330
331 /* A state created by SaveGraphics cannot be restored with EndContainer. */
332 GdipCreateFromHDC(hdc, &graphics1);
334 stat = GdipSaveGraphics(graphics1, &state_a);
335 expect(Ok, stat);
337 stat = GdipEndContainer(graphics1, state_a);
338 expect(Ok, stat);
339 GdipGetInterpolationMode(graphics1, &mode);
341 stat = GdipRestoreGraphics(graphics1, state_a);
342 expect(Ok, stat);
343 GdipGetInterpolationMode(graphics1, &mode);
345 GdipDeleteGraphics(graphics1);
346
347 log_state(state_a, &state_log);
348
349 /* A state created by BeginContainer cannot be restored with RestoreGraphics. */
350 stat = GdipCreateFromHDC(hdc, &graphics1);
351 expect(Ok, stat);
353 stat = GdipBeginContainer2(graphics1, &state_a);
354 expect(Ok, stat);
356 stat = GdipRestoreGraphics(graphics1, state_a);
357 expect(Ok, stat);
358 GdipGetInterpolationMode(graphics1, &mode);
360 stat = GdipEndContainer(graphics1, state_a);
361 expect(Ok, stat);
362 GdipGetInterpolationMode(graphics1, &mode);
364 GdipDeleteGraphics(graphics1);
365
366 log_state(state_a, &state_log);
367
368 /* BeginContainer and SaveGraphics use the same stack. */
369 stat = GdipCreateFromHDC(hdc, &graphics1);
370 expect(Ok, stat);
372 stat = GdipBeginContainer2(graphics1, &state_a);
373 expect(Ok, stat);
375 stat = GdipSaveGraphics(graphics1, &state_b);
376 expect(Ok, stat);
378 stat = GdipEndContainer(graphics1, state_a);
379 expect(Ok, stat);
380 GdipGetInterpolationMode(graphics1, &mode);
382 stat = GdipRestoreGraphics(graphics1, state_b);
383 expect(Ok, stat);
384 GdipGetInterpolationMode(graphics1, &mode);
386 GdipDeleteGraphics(graphics1);
387
388 log_state(state_a, &state_log);
389 log_state(state_b, &state_log);
390
391 /* The same state value should never be returned twice. */
393 check_no_duplicates(state_log);
394
396}
397
399{
401 GpGraphics *graphics = NULL;
402 GpSolidFill *brush = NULL;
403 HDC hdc = GetDC( hwnd );
404 GpPointF points[3];
405
406 points[0].X = 0;
407 points[0].Y = 0;
408
409 points[1].X = 40;
410 points[1].Y = 20;
411
412 points[2].X = 10;
413 points[2].Y = 40;
414
415 /* make a graphics object and brush object */
416 ok(hdc != NULL, "Expected HDC to be initialized\n");
417
418 status = GdipCreateFromHDC(hdc, &graphics);
419 expect(Ok, status);
420 ok(graphics != NULL, "Expected graphics to be initialized\n");
421
422 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
423
424 /* InvalidParameter cases: null graphics, null brush, null points */
427
430
433
436
437 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
439
442
445
446 /* InvalidParameter cases: invalid count */
447 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
449
450 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
452
453 /* Valid test cases */
454 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
455 expect(Ok, status);
456
457 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
458 expect(Ok, status);
459
460 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
461 expect(Ok, status);
462
463 GdipDeleteGraphics(graphics);
464 GdipDeleteBrush((GpBrush*)brush);
465
467}
468
470{
472 GpGraphics *graphics = NULL;
473 GpSolidFill *brush = NULL;
474 HDC hdc = GetDC( hwnd );
475 GpPoint points[3];
476
477 points[0].X = 0;
478 points[0].Y = 0;
479
480 points[1].X = 40;
481 points[1].Y = 20;
482
483 points[2].X = 10;
484 points[2].Y = 40;
485
486 /* make a graphics object and brush object */
487 ok(hdc != NULL, "Expected HDC to be initialized\n");
488
489 status = GdipCreateFromHDC(hdc, &graphics);
490 expect(Ok, status);
491 ok(graphics != NULL, "Expected graphics to be initialized\n");
492
493 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
494
495 /* InvalidParameter cases: null graphics, null brush */
496 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
497 when points == NULL, so don't test this condition */
500
503
506
507 /* InvalidParameter cases: invalid count */
508 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
510
511 /* OutOfMemory cases: large (unsigned) int */
512 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
514
515 /* Valid test cases */
516 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
517 expect(Ok, status);
518
519 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
520 expect(Ok, status);
521
522 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
523 expect(Ok, status);
524
525 GdipDeleteGraphics(graphics);
526 GdipDeleteBrush((GpBrush*)brush);
527
529}
530
531static void test_GdipDrawArc(void)
532{
534 GpGraphics *graphics = NULL;
535 GpPen *pen = NULL;
536 HDC hdc = GetDC( hwnd );
537
538 /* make a graphics object and pen object */
539 ok(hdc != NULL, "Expected HDC to be initialized\n");
540
541 status = GdipCreateFromHDC(hdc, &graphics);
542 expect(Ok, status);
543 ok(graphics != NULL, "Expected graphics to be initialized\n");
544
545 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
546 expect(Ok, status);
547 ok(pen != NULL, "Expected pen to be initialized\n");
548
549 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
550 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
552
553 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
555
556 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
558
559 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
561
562 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
564
565 /* successful case */
566 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
567 expect(Ok, status);
568
569 GdipDeletePen(pen);
570 GdipDeleteGraphics(graphics);
571
573}
574
575static void test_GdipDrawArcI(void)
576{
578 GpGraphics *graphics = NULL;
579 GpPen *pen = NULL;
580 HDC hdc = GetDC( hwnd );
581
582 /* make a graphics object and pen object */
583 ok(hdc != NULL, "Expected HDC to be initialized\n");
584
585 status = GdipCreateFromHDC(hdc, &graphics);
586 expect(Ok, status);
587 ok(graphics != NULL, "Expected graphics to be initialized\n");
588
589 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
590 expect(Ok, status);
591 ok(pen != NULL, "Expected pen to be initialized\n");
592
593 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
594 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
596
597 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
599
600 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
602
603 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
605
606 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
608
609 /* successful case */
610 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
611 expect(Ok, status);
612
613 GdipDeletePen(pen);
614 GdipDeleteGraphics(graphics);
615
617}
618
619static void test_BeginContainer2(void)
620{
622 GpRectF clip;
623 REAL defClip[] = {5, 10, 15, 20};
624 REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
625 GraphicsContainer cont1, cont2, cont3, cont4;
626 CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
627 CompositingMode compmode, defCompmode = CompositingModeSourceOver;
629 REAL scale, defScale = 17;
630 GpUnit unit, defUnit = UnitPixel;
631 PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
632 SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
633 UINT contrast, defContrast = 5;
634 TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
635
637 GpGraphics *graphics = NULL;
638 HDC hdc = GetDC( hwnd );
639
640 ok(hdc != NULL, "Expected HDC to be initialized\n");
641
642 status = GdipCreateFromHDC(hdc, &graphics);
643 expect(Ok, status);
644 ok(graphics != NULL, "Expected graphics to be initialized\n");
645
646 /* null graphics, null container */
649
650 status = GdipBeginContainer2(graphics, NULL);
652
653 status = GdipEndContainer(NULL, cont1);
655
656 /* test all quality-related values */
657 GdipSetCompositingMode(graphics, defCompmode);
658 GdipSetCompositingQuality(graphics, defCompqual);
659 GdipSetInterpolationMode(graphics, defInterp);
660 GdipSetPageScale(graphics, defScale);
661 GdipSetPageUnit(graphics, defUnit);
662 GdipSetPixelOffsetMode(graphics, defOffsetmode);
663 GdipSetSmoothingMode(graphics, defSmoothmode);
664 GdipSetTextContrast(graphics, defContrast);
665 GdipSetTextRenderingHint(graphics, defTexthint);
666
667 status = GdipBeginContainer2(graphics, &cont1);
668 expect(Ok, status);
669
673 GdipSetPageScale(graphics, 10);
674 GdipSetPageUnit(graphics, UnitDocument);
677 GdipSetTextContrast(graphics, 7);
679
680 status = GdipEndContainer(graphics, cont1);
681 expect(Ok, status);
682
683 GdipGetCompositingMode(graphics, &compmode);
684 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
685
686 GdipGetCompositingQuality(graphics, &compqual);
687 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
688
690 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
691
692 GdipGetPageScale(graphics, &scale);
693 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
694
695 GdipGetPageUnit(graphics, &unit);
696 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
697
698 GdipGetPixelOffsetMode(graphics, &offsetmode);
699 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
700
701 GdipGetSmoothingMode(graphics, &smoothmode);
702 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
703
704 GdipGetTextContrast(graphics, &contrast);
705 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
706
707 status = GdipGetTextRenderingHint(graphics, &texthint);
708 expect(Ok, status);
709 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
710
711 /* test world transform */
712 status = GdipBeginContainer2(graphics, &cont1);
713 expect(Ok, status);
714
715 status = GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
716 defTrans[4], defTrans[5], &transform);
717 expect(Ok, status);
720 transform = NULL;
721
722 status = GdipBeginContainer2(graphics, &cont2);
723 expect(Ok, status);
724
725 status = GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
726 expect(Ok, status);
728 expect(Ok, status);
730 transform = NULL;
731
732 status = GdipEndContainer(graphics, cont2);
733 expect(Ok, status);
734
736 expect(Ok, status);
738 expect(Ok, status);
740 expect(Ok, status);
741 ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
742 fabs(defTrans[1] - elems[1]) < 0.0001 &&
743 fabs(defTrans[2] - elems[2]) < 0.0001 &&
744 fabs(defTrans[3] - elems[3]) < 0.0001 &&
745 fabs(defTrans[4] - elems[4]) < 0.0001 &&
746 fabs(defTrans[5] - elems[5]) < 0.0001,
747 "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
748 defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
749 elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
751 transform = NULL;
752
753 status = GdipEndContainer(graphics, cont1);
754 expect(Ok, status);
755
756 /* test clipping */
757 status = GdipBeginContainer2(graphics, &cont1);
758 expect(Ok, status);
759
760 status = GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
761 expect(Ok, status);
762
763 status = GdipBeginContainer2(graphics, &cont2);
764 expect(Ok, status);
765
766 status = GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
767 expect(Ok, status);
768
769 status = GdipEndContainer(graphics, cont2);
770 expect(Ok, status);
771
772 status = GdipGetClipBounds(graphics, &clip);
773 expect(Ok, status);
774
775 ok(fabs(defClip[0] - clip.X) < 0.0001 &&
776 fabs(defClip[1] - clip.Y) < 0.0001 &&
777 fabs(defClip[2] - clip.Width) < 0.0001 &&
778 fabs(defClip[3] - clip.Height) < 0.0001,
779 "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
780 defClip[0], defClip[1], defClip[2], defClip[3],
781 clip.X, clip.Y, clip.Width, clip.Height);
782
783 status = GdipEndContainer(graphics, cont1);
784 expect(Ok, status);
785
786 /* nesting */
787 status = GdipBeginContainer2(graphics, &cont1);
788 expect(Ok, status);
789
790 status = GdipBeginContainer2(graphics, &cont2);
791 expect(Ok, status);
792
793 status = GdipBeginContainer2(graphics, &cont3);
794 expect(Ok, status);
795
796 status = GdipEndContainer(graphics, cont3);
797 expect(Ok, status);
798
799 status = GdipBeginContainer2(graphics, &cont4);
800 expect(Ok, status);
801
802 status = GdipEndContainer(graphics, cont4);
803 expect(Ok, status);
804
805 /* skip cont2 */
806 status = GdipEndContainer(graphics, cont1);
807 expect(Ok, status);
808
809 /* end an already-ended container */
810 status = GdipEndContainer(graphics, cont1);
811 expect(Ok, status);
812
813 GdipDeleteGraphics(graphics);
815}
816
817static void test_GdipDrawBezierI(void)
818{
820 GpGraphics *graphics = NULL;
821 GpPen *pen = NULL;
822 HDC hdc = GetDC( hwnd );
823
824 /* make a graphics object and pen object */
825 ok(hdc != NULL, "Expected HDC to be initialized\n");
826
827 status = GdipCreateFromHDC(hdc, &graphics);
828 expect(Ok, status);
829 ok(graphics != NULL, "Expected graphics to be initialized\n");
830
831 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
832 expect(Ok, status);
833 ok(pen != NULL, "Expected pen to be initialized\n");
834
835 /* InvalidParameter cases: null graphics, null pen */
836 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
838
839 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
841
842 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
844
845 /* successful case */
846 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
847 expect(Ok, status);
848
849 GdipDeletePen(pen);
850 GdipDeleteGraphics(graphics);
851
853}
854
855static void test_GdipDrawCurve3(void)
856{
858 GpGraphics *graphics = NULL;
859 GpPen *pen = NULL;
860 HDC hdc = GetDC( hwnd );
861 GpPointF points[3];
862
863 points[0].X = 0;
864 points[0].Y = 0;
865
866 points[1].X = 40;
867 points[1].Y = 20;
868
869 points[2].X = 10;
870 points[2].Y = 40;
871
872 /* make a graphics object and pen object */
873 ok(hdc != NULL, "Expected HDC to be initialized\n");
874
875 status = GdipCreateFromHDC(hdc, &graphics);
876 expect(Ok, status);
877 ok(graphics != NULL, "Expected graphics to be initialized\n");
878
879 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
880 expect(Ok, status);
881 ok(pen != NULL, "Expected pen to be initialized\n");
882
883 /* InvalidParameter cases: null graphics, null pen */
884 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
886
887 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
889
890 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
892
893 /* InvalidParameter cases: invalid count */
894 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
896
897 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
899
900 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
902
903 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
905
906 /* InvalidParameter cases: invalid number of segments */
907 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
909
910 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
912
913 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
915
916 /* Valid test cases */
917 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
918 expect(Ok, status);
919
920 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
921 expect(Ok, status);
922
923 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
924 expect(Ok, status);
925
926 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
927 expect(Ok, status);
928
929 GdipDeletePen(pen);
930 GdipDeleteGraphics(graphics);
931
933}
934
935static void test_GdipDrawCurve3I(void)
936{
938 GpGraphics *graphics = NULL;
939 GpPen *pen = NULL;
940 HDC hdc = GetDC( hwnd );
941 GpPoint points[3];
942
943 points[0].X = 0;
944 points[0].Y = 0;
945
946 points[1].X = 40;
947 points[1].Y = 20;
948
949 points[2].X = 10;
950 points[2].Y = 40;
951
952 /* make a graphics object and pen object */
953 ok(hdc != NULL, "Expected HDC to be initialized\n");
954
955 status = GdipCreateFromHDC(hdc, &graphics);
956 expect(Ok, status);
957 ok(graphics != NULL, "Expected graphics to be initialized\n");
958
959 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
960 expect(Ok, status);
961 ok(pen != NULL, "Expected pen to be initialized\n");
962
963 /* InvalidParameter cases: null graphics, null pen */
964 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
966
967 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
969
970 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
972
973 /* InvalidParameter cases: invalid count */
974 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
976
977 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
979
980 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
982
983 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
985
986 /* InvalidParameter cases: invalid number of segments */
987 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
989
990 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
992
993 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
995
996 /* Valid test cases */
997 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
998 expect(Ok, status);
999
1000 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
1001 expect(Ok, status);
1002
1003 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
1004 expect(Ok, status);
1005
1006 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
1007 expect(Ok, status);
1008
1009 GdipDeletePen(pen);
1010 GdipDeleteGraphics(graphics);
1011
1012 ReleaseDC(hwnd, hdc);
1013}
1014
1015static void test_GdipDrawCurve2(void)
1016{
1018 GpGraphics *graphics = NULL;
1019 GpPen *pen = NULL;
1020 HDC hdc = GetDC( hwnd );
1021 GpPointF points[3];
1022
1023 points[0].X = 0;
1024 points[0].Y = 0;
1025
1026 points[1].X = 40;
1027 points[1].Y = 20;
1028
1029 points[2].X = 10;
1030 points[2].Y = 40;
1031
1032 /* make a graphics object and pen object */
1033 ok(hdc != NULL, "Expected HDC to be initialized\n");
1034
1035 status = GdipCreateFromHDC(hdc, &graphics);
1036 expect(Ok, status);
1037 ok(graphics != NULL, "Expected graphics to be initialized\n");
1038
1039 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1040 expect(Ok, status);
1041 ok(pen != NULL, "Expected pen to be initialized\n");
1042
1043 /* InvalidParameter cases: null graphics, null pen */
1046
1047 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
1049
1050 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
1052
1053 /* InvalidParameter cases: invalid count */
1054 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
1056
1057 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
1059
1060 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
1062
1063 /* Valid test cases */
1064 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
1065 expect(Ok, status);
1066
1067 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
1068 expect(Ok, status);
1069
1070 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
1071 expect(Ok, status);
1072
1073 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
1074 expect(Ok, status);
1075
1076 GdipDeletePen(pen);
1077 GdipDeleteGraphics(graphics);
1078
1079 ReleaseDC(hwnd, hdc);
1080}
1081
1082static void test_GdipDrawCurve2I(void)
1083{
1085 GpGraphics *graphics = NULL;
1086 GpPen *pen = NULL;
1087 HDC hdc = GetDC( hwnd );
1088 GpPoint points[3];
1089
1090 points[0].X = 0;
1091 points[0].Y = 0;
1092
1093 points[1].X = 40;
1094 points[1].Y = 20;
1095
1096 points[2].X = 10;
1097 points[2].Y = 40;
1098
1099 /* make a graphics object and pen object */
1100 ok(hdc != NULL, "Expected HDC to be initialized\n");
1101
1102 status = GdipCreateFromHDC(hdc, &graphics);
1103 expect(Ok, status);
1104 ok(graphics != NULL, "Expected graphics to be initialized\n");
1105
1106 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1107 expect(Ok, status);
1108 ok(pen != NULL, "Expected pen to be initialized\n");
1109
1110 /* InvalidParameter cases: null graphics, null pen */
1113
1114 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
1116
1117 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
1119
1120 /* InvalidParameter cases: invalid count */
1121 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
1123
1124 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
1126
1127 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
1129
1130 /* Valid test cases */
1131 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
1132 expect(Ok, status);
1133
1134 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
1135 expect(Ok, status);
1136
1137 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
1138 expect(Ok, status);
1139
1140 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
1141 expect(Ok, status);
1142
1143 GdipDeletePen(pen);
1144 GdipDeleteGraphics(graphics);
1145
1146 ReleaseDC(hwnd, hdc);
1147}
1148
1149static void test_GdipDrawCurve(void)
1150{
1152 GpGraphics *graphics = NULL;
1153 GpPen *pen = NULL;
1154 HDC hdc = GetDC( hwnd );
1155 GpPointF points[3];
1156
1157 points[0].X = 0;
1158 points[0].Y = 0;
1159
1160 points[1].X = 40;
1161 points[1].Y = 20;
1162
1163 points[2].X = 10;
1164 points[2].Y = 40;
1165
1166 /* make a graphics object and pen object */
1167 ok(hdc != NULL, "Expected HDC to be initialized\n");
1168
1169 status = GdipCreateFromHDC(hdc, &graphics);
1170 expect(Ok, status);
1171 ok(graphics != NULL, "Expected graphics to be initialized\n");
1172
1173 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1174 expect(Ok, status);
1175 ok(pen != NULL, "Expected pen to be initialized\n");
1176
1177 /* InvalidParameter cases: null graphics, null pen */
1180
1181 status = GdipDrawCurve(graphics, NULL, points, 3);
1183
1184 status = GdipDrawCurve(NULL, pen, points, 3);
1186
1187 /* InvalidParameter cases: invalid count */
1188 status = GdipDrawCurve(graphics, pen, points, -1);
1190
1191 status = GdipDrawCurve(graphics, pen, points, 0);
1193
1194 status = GdipDrawCurve(graphics, pen, points, 1);
1196
1197 /* Valid test cases */
1198 status = GdipDrawCurve(graphics, pen, points, 2);
1199 expect(Ok, status);
1200
1201 status = GdipDrawCurve(graphics, pen, points, 3);
1202 expect(Ok, status);
1203
1204 GdipDeletePen(pen);
1205 GdipDeleteGraphics(graphics);
1206
1207 ReleaseDC(hwnd, hdc);
1208}
1209
1210static void test_GdipDrawCurveI(void)
1211{
1213 GpGraphics *graphics = NULL;
1214 GpPen *pen = NULL;
1215 HDC hdc = GetDC( hwnd );
1216 GpPoint points[3];
1217
1218 points[0].X = 0;
1219 points[0].Y = 0;
1220
1221 points[1].X = 40;
1222 points[1].Y = 20;
1223
1224 points[2].X = 10;
1225 points[2].Y = 40;
1226
1227 /* make a graphics object and pen object */
1228 ok(hdc != NULL, "Expected HDC to be initialized\n");
1229
1230 status = GdipCreateFromHDC(hdc, &graphics);
1231 expect(Ok, status);
1232 ok(graphics != NULL, "Expected graphics to be initialized\n");
1233
1234 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1235 expect(Ok, status);
1236 ok(pen != NULL, "Expected pen to be initialized\n");
1237
1238 /* InvalidParameter cases: null graphics, null pen */
1241
1242 status = GdipDrawCurveI(graphics, NULL, points, 3);
1244
1245 status = GdipDrawCurveI(NULL, pen, points, 3);
1247
1248 /* InvalidParameter cases: invalid count */
1249 status = GdipDrawCurveI(graphics, pen, points, -1);
1251
1252 status = GdipDrawCurveI(graphics, pen, points, 0);
1254
1255 status = GdipDrawCurveI(graphics, pen, points, 1);
1257
1258 /* Valid test cases */
1259 status = GdipDrawCurveI(graphics, pen, points, 2);
1260 expect(Ok, status);
1261
1262 status = GdipDrawCurveI(graphics, pen, points, 3);
1263 expect(Ok, status);
1264
1265 GdipDeletePen(pen);
1266 GdipDeleteGraphics(graphics);
1267
1268 ReleaseDC(hwnd, hdc);
1269}
1270
1271static void test_GdipDrawLineI(void)
1272{
1274 GpGraphics *graphics = NULL;
1275 GpPen *pen = NULL;
1276 HDC hdc = GetDC( hwnd );
1277
1278 /* make a graphics object and pen object */
1279 ok(hdc != NULL, "Expected HDC to be initialized\n");
1280
1281 status = GdipCreateFromHDC(hdc, &graphics);
1282 expect(Ok, status);
1283 ok(graphics != NULL, "Expected graphics to be initialized\n");
1284
1285 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1286 expect(Ok, status);
1287 ok(pen != NULL, "Expected pen to be initialized\n");
1288
1289 /* InvalidParameter cases: null graphics, null pen */
1290 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
1292
1293 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
1295
1296 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
1298
1299 /* successful case */
1300 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
1301 expect(Ok, status);
1302
1303 GdipDeletePen(pen);
1304 GdipDeleteGraphics(graphics);
1305
1306 ReleaseDC(hwnd, hdc);
1307}
1308
1310{
1312 GpGraphics *graphics = NULL;
1313 GpPointF ptf[4];
1314 GpBitmap *bm = NULL;
1315 BYTE rbmi[sizeof(BITMAPINFOHEADER)];
1316 BYTE buff[400];
1317 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
1318 HDC hdc = GetDC( hwnd );
1319 if (!hdc)
1320 return;
1321
1322 memset(rbmi, 0, sizeof(rbmi));
1323 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1324 bmi->bmiHeader.biWidth = 10;
1325 bmi->bmiHeader.biHeight = 10;
1326 bmi->bmiHeader.biPlanes = 1;
1327 bmi->bmiHeader.biBitCount = 32;
1330 expect(Ok, status);
1331 ok(NULL != bm, "Expected bitmap to be initialized\n");
1332 status = GdipCreateFromHDC(hdc, &graphics);
1333 expect(Ok, status);
1334 ptf[0].X = 0;
1335 ptf[0].Y = 0;
1336 ptf[1].X = 10;
1337 ptf[1].Y = 0;
1338 ptf[2].X = 0;
1339 ptf[2].Y = 10;
1340 ptf[3].X = 10;
1341 ptf[3].Y = 10;
1342 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 4, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1344 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 2, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1346 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1347 expect(Ok, status);
1348 status = GdipDrawImagePointsRect(graphics, NULL, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1350 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, NULL, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1352 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 0, 0, UnitPixel, NULL, NULL, NULL);
1353 expect(Ok, status);
1354 memset(ptf, 0, sizeof(ptf));
1355 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1356 expect(Ok, status);
1357
1359 GdipDeleteGraphics(graphics);
1360 ReleaseDC(hwnd, hdc);
1361}
1362
1363static void test_GdipDrawLinesI(void)
1364{
1366 GpGraphics *graphics = NULL;
1367 GpPen *pen = NULL;
1368 GpPoint *ptf = NULL;
1369 HDC hdc = GetDC( hwnd );
1370
1371 /* make a graphics object and pen object */
1372 ok(hdc != NULL, "Expected HDC to be initialized\n");
1373
1374 status = GdipCreateFromHDC(hdc, &graphics);
1375 expect(Ok, status);
1376 ok(graphics != NULL, "Expected graphics to be initialized\n");
1377
1378 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1379 expect(Ok, status);
1380 ok(pen != NULL, "Expected pen to be initialized\n");
1381
1382 /* make some arbitrary valid points*/
1383 ptf = GdipAlloc(2 * sizeof(GpPointF));
1384
1385 ptf[0].X = 1;
1386 ptf[0].Y = 1;
1387
1388 ptf[1].X = 2;
1389 ptf[1].Y = 2;
1390
1391 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1394
1395 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1397
1398 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1400
1401 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1403
1404 /* successful case */
1405 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1406 expect(Ok, status);
1407
1408 GdipFree(ptf);
1409 GdipDeletePen(pen);
1410 GdipDeleteGraphics(graphics);
1411
1412 ReleaseDC(hwnd, hdc);
1413}
1414
1416{
1418 GpGraphics *graphics = NULL;
1419 GpSolidFill *brush = NULL;
1420 HDC hdc = GetDC( hwnd );
1421 GpPointF points[3];
1422
1423 points[0].X = 0;
1424 points[0].Y = 0;
1425
1426 points[1].X = 40;
1427 points[1].Y = 20;
1428
1429 points[2].X = 10;
1430 points[2].Y = 40;
1431
1432 /* make a graphics object and brush object */
1433 ok(hdc != NULL, "Expected HDC to be initialized\n");
1434
1435 status = GdipCreateFromHDC(hdc, &graphics);
1436 expect(Ok, status);
1437 ok(graphics != NULL, "Expected graphics to be initialized\n");
1438
1439 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1440
1441 /* InvalidParameter cases: null graphics, null brush, null points */
1444
1445 status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1447
1448 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1450
1453
1454 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1456
1457 status = GdipFillClosedCurve(graphics, NULL, points, 3);
1459
1462
1463 /* InvalidParameter cases: invalid count */
1464 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1466
1467 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1469
1470 /* Valid test cases */
1471 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1472 expect(Ok, status);
1473
1474 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1475 expect(Ok, status);
1476
1477 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1478 expect(Ok, status);
1479
1480 GdipDeleteGraphics(graphics);
1481 GdipDeleteBrush((GpBrush*)brush);
1482
1483 ReleaseDC(hwnd, hdc);
1484}
1485
1487{
1489 GpGraphics *graphics = NULL;
1490 GpSolidFill *brush = NULL;
1491 HDC hdc = GetDC( hwnd );
1492 GpPoint points[3];
1493
1494 points[0].X = 0;
1495 points[0].Y = 0;
1496
1497 points[1].X = 40;
1498 points[1].Y = 20;
1499
1500 points[2].X = 10;
1501 points[2].Y = 40;
1502
1503 /* make a graphics object and brush object */
1504 ok(hdc != NULL, "Expected HDC to be initialized\n");
1505
1506 status = GdipCreateFromHDC(hdc, &graphics);
1507 expect(Ok, status);
1508 ok(graphics != NULL, "Expected graphics to be initialized\n");
1509
1510 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1511
1512 /* InvalidParameter cases: null graphics, null brush */
1513 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
1514 when points == NULL, so don't test this condition */
1517
1518 status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1520
1523
1524 /* InvalidParameter cases: invalid count */
1525 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1527
1528 /* OutOfMemory cases: large (unsigned) int */
1529 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1531
1532 /* Valid test cases */
1533 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1534 expect(Ok, status);
1535
1536 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1537 expect(Ok, status);
1538
1539 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1540 expect(Ok, status);
1541
1542 GdipDeleteGraphics(graphics);
1543 GdipDeleteBrush((GpBrush*)brush);
1544
1545 ReleaseDC(hwnd, hdc);
1546}
1547
1548static void test_GdipFillPath(void)
1549{
1551 GpGraphics *graphics;
1552 GpSolidFill *brush;
1553 GpPath *path;
1554 HDC hdc = GetDC(hwnd);
1555
1556 ok(hdc != NULL, "Expected HDC to be initialized\n");
1557 status = GdipCreateFromHDC(hdc, &graphics);
1558 expect(Ok, status);
1559 ok(graphics != NULL, "Expected graphics to be initialized\n");
1560 status = GdipCreateSolidFill((ARGB)0xffffffff, &brush);
1561 expect(Ok, status);
1562 ok(brush != NULL, "Expected brush to be initialized\n");
1564 expect(Ok, status);
1565 ok(path != NULL, "Expected path to be initialized\n");
1566
1567 /* Empty path */
1569 status = GdipFillPath(graphics, (GpBrush *)brush, path);
1570 expect(Ok, status);
1571
1572 /* Not closed path */
1574 status = GdipAddPathLineI(path, 0, 0, 2, 2);
1575 expect(Ok, status);
1576 status = GdipAddPathLineI(path, 2, 2, 4, 0);
1577 expect(Ok, status);
1578 status = GdipFillPath(graphics, (GpBrush *)brush, path);
1579 expect(Ok, status);
1580
1581 /* Closed path */
1583 status = GdipAddPathRectangle(path, 0, 0, 4, 4);
1584 expect(Ok, status);
1585 status = GdipFillPath(graphics, (GpBrush *)brush, path);
1586 expect(Ok, status);
1587
1589 GdipDeleteBrush((GpBrush *)brush);
1590 GdipDeleteGraphics(graphics);
1591 ReleaseDC(hwnd, hdc);
1592}
1593
1594static void test_Get_Release_DC(void)
1595{
1597 GpGraphics *graphics = NULL;
1598 GpPen *pen;
1599 GpSolidFill *brush;
1600 GpPath *path;
1601 HDC hdc = GetDC( hwnd );
1602 HDC retdc;
1603 REAL r;
1605 CompositingMode compmode;
1606 InterpolationMode intmode;
1607 GpMatrix *m;
1608 GpRegion *region;
1609 GpUnit unit;
1610 PixelOffsetMode offsetmode;
1611 SmoothingMode smoothmode;
1612 TextRenderingHint texthint;
1613 GpPointF ptf[5];
1614 GpPoint pt[5];
1615 GpRectF rectf[2];
1616 GpRect rect[2];
1617 GpRegion *clip;
1618 INT i;
1619 BOOL res;
1620 ARGB color = 0x00000000;
1621 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1622
1623 pt[0].X = 10;
1624 pt[0].Y = 10;
1625 pt[1].X = 20;
1626 pt[1].Y = 15;
1627 pt[2].X = 40;
1628 pt[2].Y = 80;
1629 pt[3].X = -20;
1630 pt[3].Y = 20;
1631 pt[4].X = 50;
1632 pt[4].Y = 110;
1633
1634 for(i = 0; i < 5;i++){
1635 ptf[i].X = (REAL)pt[i].X;
1636 ptf[i].Y = (REAL)pt[i].Y;
1637 }
1638
1639 rect[0].X = 0;
1640 rect[0].Y = 0;
1641 rect[0].Width = 50;
1642 rect[0].Height = 70;
1643 rect[1].X = 0;
1644 rect[1].Y = 0;
1645 rect[1].Width = 10;
1646 rect[1].Height = 20;
1647
1648 for(i = 0; i < 2;i++){
1649 rectf[i].X = (REAL)rect[i].X;
1650 rectf[i].Y = (REAL)rect[i].Y;
1651 rectf[i].Height = (REAL)rect[i].Height;
1652 rectf[i].Width = (REAL)rect[i].Width;
1653 }
1654
1656 expect(Ok, status);
1657 status = GdipCreateRegion(&region);
1658 expect(Ok, status);
1659 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1661 status = GdipCreateRegion(&clip);
1662 expect(Ok, status);
1663
1664 status = GdipCreateFromHDC(hdc, &graphics);
1665 expect(Ok, status);
1666 ok(graphics != NULL, "Expected graphics to be initialized\n");
1667 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1668 expect(Ok, status);
1669
1670 /* NULL arguments */
1673 status = GdipGetDC(graphics, NULL);
1675 status = GdipGetDC(NULL, &retdc);
1677
1680 status = GdipReleaseDC(graphics, NULL);
1682 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1684
1685 /* Release without Get */
1686 status = GdipReleaseDC(graphics, hdc);
1688
1689 retdc = NULL;
1690 status = GdipGetDC(graphics, &retdc);
1691 expect(Ok, status);
1692 ok(retdc == hdc, "Invalid HDC returned\n");
1693 /* call it once more */
1694 status = GdipGetDC(graphics, &retdc);
1696
1697 /* try all Graphics calls here */
1698 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1700 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1702 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1704 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1706 status = GdipDrawBeziers(graphics, pen, ptf, 5);
1708 status = GdipDrawBeziersI(graphics, pen, pt, 5);
1710 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1712 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1714 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1716 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1718 status = GdipDrawCurve(graphics, pen, ptf, 5);
1720 status = GdipDrawCurveI(graphics, pen, pt, 5);
1722 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1724 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1726 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1728 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1730 /* GdipDrawImage/GdipDrawImageI */
1731 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1732 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1733 /* GdipDrawImageRect/GdipDrawImageRectI */
1734 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1736 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1738 status = GdipDrawLines(graphics, pen, ptf, 5);
1740 status = GdipDrawLinesI(graphics, pen, pt, 5);
1742 status = GdipDrawPath(graphics, pen, path);
1744 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1746 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1748 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1750 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1752 status = GdipDrawRectangles(graphics, pen, rectf, 2);
1754 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1756 /* GdipDrawString */
1757 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1759 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1761 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, ptf, 5);
1763 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, pt, 5);
1765 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1767 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1769 status = GdipFillPath(graphics, (GpBrush*)brush, path);
1771 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1773 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1775 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1777 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1779 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1781 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1783 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1785 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1787 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1789 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1791 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1795 status = GdipGetClipBounds(graphics, rectf);
1797 status = GdipGetClipBoundsI(graphics, rect);
1799 status = GdipGetCompositingMode(graphics, &compmode);
1803 status = GdipGetInterpolationMode(graphics, &intmode);
1805 status = GdipGetNearestColor(graphics, &color);
1807 status = GdipGetPageScale(graphics, &r);
1809 status = GdipGetPageUnit(graphics, &unit);
1811 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1813 status = GdipGetSmoothingMode(graphics, &smoothmode);
1815 status = GdipGetTextRenderingHint(graphics, &texthint);
1817 status = GdipGetWorldTransform(graphics, m);
1819 status = GdipGraphicsClear(graphics, 0xdeadbeef);
1821 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1823 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1825 /* GdipMeasureCharacterRanges */
1826 /* GdipMeasureString */
1827 status = GdipResetClip(graphics);
1829 status = GdipResetWorldTransform(graphics);
1831 /* GdipRestoreGraphics */
1834 /* GdipSaveGraphics */
1835 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1843 status = GdipSetPageScale(graphics, 1.0);
1845 status = GdipSetPageUnit(graphics, UnitWorld);
1853 status = GdipSetWorldTransform(graphics, m);
1861 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1863 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1865 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1867 status = GdipTranslateClip(graphics, 0.0, 0.0);
1869 status = GdipTranslateClipI(graphics, 0, 0);
1871 status = GdipDrawPolygon(graphics, pen, ptf, 5);
1873 status = GdipDrawPolygonI(graphics, pen, pt, 5);
1875 status = GdipGetDpiX(graphics, &r);
1877 status = GdipGetDpiY(graphics, &r);
1881 status = GdipGetClip(graphics, region);
1885
1886 /* try to delete before release */
1887 status = GdipDeleteGraphics(graphics);
1889
1890 status = GdipReleaseDC(graphics, retdc);
1891 expect(Ok, status);
1892
1893 GdipDeletePen(pen);
1894 GdipDeleteGraphics(graphics);
1895
1896 GdipDeleteRegion(clip);
1898 GdipDeleteBrush((GpBrush*)brush);
1899 GdipDeleteRegion(region);
1902
1903 ReleaseDC(hwnd, hdc);
1904}
1905
1906static void test_transformpoints(void)
1907{
1909 GpGraphics *graphics = NULL;
1910 HDC hdc = GetDC( hwnd );
1911 GpPointF ptf[2];
1912 GpPoint pt[2];
1913
1914 status = GdipCreateFromHDC(hdc, &graphics);
1915 expect(Ok, status);
1916
1917 /* NULL arguments */
1926
1929 status = GdipTransformPoints(graphics, -1, CoordinateSpaceWorld, ptf, 2);
1933 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, -1, ptf, 2);
1935
1936 ptf[0].X = 1.0;
1937 ptf[0].Y = 0.0;
1938 ptf[1].X = 0.0;
1939 ptf[1].Y = 1.0;
1941 expect(Ok, status);
1942 expectf(1.0, ptf[0].X);
1943 expectf(0.0, ptf[0].Y);
1944 expectf(0.0, ptf[1].X);
1945 expectf(1.0, ptf[1].Y);
1946
1948 expect(Ok, status);
1949 status = GdipSetPageUnit(graphics, UnitPixel);
1950 expect(Ok, status);
1951 status = GdipSetPageScale(graphics, 3.0);
1952 expect(Ok, status);
1953
1954 ptf[0].X = 1.0;
1955 ptf[0].Y = 0.0;
1956 ptf[1].X = 0.0;
1957 ptf[1].Y = 1.0;
1959 expect(Ok, status);
1960 expectf(18.0, ptf[0].X);
1961 expectf(15.0, ptf[0].Y);
1962 expectf(15.0, ptf[1].X);
1963 expectf(18.0, ptf[1].Y);
1964
1965 ptf[0].X = 1.0;
1966 ptf[0].Y = 0.0;
1967 ptf[1].X = 0.0;
1968 ptf[1].Y = 1.0;
1970 expect(Ok, status);
1971 expectf(6.0, ptf[0].X);
1972 expectf(5.0, ptf[0].Y);
1973 expectf(5.0, ptf[1].X);
1974 expectf(6.0, ptf[1].Y);
1975
1976 ptf[0].X = 1.0;
1977 ptf[0].Y = 0.0;
1978 ptf[1].X = 0.0;
1979 ptf[1].Y = 1.0;
1981 expect(Ok, status);
1982 expectf(3.0, ptf[0].X);
1983 expectf(0.0, ptf[0].Y);
1984 expectf(0.0, ptf[1].X);
1985 expectf(3.0, ptf[1].Y);
1986
1987 ptf[0].X = 18.0;
1988 ptf[0].Y = 15.0;
1989 ptf[1].X = 15.0;
1990 ptf[1].Y = 18.0;
1992 expect(Ok, status);
1993 expectf(1.0, ptf[0].X);
1994 expectf(0.0, ptf[0].Y);
1995 expectf(0.0, ptf[1].X);
1996 expectf(1.0, ptf[1].Y);
1997
1998 ptf[0].X = 6.0;
1999 ptf[0].Y = 5.0;
2000 ptf[1].X = 5.0;
2001 ptf[1].Y = 6.0;
2003 expect(Ok, status);
2004 expectf(1.0, ptf[0].X);
2005 expectf(0.0, ptf[0].Y);
2006 expectf(0.0, ptf[1].X);
2007 expectf(1.0, ptf[1].Y);
2008
2009 ptf[0].X = 3.0;
2010 ptf[0].Y = 0.0;
2011 ptf[1].X = 0.0;
2012 ptf[1].Y = 3.0;
2014 expect(Ok, status);
2015 expectf(1.0, ptf[0].X);
2016 expectf(0.0, ptf[0].Y);
2017 expectf(0.0, ptf[1].X);
2018 expectf(1.0, ptf[1].Y);
2019
2020 pt[0].X = 1;
2021 pt[0].Y = 0;
2022 pt[1].X = 0;
2023 pt[1].Y = 1;
2025 expect(Ok, status);
2026 expect(18, pt[0].X);
2027 expect(15, pt[0].Y);
2028 expect(15, pt[1].X);
2029 expect(18, pt[1].Y);
2030
2031 GdipDeleteGraphics(graphics);
2032 ReleaseDC(hwnd, hdc);
2033}
2034
2035static void test_get_set_clip(void)
2036{
2038 GpGraphics *graphics = NULL;
2039 HDC hdc = GetDC( hwnd );
2040 GpRegion *clip;
2041 GpRectF rect;
2042 BOOL res;
2043
2044 status = GdipCreateFromHDC(hdc, &graphics);
2045 expect(Ok, status);
2046
2047 rect.X = rect.Y = 0.0;
2048 rect.Height = rect.Width = 100.0;
2049
2050 status = GdipCreateRegionRect(&rect, &clip);
2051 expect(Ok, status);
2052
2053 /* NULL arguments */
2056 status = GdipGetClip(graphics, NULL);
2058 status = GdipGetClip(NULL, clip);
2060
2065
2070
2071 res = FALSE;
2072 status = GdipGetClip(graphics, clip);
2073 expect(Ok, status);
2074 status = GdipIsInfiniteRegion(clip, graphics, &res);
2075 expect(Ok, status);
2076 expect(TRUE, res);
2077
2078 /* remains infinite after reset */
2079 res = FALSE;
2080 status = GdipResetClip(graphics);
2081 expect(Ok, status);
2082 status = GdipGetClip(graphics, clip);
2083 expect(Ok, status);
2084 status = GdipIsInfiniteRegion(clip, graphics, &res);
2085 expect(Ok, status);
2086 expect(TRUE, res);
2087
2088 /* set to empty and then reset to infinite */
2089 status = GdipSetEmpty(clip);
2090 expect(Ok, status);
2091 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
2092 expect(Ok, status);
2093
2094 status = GdipGetClip(graphics, clip);
2095 expect(Ok, status);
2096 res = FALSE;
2097 status = GdipIsEmptyRegion(clip, graphics, &res);
2098 expect(Ok, status);
2099 expect(TRUE, res);
2100 status = GdipResetClip(graphics);
2101 expect(Ok, status);
2102 status = GdipGetClip(graphics, clip);
2103 expect(Ok, status);
2104 res = FALSE;
2105 status = GdipIsInfiniteRegion(clip, graphics, &res);
2106 expect(Ok, status);
2107 expect(TRUE, res);
2108
2109 GdipDeleteRegion(clip);
2110
2111 GdipDeleteGraphics(graphics);
2112 ReleaseDC(hwnd, hdc);
2113}
2114
2115static void test_clip_xform(void)
2116{
2118 GpGraphics *graphics = NULL;
2119 HDC hdc = GetDC( hwnd );
2120 GpRegion *clip;
2122 UINT region_data_size;
2123 struct {
2124 DWORD size;
2126 DWORD magic;
2127 DWORD num_children;
2128 DWORD element_type;
2129 REAL x;
2130 REAL y;
2131 REAL width;
2132 REAL height;
2133 } region_data;
2134
2135 status = GdipCreateFromHDC(hdc, &graphics);
2136 expect(Ok, status);
2137 status = GdipCreateRegion(&clip);
2138 expect(Ok, status);
2139
2140 status = GdipGraphicsClear(graphics, 0xff000000);
2141 expect(Ok, status);
2142
2143 status = GdipSetClipRect(graphics, 10, 10, -10, -10, CombineModeReplace);
2144 expect(Ok, status);
2145 status = GdipGetClip(graphics, clip);
2146 expect(Ok, status);
2147 status = GdipGetRegionData(clip, (BYTE*)&region_data, sizeof(region_data), &region_data_size);
2148 expect(Ok, status);
2149 expect(36, region_data_size);
2150 expect(28, region_data.size);
2151 expect(0, region_data.num_children);
2152 expect(0x10000000 /* RegionDataRect */, region_data.element_type);
2153 expectf(0.0, region_data.x);
2154 expectf(0.0, region_data.y);
2155 expectf(10.0, region_data.width);
2156 expectf(10.0, region_data.height);
2157
2158 /* No effect with negative width/height */
2159 status = GdipGraphicsClear(graphics, 0xffff0000);
2160 expect(Ok, status);
2161 color = GetPixel(hdc, 5, 5);
2162 expect(0, color);
2163
2164 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderAppend);
2165 expect(Ok, status);
2166
2167 status = GdipGraphicsClear(graphics, 0xffff0000);
2168 expect(Ok, status);
2169 color = GetPixel(hdc, 5, 5);
2170 expect(0, color);
2171
2172 status = GdipResetClip(graphics);
2173 expect(Ok, status);
2174 status = GdipResetWorldTransform(graphics);
2175 expect(Ok, status);
2176 status = GdipGraphicsClear(graphics, 0xff000000);
2177 expect(Ok, status);
2178
2179 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderAppend);
2180 expect(Ok, status);
2181
2182 status = GdipSetClipRect(graphics, 5, 5, -5, -5, CombineModeReplace);
2183 expect(Ok, status);
2184 status = GdipGetClip(graphics, clip);
2185 expect(Ok, status);
2186 status = GdipGetRegionData(clip, (BYTE*)&region_data, sizeof(region_data), &region_data_size);
2187 expect(Ok, status);
2188 expect(36, region_data_size);
2189 expect(28, region_data.size);
2190 expect(0, region_data.num_children);
2191 expect(0x10000000 /* RegionDataRect */, region_data.element_type);
2192 expectf(0.0, region_data.x);
2193 expectf(0.0, region_data.y);
2194 expectf(5.0, region_data.width);
2195 expectf(5.0, region_data.height);
2196
2197 status = GdipGraphicsClear(graphics, 0xffff0000);
2198 expect(Ok, status);
2199 color = GetPixel(hdc, 5, 5);
2200 expect(0xff, color);
2201
2202 GdipDeleteGraphics(graphics);
2203 GdipDeleteRegion(clip);
2204 ReleaseDC(hwnd, hdc);
2205}
2206
2207static void test_isempty(void)
2208{
2210 GpGraphics *graphics = NULL;
2211 HDC hdc = GetDC( hwnd );
2212 GpRegion *clip;
2213 BOOL res;
2214
2215 status = GdipCreateFromHDC(hdc, &graphics);
2216 expect(Ok, status);
2217
2218 status = GdipCreateRegion(&clip);
2219 expect(Ok, status);
2220
2221 /* NULL */
2224 status = GdipIsClipEmpty(graphics, NULL);
2228
2229 /* default is infinite */
2230 res = TRUE;
2231 status = GdipIsClipEmpty(graphics, &res);
2232 expect(Ok, status);
2233 expect(FALSE, res);
2234
2235 GdipDeleteRegion(clip);
2236
2237 GdipDeleteGraphics(graphics);
2238 ReleaseDC(hwnd, hdc);
2239}
2240
2241static void test_clear(void)
2242{
2244
2245 status = GdipGraphicsClear(NULL, 0xdeadbeef);
2247}
2248
2249static void test_textcontrast(void)
2250{
2252 HDC hdc = GetDC( hwnd );
2253 GpGraphics *graphics;
2254 UINT contrast;
2255
2258
2259 status = GdipCreateFromHDC(hdc, &graphics);
2260 expect(Ok, status);
2261
2262 status = GdipGetTextContrast(graphics, NULL);
2264 status = GdipGetTextContrast(graphics, &contrast);
2265 expect(Ok, status);
2266 expect(4, contrast);
2267
2268 GdipDeleteGraphics(graphics);
2269 ReleaseDC(hwnd, hdc);
2270}
2271
2272static void test_GdipDrawString(void)
2273{
2275 GpGraphics *graphics = NULL;
2276 GpFont *fnt = NULL;
2277 RectF rect;
2279 GpBrush *brush;
2280 LOGFONTA logfont;
2281 HDC hdc = GetDC( hwnd );
2282 static const WCHAR string[] = {'T','e','s','t',0};
2283 static const PointF positions[4] = {{0,0}, {1,1}, {2,2}, {3,3}};
2285
2286 memset(&logfont,0,sizeof(logfont));
2287 strcpy(logfont.lfFaceName,"Arial");
2288 logfont.lfHeight = 12;
2289 logfont.lfCharSet = DEFAULT_CHARSET;
2290
2291 status = GdipCreateFromHDC(hdc, &graphics);
2292 expect(Ok, status);
2293
2294 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
2296 {
2297 skip("Arial not installed.\n");
2298 return;
2299 }
2300 expect(Ok, status);
2301
2302 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
2303 expect(Ok, status);
2304
2306 expect(Ok, status);
2307
2308 rect.X = 0;
2309 rect.Y = 0;
2310 rect.Width = 0;
2311 rect.Height = 12;
2312
2313 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
2314 expect(Ok, status);
2315
2317 expect(Ok, status);
2318
2319 status = GdipDrawDriverString(NULL, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2321
2322 status = GdipDrawDriverString(graphics, NULL, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2324
2325 status = GdipDrawDriverString(graphics, string, 4, NULL, brush, positions, DriverStringOptionsCmapLookup, matrix);
2327
2328 status = GdipDrawDriverString(graphics, string, 4, fnt, NULL, positions, DriverStringOptionsCmapLookup, matrix);
2330
2331 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, NULL, DriverStringOptionsCmapLookup, matrix);
2333
2334 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup|0x10, matrix);
2335 expect(Ok, status);
2336
2337 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, NULL);
2338 expect(Ok, status);
2339
2340 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2341 expect(Ok, status);
2342
2344 GdipDeleteGraphics(graphics);
2345 GdipDeleteBrush(brush);
2346 GdipDeleteFont(fnt);
2348
2349 ReleaseDC(hwnd, hdc);
2350}
2351
2353{
2355 GpGraphics *graphics = NULL;
2356 HDC hdc = GetDC(0);
2357 GpRectF rectf, exp, clipr;
2358 GpRect recti;
2359
2360 ok(hdc != NULL, "Expected HDC to be initialized\n");
2361
2362 status = GdipCreateFromHDC(hdc, &graphics);
2363 expect(Ok, status);
2364 ok(graphics != NULL, "Expected graphics to be initialized\n");
2365
2366 /* no clipping rect */
2367 exp.X = 0;
2368 exp.Y = 0;
2369 exp.Width = GetDeviceCaps(hdc, HORZRES);
2370 exp.Height = GetDeviceCaps(hdc, VERTRES);
2371
2372 status = GdipGetVisibleClipBounds(graphics, &rectf);
2373 expect(Ok, status);
2374 ok(rectf.X == exp.X &&
2375 rectf.Y == exp.Y &&
2376 rectf.Width == exp.Width &&
2377 rectf.Height == exp.Height,
2378 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2379 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2380 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2381 exp.X, exp.Y, exp.Width, exp.Height);
2382
2383 /* clipping rect entirely within window */
2384 exp.X = clipr.X = 10;
2385 exp.Y = clipr.Y = 12;
2386 exp.Width = clipr.Width = 14;
2387 exp.Height = clipr.Height = 16;
2388
2389 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2390 expect(Ok, status);
2391
2392 status = GdipGetVisibleClipBounds(graphics, &rectf);
2393 expect(Ok, status);
2394 ok(rectf.X == exp.X &&
2395 rectf.Y == exp.Y &&
2396 rectf.Width == exp.Width &&
2397 rectf.Height == exp.Height,
2398 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2399 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2400 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2401 exp.X, exp.Y, exp.Width, exp.Height);
2402
2403 /* clipping rect partially outside of screen */
2404 clipr.X = -10;
2405 clipr.Y = -12;
2406 clipr.Width = 20;
2407 clipr.Height = 24;
2408
2409 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2410 expect(Ok, status);
2411
2412 exp.X = 0;
2413 exp.Y = 0;
2414 exp.Width = 10;
2415 exp.Height = 12;
2416
2417 status = GdipGetVisibleClipBounds(graphics, &rectf);
2418 expect(Ok, status);
2419 ok(rectf.X == exp.X &&
2420 rectf.Y == exp.Y &&
2421 rectf.Width == exp.Width &&
2422 rectf.Height == exp.Height,
2423 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2424 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2425 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2426 exp.X, exp.Y, exp.Width, exp.Height);
2427
2428 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2429 expect(Ok, status);
2430 ok(recti.X == exp.X &&
2431 recti.Y == exp.Y &&
2432 recti.Width == exp.Width &&
2433 recti.Height == exp.Height,
2434 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2435 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2436 recti.X, recti.Y, recti.Width, recti.Height,
2437 exp.X, exp.Y, exp.Width, exp.Height);
2438
2439 GdipDeleteGraphics(graphics);
2440 ReleaseDC(0, hdc);
2441}
2442
2444{
2446 GpGraphics *graphics = NULL;
2447 GpRectF rectf, window, exp, clipr;
2448 GpRect recti;
2449 HDC hdc;
2450 PAINTSTRUCT ps;
2451 RECT wnd_rect;
2452
2453 /* get client area size */
2454 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2455 window.X = wnd_rect.left;
2456 window.Y = wnd_rect.top;
2457 window.Width = wnd_rect.right - wnd_rect.left;
2458 window.Height = wnd_rect.bottom - wnd_rect.top;
2459
2460 hdc = BeginPaint(hwnd, &ps);
2461
2462 status = GdipCreateFromHDC(hdc, &graphics);
2463 expect(Ok, status);
2464 ok(graphics != NULL, "Expected graphics to be initialized\n");
2465
2466 status = GdipGetVisibleClipBounds(graphics, &rectf);
2467 expect(Ok, status);
2468 ok(rectf.X == window.X &&
2469 rectf.Y == window.Y &&
2470 rectf.Width == window.Width &&
2471 rectf.Height == window.Height,
2472 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2473 "the window (%0.f, %0.f, %0.f, %0.f)\n",
2474 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2475 window.X, window.Y, window.Width, window.Height);
2476
2477 /* clipping rect entirely within window */
2478 exp.X = clipr.X = 20;
2479 exp.Y = clipr.Y = 8;
2480 exp.Width = clipr.Width = 30;
2481 exp.Height = clipr.Height = 20;
2482
2483 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2484 expect(Ok, status);
2485
2486 status = GdipGetVisibleClipBounds(graphics, &rectf);
2487 expect(Ok, status);
2488 ok(rectf.X == exp.X &&
2489 rectf.Y == exp.Y &&
2490 rectf.Width == exp.Width &&
2491 rectf.Height == exp.Height,
2492 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2493 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2494 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2495 exp.X, exp.Y, exp.Width, exp.Height);
2496
2497 /* clipping rect partially outside of window */
2498 clipr.X = window.Width - 10;
2499 clipr.Y = window.Height - 15;
2500 clipr.Width = 20;
2501 clipr.Height = 30;
2502
2503 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2504 expect(Ok, status);
2505
2506 exp.X = window.Width - 10;
2507 exp.Y = window.Height - 15;
2508 exp.Width = 10;
2509 exp.Height = 15;
2510
2511 status = GdipGetVisibleClipBounds(graphics, &rectf);
2512 expect(Ok, status);
2513 ok(rectf.X == exp.X &&
2514 rectf.Y == exp.Y &&
2515 rectf.Width == exp.Width &&
2516 rectf.Height == exp.Height,
2517 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2518 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2519 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2520 exp.X, exp.Y, exp.Width, exp.Height);
2521
2522 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2523 expect(Ok, status);
2524 ok(recti.X == exp.X &&
2525 recti.Y == exp.Y &&
2526 recti.Width == exp.Width &&
2527 recti.Height == exp.Height,
2528 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2529 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2530 recti.X, recti.Y, recti.Width, recti.Height,
2531 exp.X, exp.Y, exp.Width, exp.Height);
2532
2533 /* window bounds with transform applied */
2534 status = GdipResetClip(graphics);
2535 expect(Ok, status);
2536
2537 status = GdipScaleWorldTransform(graphics, 0.5, 0.5, MatrixOrderPrepend);
2538 expect(Ok, status);
2539
2540 exp.X = window.X * 2.0;
2541 exp.Y = window.Y * 2.0;
2542 exp.Width = window.Width * 2.0;
2543 exp.Height = window.Height * 2.0;
2544
2545 status = GdipGetVisibleClipBounds(graphics, &rectf);
2546 expect(Ok, status);
2547 ok(rectf.X == exp.X &&
2548 rectf.Y == exp.Y &&
2549 rectf.Width == exp.Width &&
2550 rectf.Height == exp.Height,
2551 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be "
2552 "twice the window size (%0.f, %0.f, %0.f, %0.f)\n",
2553 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2554 exp.X, exp.Y, exp.Width, exp.Height);
2555
2556 GdipDeleteGraphics(graphics);
2557 EndPaint(hwnd, &ps);
2558}
2559
2561{
2562 GpGraphics* graphics = NULL;
2563 GpRectF rectf;
2564 GpRect rect;
2565 HDC hdc = GetDC( hwnd );
2567
2568 status = GdipCreateFromHDC(hdc, &graphics);
2569 expect(Ok, status);
2570 ok(graphics != NULL, "Expected graphics to be initialized\n");
2571
2572 /* test null parameters */
2575
2578
2581
2584
2585 GdipDeleteGraphics(graphics);
2586 ReleaseDC(hwnd, hdc);
2587
2590}
2591
2592static void test_fromMemoryBitmap(void)
2593{
2595 GpGraphics *graphics = NULL;
2596 GpBitmap *bitmap = NULL;
2597 BYTE bits[48] = {0};
2598 HDC hdc=NULL;
2600
2602 expect(Ok, status);
2603
2605 expect(Ok, status);
2606
2607 status = GdipGraphicsClear(graphics, 0xff686868);
2608 expect(Ok, status);
2609
2610 GdipDeleteGraphics(graphics);
2611
2612 /* drawing writes to the memory provided */
2613 expect(0x68, bits[10]);
2614
2616 expect(Ok, status);
2617
2618 status = GdipGetDC(graphics, &hdc);
2619 expect(Ok, status);
2620 ok(hdc != NULL, "got NULL hdc\n");
2621
2622 color = GetPixel(hdc, 0, 0);
2623 /* The HDC is write-only, and native fills with a solid color to figure out
2624 * which pixels have changed. */
2625 todo_wine expect(0x0c0b0d, color);
2626
2627 SetPixel(hdc, 0, 0, 0x797979);
2628 SetPixel(hdc, 1, 0, 0x0c0b0d);
2629
2630 status = GdipReleaseDC(graphics, hdc);
2631 expect(Ok, status);
2632
2633 GdipDeleteGraphics(graphics);
2634
2635 expect(0x79, bits[0]);
2636 todo_wine expect(0x68, bits[3]);
2637
2639
2640 /* We get the same kind of write-only HDC for a "normal" bitmap */
2642 expect(Ok, status);
2643
2645 expect(Ok, status);
2646
2647 status = GdipGetDC(graphics, &hdc);
2648 expect(Ok, status);
2649 ok(hdc != NULL, "got NULL hdc\n");
2650
2651 color = GetPixel(hdc, 0, 0);
2652 todo_wine expect(0x0c0b0d, color);
2653
2654 status = GdipReleaseDC(graphics, hdc);
2655 expect(Ok, status);
2656
2657 GdipDeleteGraphics(graphics);
2658
2660
2661 /* If we don't draw to the HDC, the bits are never accessed */
2663 expect(Ok, status);
2664
2666 expect(Ok, status);
2667
2668 status = GdipGetDC(graphics, &hdc);
2669 expect(Ok, status);
2670 ok(hdc != NULL, "got NULL hdc\n");
2671
2672 color = GetPixel(hdc, 0, 0);
2673 todo_wine expect(0x0c0b0d, color);
2674
2675 status = GdipReleaseDC(graphics, hdc);
2676 expect(Ok, status);
2677
2678 GdipDeleteGraphics(graphics);
2679
2681}
2682
2684{
2686 GpGraphics *graphics = NULL;
2687 HDC hdc = GetDC( hwnd );
2688 REAL x, y;
2689 BOOL val;
2690
2691 ok(hdc != NULL, "Expected HDC to be initialized\n");
2692
2693 status = GdipCreateFromHDC(hdc, &graphics);
2694 expect(Ok, status);
2695 ok(graphics != NULL, "Expected graphics to be initialized\n");
2696
2697 /* null parameters */
2698 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2700
2701 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2703
2706
2707 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2709
2710 x = 0;
2711 y = 0;
2712 status = GdipIsVisiblePoint(graphics, x, y, &val);
2713 expect(Ok, status);
2714 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2715
2716 x = -10;
2717 y = 0;
2718 status = GdipIsVisiblePoint(graphics, x, y, &val);
2719 expect(Ok, status);
2720 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2721
2722 x = 0;
2723 y = -5;
2724 status = GdipIsVisiblePoint(graphics, x, y, &val);
2725 expect(Ok, status);
2726 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2727
2728 x = 1;
2729 y = 1;
2730 status = GdipIsVisiblePoint(graphics, x, y, &val);
2731 expect(Ok, status);
2732 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2733
2734 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2735 expect(Ok, status);
2736
2737 x = 1;
2738 y = 1;
2739 status = GdipIsVisiblePoint(graphics, x, y, &val);
2740 expect(Ok, status);
2741 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2742
2743 x = 15.5;
2744 y = 40.5;
2745 status = GdipIsVisiblePoint(graphics, x, y, &val);
2746 expect(Ok, status);
2747 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2748
2749 /* translate into the center of the rect */
2751
2752 x = 0;
2753 y = 0;
2754 status = GdipIsVisiblePoint(graphics, x, y, &val);
2755 expect(Ok, status);
2756 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2757
2758 x = 25;
2759 y = 40;
2760 status = GdipIsVisiblePoint(graphics, x, y, &val);
2761 expect(Ok, status);
2762 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2763
2765
2766 /* corner cases */
2767 x = 9;
2768 y = 19;
2769 status = GdipIsVisiblePoint(graphics, x, y, &val);
2770 expect(Ok, status);
2771 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2772
2773 x = 9.25;
2774 y = 19.25;
2775 status = GdipIsVisiblePoint(graphics, x, y, &val);
2776 expect(Ok, status);
2777 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2778
2779 x = 9.5;
2780 y = 19.5;
2781 status = GdipIsVisiblePoint(graphics, x, y, &val);
2782 expect(Ok, status);
2783 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2784
2785 x = 9.75;
2786 y = 19.75;
2787 status = GdipIsVisiblePoint(graphics, x, y, &val);
2788 expect(Ok, status);
2789 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2790
2791 x = 10;
2792 y = 20;
2793 status = GdipIsVisiblePoint(graphics, x, y, &val);
2794 expect(Ok, status);
2795 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2796
2797 x = 40;
2798 y = 20;
2799 status = GdipIsVisiblePoint(graphics, x, y, &val);
2800 expect(Ok, status);
2801 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2802
2803 x = 39;
2804 y = 59;
2805 status = GdipIsVisiblePoint(graphics, x, y, &val);
2806 expect(Ok, status);
2807 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2808
2809 x = 39.25;
2810 y = 59.25;
2811 status = GdipIsVisiblePoint(graphics, x, y, &val);
2812 expect(Ok, status);
2813 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2814
2815 x = 39.5;
2816 y = 39.5;
2817 status = GdipIsVisiblePoint(graphics, x, y, &val);
2818 expect(Ok, status);
2819 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2820
2821 x = 39.75;
2822 y = 59.75;
2823 status = GdipIsVisiblePoint(graphics, x, y, &val);
2824 expect(Ok, status);
2825 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2826
2827 x = 40;
2828 y = 60;
2829 status = GdipIsVisiblePoint(graphics, x, y, &val);
2830 expect(Ok, status);
2831 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2832
2833 x = 40.15;
2834 y = 60.15;
2835 status = GdipIsVisiblePoint(graphics, x, y, &val);
2836 expect(Ok, status);
2837 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2838
2839 x = 10;
2840 y = 60;
2841 status = GdipIsVisiblePoint(graphics, x, y, &val);
2842 expect(Ok, status);
2843 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2844
2845 /* integer version */
2846 x = 25;
2847 y = 30;
2848 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2849 expect(Ok, status);
2850 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2851
2852 x = 50;
2853 y = 100;
2854 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2855 expect(Ok, status);
2856 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2857
2858 GdipDeleteGraphics(graphics);
2859 ReleaseDC(hwnd, hdc);
2860}
2861
2862static void test_GdipIsVisibleRect(void)
2863{
2865 GpGraphics *graphics = NULL;
2866 HDC hdc = GetDC( hwnd );
2867 REAL x, y, width, height;
2868 BOOL val;
2869
2870 ok(hdc != NULL, "Expected HDC to be initialized\n");
2871
2872 status = GdipCreateFromHDC(hdc, &graphics);
2873 expect(Ok, status);
2874 ok(graphics != NULL, "Expected graphics to be initialized\n");
2875
2876 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2878
2879 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2881
2882 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2884
2885 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2887
2888 /* entirely within the visible region */
2889 x = 0; width = 10;
2890 y = 0; height = 10;
2891 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2892 expect(Ok, status);
2893 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2894
2895 /* partially outside */
2896 x = -10; width = 20;
2897 y = -10; height = 20;
2898 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2899 expect(Ok, status);
2900 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2901
2902 /* entirely outside */
2903 x = -10; width = 5;
2904 y = -10; height = 5;
2905 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2906 expect(Ok, status);
2907 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2908
2909 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2910 expect(Ok, status);
2911
2912 /* entirely within the visible region */
2913 x = 12; width = 10;
2914 y = 22; height = 10;
2915 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2916 expect(Ok, status);
2917 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2918
2919 /* partially outside */
2920 x = 35; width = 10;
2921 y = 55; height = 10;
2922 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2923 expect(Ok, status);
2924 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2925
2926 /* entirely outside */
2927 x = 45; width = 5;
2928 y = 65; height = 5;
2929 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2930 expect(Ok, status);
2931 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2932
2933 /* translate into center of clipping rect */
2935
2936 x = 0; width = 10;
2937 y = 0; height = 10;
2938 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2939 expect(Ok, status);
2940 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2941
2942 x = 25; width = 5;
2943 y = 40; height = 5;
2944 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2945 expect(Ok, status);
2946 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2947
2949
2950 /* corners entirely outside, but some intersections */
2951 x = 0; width = 70;
2952 y = 0; height = 90;
2953 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2954 expect(Ok, status);
2955 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2956
2957 x = 0; width = 70;
2958 y = 0; height = 30;
2959 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2960 expect(Ok, status);
2961 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2962
2963 x = 0; width = 30;
2964 y = 0; height = 90;
2965 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2966 expect(Ok, status);
2967 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2968
2969 /* edge cases */
2970 x = 0; width = 10;
2971 y = 20; height = 40;
2972 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2973 expect(Ok, status);
2974 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2975
2976 x = 10; width = 30;
2977 y = 0; height = 20;
2978 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2979 expect(Ok, status);
2980 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2981
2982 x = 40; width = 10;
2983 y = 20; height = 40;
2984 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2985 expect(Ok, status);
2986 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2987
2988 x = 10; width = 30;
2989 y = 60; height = 10;
2990 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2991 expect(Ok, status);
2992 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2993
2994 /* rounding tests */
2995 x = 0.4; width = 10.4;
2996 y = 20; height = 40;
2997 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2998 expect(Ok, status);
2999 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
3000
3001 x = 10; width = 30;
3002 y = 0.4; height = 20.4;
3003 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
3004 expect(Ok, status);
3005 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
3006
3007 /* integer version */
3008 x = 0; width = 30;
3009 y = 0; height = 90;
3010 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
3011 expect(Ok, status);
3012 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
3013
3014 x = 12; width = 10;
3015 y = 22; height = 10;
3016 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
3017 expect(Ok, status);
3018 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
3019
3020 GdipDeleteGraphics(graphics);
3021 ReleaseDC(hwnd, hdc);
3022}
3023
3025{
3027 GpGraphics *graphics;
3029 ARGB color = 0xdeadbeef;
3030 HDC hdc = GetDC( hwnd );
3031
3032 /* create a graphics object */
3033 ok(hdc != NULL, "Expected HDC to be initialized\n");
3034
3035 status = GdipCreateFromHDC(hdc, &graphics);
3036 expect(Ok, status);
3037 ok(graphics != NULL, "Expected graphics to be initialized\n");
3038
3039 status = GdipGetNearestColor(graphics, NULL);
3041
3044 GdipDeleteGraphics(graphics);
3045
3047 expect(Ok, status);
3049 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
3050 if (status == Ok)
3051 {
3052 status = GdipGetNearestColor(graphics, &color);
3053 expect(Ok, status);
3054 expect(0xdeadbeef, color);
3055 GdipDeleteGraphics(graphics);
3056 }
3058
3060 expect(Ok, status);
3062 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
3063 if (status == Ok)
3064 {
3065 status = GdipGetNearestColor(graphics, &color);
3066 expect(Ok, status);
3067 expect(0xdeadbeef, color);
3068 GdipDeleteGraphics(graphics);
3069 }
3071
3073 expect(Ok, status);
3075 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
3076 if (status == Ok)
3077 {
3078 status = GdipGetNearestColor(graphics, &color);
3079 expect(Ok, status);
3080 expect(0xdeadbeef, color);
3081 GdipDeleteGraphics(graphics);
3082 }
3084
3086 expect(Ok, status);
3089 if (status == Ok)
3090 GdipDeleteGraphics(graphics);
3092
3094 expect(Ok, status);
3096 expect(Ok, status);
3097 status = GdipGetNearestColor(graphics, &color);
3098 expect(Ok, status);
3099 expect(0xdeadbeef, color);
3100 GdipDeleteGraphics(graphics);
3102
3104 expect(Ok, status);
3106 expect(Ok,