gdiplus: Implement GdipTransformPoints.
[wine/wine-gecko.git] / dlls / gdiplus / tests / graphics.c
blob510a1489a5424c05dc026ac3fb3251393059a001
1 /*
2 * Unit test suite for graphics objects
4 * Copyright (C) 2007 Google (Evan Stade)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wingdi.h"
24 #include "wine/test.h"
25 #include <math.h>
27 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
28 #define expectf(expected, got) ok(fabs(expected - got) < 0.0001, "Expected %.2f, got %.2f\n", expected, got)
29 #define TABLE_LEN (23)
31 static void test_constructor_destructor(void)
33 GpStatus stat;
34 GpGraphics *graphics = NULL;
35 HDC hdc = GetDC(0);
37 stat = GdipCreateFromHDC(NULL, &graphics);
38 expect(OutOfMemory, stat);
39 stat = GdipDeleteGraphics(graphics);
40 expect(InvalidParameter, stat);
42 stat = GdipCreateFromHDC(hdc, &graphics);
43 expect(Ok, stat);
44 stat = GdipDeleteGraphics(graphics);
45 expect(Ok, stat);
47 stat = GdipCreateFromHWND(NULL, &graphics);
48 expect(Ok, stat);
49 stat = GdipDeleteGraphics(graphics);
50 expect(Ok, stat);
52 stat = GdipCreateFromHWNDICM(NULL, &graphics);
53 expect(Ok, stat);
54 stat = GdipDeleteGraphics(graphics);
55 expect(Ok, stat);
57 stat = GdipDeleteGraphics(NULL);
58 expect(InvalidParameter, stat);
59 ReleaseDC(0, hdc);
62 typedef struct node{
63 GraphicsState data;
64 struct node * next;
65 } node;
67 /* Linked list prepend function. */
68 static void log_state(GraphicsState data, node ** log)
70 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
72 new_entry->data = data;
73 new_entry->next = *log;
74 *log = new_entry;
77 /* Checks if there are duplicates in the list, and frees it. */
78 static void check_no_duplicates(node * log)
80 INT dups = 0;
81 node * temp = NULL;
82 node * temp2 = NULL;
83 node * orig = log;
85 if(!log)
86 goto end;
88 do{
89 temp = log;
90 while((temp = temp->next)){
91 if(log->data == temp->data){
92 dups++;
93 break;
95 if(dups > 0)
96 break;
98 }while((log = log->next));
100 temp = orig;
102 temp2 = temp->next;
103 HeapFree(GetProcessHeap(), 0, temp);
104 temp = temp2;
105 }while(temp);
107 end:
108 expect(0, dups);
111 static void test_save_restore(void)
113 GpStatus stat;
114 GraphicsState state_a, state_b, state_c;
115 InterpolationMode mode;
116 GpGraphics *graphics1, *graphics2;
117 node * state_log = NULL;
118 HDC hdc = GetDC(0);
119 state_a = state_b = state_c = 0xdeadbeef;
121 /* Invalid saving. */
122 GdipCreateFromHDC(hdc, &graphics1);
123 stat = GdipSaveGraphics(graphics1, NULL);
124 expect(InvalidParameter, stat);
125 stat = GdipSaveGraphics(NULL, &state_a);
126 expect(InvalidParameter, stat);
127 GdipDeleteGraphics(graphics1);
129 log_state(state_a, &state_log);
131 /* Basic save/restore. */
132 GdipCreateFromHDC(hdc, &graphics1);
133 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
134 stat = GdipSaveGraphics(graphics1, &state_a);
135 expect(Ok, stat);
136 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
137 stat = GdipRestoreGraphics(graphics1, state_a);
138 expect(Ok, stat);
139 GdipGetInterpolationMode(graphics1, &mode);
140 todo_wine
141 expect(InterpolationModeBilinear, mode);
142 GdipDeleteGraphics(graphics1);
144 log_state(state_a, &state_log);
146 /* Restoring garbage doesn't affect saves. */
147 GdipCreateFromHDC(hdc, &graphics1);
148 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
149 GdipSaveGraphics(graphics1, &state_a);
150 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
151 GdipSaveGraphics(graphics1, &state_b);
152 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
153 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
154 expect(Ok, stat);
155 GdipRestoreGraphics(graphics1, state_b);
156 GdipGetInterpolationMode(graphics1, &mode);
157 todo_wine
158 expect(InterpolationModeBicubic, mode);
159 GdipRestoreGraphics(graphics1, state_a);
160 GdipGetInterpolationMode(graphics1, &mode);
161 todo_wine
162 expect(InterpolationModeBilinear, mode);
163 GdipDeleteGraphics(graphics1);
165 log_state(state_a, &state_log);
166 log_state(state_b, &state_log);
168 /* Restoring older state invalidates newer saves (but not older saves). */
169 GdipCreateFromHDC(hdc, &graphics1);
170 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
171 GdipSaveGraphics(graphics1, &state_a);
172 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
173 GdipSaveGraphics(graphics1, &state_b);
174 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
175 GdipSaveGraphics(graphics1, &state_c);
176 GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
177 GdipRestoreGraphics(graphics1, state_b);
178 GdipGetInterpolationMode(graphics1, &mode);
179 todo_wine
180 expect(InterpolationModeBicubic, mode);
181 GdipRestoreGraphics(graphics1, state_c);
182 GdipGetInterpolationMode(graphics1, &mode);
183 todo_wine
184 expect(InterpolationModeBicubic, mode);
185 GdipRestoreGraphics(graphics1, state_a);
186 GdipGetInterpolationMode(graphics1, &mode);
187 todo_wine
188 expect(InterpolationModeBilinear, mode);
189 GdipDeleteGraphics(graphics1);
191 log_state(state_a, &state_log);
192 log_state(state_b, &state_log);
193 log_state(state_c, &state_log);
195 /* Restoring older save from one graphics object does not invalidate
196 * newer save from other graphics object. */
197 GdipCreateFromHDC(hdc, &graphics1);
198 GdipCreateFromHDC(hdc, &graphics2);
199 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
200 GdipSaveGraphics(graphics1, &state_a);
201 GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
202 GdipSaveGraphics(graphics2, &state_b);
203 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
204 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
205 GdipRestoreGraphics(graphics1, state_a);
206 GdipGetInterpolationMode(graphics1, &mode);
207 todo_wine
208 expect(InterpolationModeBilinear, mode);
209 GdipRestoreGraphics(graphics2, state_b);
210 GdipGetInterpolationMode(graphics2, &mode);
211 todo_wine
212 expect(InterpolationModeBicubic, mode);
213 GdipDeleteGraphics(graphics1);
214 GdipDeleteGraphics(graphics2);
216 /* You can't restore a state to a graphics object that didn't save it. */
217 GdipCreateFromHDC(hdc, &graphics1);
218 GdipCreateFromHDC(hdc, &graphics2);
219 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
220 GdipSaveGraphics(graphics1, &state_a);
221 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
222 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
223 GdipRestoreGraphics(graphics2, state_a);
224 GdipGetInterpolationMode(graphics2, &mode);
225 expect(InterpolationModeNearestNeighbor, mode);
226 GdipDeleteGraphics(graphics1);
227 GdipDeleteGraphics(graphics2);
229 log_state(state_a, &state_log);
231 /* The same state value should never be returned twice. */
232 todo_wine
233 check_no_duplicates(state_log);
235 ReleaseDC(0, hdc);
238 static void test_GdipDrawArc(void)
240 GpStatus status;
241 GpGraphics *graphics = NULL;
242 GpPen *pen = NULL;
243 HDC hdc = GetDC(0);
245 /* make a graphics object and pen object */
246 status = GdipCreateFromHDC(hdc, &graphics);
247 expect(Ok, status);
248 ok(hdc != NULL, "Expected HDC to be initialized\n");
250 status = GdipCreateFromHDC(hdc, &graphics);
251 expect(Ok, status);
252 ok(graphics != NULL, "Expected graphics to be initialized\n");
254 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
255 expect(Ok, status);
256 ok(pen != NULL, "Expected pen to be initialized\n");
258 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
259 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
260 expect(InvalidParameter, status);
262 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
263 expect(InvalidParameter, status);
265 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
266 expect(InvalidParameter, status);
268 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
269 expect(InvalidParameter, status);
271 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
272 expect(InvalidParameter, status);
274 /* successful case */
275 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
276 expect(Ok, status);
278 GdipDeletePen(pen);
279 GdipDeleteGraphics(graphics);
281 ReleaseDC(0, hdc);
284 static void test_GdipDrawArcI(void)
286 GpStatus status;
287 GpGraphics *graphics = NULL;
288 GpPen *pen = NULL;
289 HDC hdc = GetDC(0);
291 /* make a graphics object and pen object */
292 status = GdipCreateFromHDC(hdc, &graphics);
293 expect(Ok, status);
294 ok(hdc != NULL, "Expected HDC to be initialized\n");
296 status = GdipCreateFromHDC(hdc, &graphics);
297 expect(Ok, status);
298 ok(graphics != NULL, "Expected graphics to be initialized\n");
300 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
301 expect(Ok, status);
302 ok(pen != NULL, "Expected pen to be initialized\n");
304 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
305 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
306 expect(InvalidParameter, status);
308 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
309 expect(InvalidParameter, status);
311 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
312 expect(InvalidParameter, status);
314 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
315 expect(InvalidParameter, status);
317 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
318 expect(InvalidParameter, status);
320 /* successful case */
321 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
322 expect(Ok, status);
324 GdipDeletePen(pen);
325 GdipDeleteGraphics(graphics);
327 ReleaseDC(0, hdc);
330 static void test_GdipDrawBezierI(void)
332 GpStatus status;
333 GpGraphics *graphics = NULL;
334 GpPen *pen = NULL;
335 HDC hdc = GetDC(0);
337 /* make a graphics object and pen object */
338 status = GdipCreateFromHDC(hdc, &graphics);
339 expect(Ok, status);
340 ok(hdc != NULL, "Expected HDC to be initialized\n");
342 status = GdipCreateFromHDC(hdc, &graphics);
343 expect(Ok, status);
344 ok(graphics != NULL, "Expected graphics to be initialized\n");
346 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
347 expect(Ok, status);
348 ok(pen != NULL, "Expected pen to be initialized\n");
350 /* InvalidParameter cases: null graphics, null pen */
351 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
352 expect(InvalidParameter, status);
354 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
355 expect(InvalidParameter, status);
357 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
358 expect(InvalidParameter, status);
360 /* successful case */
361 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
362 expect(Ok, status);
364 GdipDeletePen(pen);
365 GdipDeleteGraphics(graphics);
367 ReleaseDC(0, hdc);
370 static void test_GdipDrawLineI(void)
372 GpStatus status;
373 GpGraphics *graphics = NULL;
374 GpPen *pen = NULL;
375 HDC hdc = GetDC(0);
377 /* make a graphics object and pen object */
378 status = GdipCreateFromHDC(hdc, &graphics);
379 expect(Ok, status);
380 ok(hdc != NULL, "Expected HDC to be initialized\n");
382 status = GdipCreateFromHDC(hdc, &graphics);
383 expect(Ok, status);
384 ok(graphics != NULL, "Expected graphics to be initialized\n");
386 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
387 expect(Ok, status);
388 ok(pen != NULL, "Expected pen to be initialized\n");
390 /* InvalidParameter cases: null graphics, null pen */
391 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
392 expect(InvalidParameter, status);
394 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
395 expect(InvalidParameter, status);
397 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
398 expect(InvalidParameter, status);
400 /* successful case */
401 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
402 expect(Ok, status);
404 GdipDeletePen(pen);
405 GdipDeleteGraphics(graphics);
407 ReleaseDC(0, hdc);
410 static void test_GdipDrawLinesI(void)
412 GpStatus status;
413 GpGraphics *graphics = NULL;
414 GpPen *pen = NULL;
415 GpPoint *ptf = NULL;
416 HDC hdc = GetDC(0);
418 /* make a graphics object and pen object */
419 status = GdipCreateFromHDC(hdc, &graphics);
420 expect(Ok, status);
421 ok(hdc != NULL, "Expected HDC to be initialized\n");
423 status = GdipCreateFromHDC(hdc, &graphics);
424 expect(Ok, status);
425 ok(graphics != NULL, "Expected graphics to be initialized\n");
427 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
428 expect(Ok, status);
429 ok(pen != NULL, "Expected pen to be initialized\n");
431 /* make some arbitrary valid points*/
432 ptf = GdipAlloc(2 * sizeof(GpPointF));
434 ptf[0].X = 1;
435 ptf[0].Y = 1;
437 ptf[1].X = 2;
438 ptf[1].Y = 2;
440 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
441 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
442 expect(InvalidParameter, status);
444 status = GdipDrawLinesI(graphics, pen, ptf, 0);
445 expect(InvalidParameter, status);
447 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
448 expect(InvalidParameter, status);
450 status = GdipDrawLinesI(NULL, pen, ptf, 2);
451 expect(InvalidParameter, status);
453 /* successful case */
454 status = GdipDrawLinesI(graphics, pen, ptf, 2);
455 expect(Ok, status);
457 GdipFree(ptf);
458 GdipDeletePen(pen);
459 GdipDeleteGraphics(graphics);
461 ReleaseDC(0, hdc);
464 static void test_Get_Release_DC(void)
466 GpStatus status;
467 GpGraphics *graphics = NULL;
468 GpPen *pen;
469 GpSolidFill *brush;
470 GpPath *path;
471 HDC hdc = GetDC(0);
472 HDC retdc;
473 REAL r;
474 CompositingQuality quality;
475 CompositingMode compmode;
476 InterpolationMode intmode;
477 GpMatrix *m;
478 GpRegion *region;
479 GpUnit unit;
480 PixelOffsetMode offsetmode;
481 SmoothingMode smoothmode;
482 TextRenderingHint texthint;
483 GpPointF ptf[5];
484 GpPoint pt[5];
485 GpRectF rectf[2];
486 GpRect rect[2];
487 GpRegion *clip;
488 INT i;
489 BOOL res;
490 ARGB color = 0x00000000;
491 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
493 pt[0].X = 10;
494 pt[0].Y = 10;
495 pt[1].X = 20;
496 pt[1].Y = 15;
497 pt[2].X = 40;
498 pt[2].Y = 80;
499 pt[3].X = -20;
500 pt[3].Y = 20;
501 pt[4].X = 50;
502 pt[4].Y = 110;
504 for(i = 0; i < 5;i++){
505 ptf[i].X = (REAL)pt[i].X;
506 ptf[i].Y = (REAL)pt[i].Y;
509 rect[0].X = 0;
510 rect[0].Y = 0;
511 rect[0].Width = 50;
512 rect[0].Height = 70;
513 rect[1].X = 0;
514 rect[1].Y = 0;
515 rect[1].Width = 10;
516 rect[1].Height = 20;
518 for(i = 0; i < 2;i++){
519 rectf[i].X = (REAL)rect[i].X;
520 rectf[i].Y = (REAL)rect[i].Y;
521 rectf[i].Height = (REAL)rect[i].Height;
522 rectf[i].Width = (REAL)rect[i].Width;
525 GdipCreateMatrix(&m);
526 GdipCreateRegion(&region);
527 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
528 GdipCreatePath(FillModeAlternate, &path);
529 GdipCreateRegion(&clip);
531 status = GdipCreateFromHDC(hdc, &graphics);
532 expect(Ok, status);
533 ok(graphics != NULL, "Expected graphics to be initialized\n");
534 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
535 expect(Ok, status);
537 /* NULL arguments */
538 status = GdipGetDC(NULL, NULL);
539 expect(InvalidParameter, status);
540 status = GdipGetDC(graphics, NULL);
541 expect(InvalidParameter, status);
542 status = GdipGetDC(NULL, &retdc);
543 expect(InvalidParameter, status);
545 status = GdipReleaseDC(NULL, NULL);
546 expect(InvalidParameter, status);
547 status = GdipReleaseDC(graphics, NULL);
548 expect(InvalidParameter, status);
549 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
550 expect(InvalidParameter, status);
552 /* Release without Get */
553 status = GdipReleaseDC(graphics, hdc);
554 expect(InvalidParameter, status);
556 retdc = NULL;
557 status = GdipGetDC(graphics, &retdc);
558 expect(Ok, status);
559 ok(retdc == hdc, "Invalid HDC returned\n");
560 /* call it once more */
561 status = GdipGetDC(graphics, &retdc);
562 expect(ObjectBusy, status);
564 /* try all Graphics calls here */
565 status = Ok;
566 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
567 expect(ObjectBusy, status); status = Ok;
568 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
569 expect(ObjectBusy, status); status = Ok;
570 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
571 expect(ObjectBusy, status); status = Ok;
572 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
573 expect(ObjectBusy, status); status = Ok;
574 status = GdipDrawBeziers(graphics, pen, ptf, 5);
575 expect(ObjectBusy, status); status = Ok;
576 status = GdipDrawBeziersI(graphics, pen, pt, 5);
577 expect(ObjectBusy, status); status = Ok;
578 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
579 expect(ObjectBusy, status); status = Ok;
580 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
581 expect(ObjectBusy, status); status = Ok;
582 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
583 expect(ObjectBusy, status); status = Ok;
584 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
585 expect(ObjectBusy, status); status = Ok;
586 status = GdipDrawCurve(graphics, pen, ptf, 5);
587 expect(ObjectBusy, status); status = Ok;
588 status = GdipDrawCurveI(graphics, pen, pt, 5);
589 expect(ObjectBusy, status); status = Ok;
590 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
591 expect(ObjectBusy, status); status = Ok;
592 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
593 expect(ObjectBusy, status); status = Ok;
594 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
595 expect(ObjectBusy, status); status = Ok;
596 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
597 expect(ObjectBusy, status); status = Ok;
598 /* GdipDrawImage/GdipDrawImageI */
599 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
600 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
601 /* GdipDrawImageRect/GdipDrawImageRectI */
602 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
603 expect(ObjectBusy, status); status = Ok;
604 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
605 expect(ObjectBusy, status); status = Ok;
606 status = GdipDrawLines(graphics, pen, ptf, 5);
607 expect(ObjectBusy, status); status = Ok;
608 status = GdipDrawLinesI(graphics, pen, pt, 5);
609 expect(ObjectBusy, status); status = Ok;
610 status = GdipDrawPath(graphics, pen, path);
611 expect(ObjectBusy, status); status = Ok;
612 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
613 expect(ObjectBusy, status); status = Ok;
614 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
615 expect(ObjectBusy, status); status = Ok;
616 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
617 expect(ObjectBusy, status); status = Ok;
618 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
619 expect(ObjectBusy, status); status = Ok;
620 status = GdipDrawRectangles(graphics, pen, rectf, 2);
621 expect(ObjectBusy, status); status = Ok;
622 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
623 expect(ObjectBusy, status); status = Ok;
624 /* GdipDrawString */
625 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
626 expect(ObjectBusy, status); status = Ok;
627 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
628 expect(ObjectBusy, status); status = Ok;
629 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
630 expect(ObjectBusy, status); status = Ok;
631 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
632 expect(ObjectBusy, status); status = Ok;
633 status = GdipFillPath(graphics, (GpBrush*)brush, path);
634 expect(ObjectBusy, status); status = Ok;
635 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
636 expect(ObjectBusy, status); status = Ok;
637 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
638 expect(ObjectBusy, status); status = Ok;
639 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
640 expect(ObjectBusy, status); status = Ok;
641 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
642 expect(ObjectBusy, status); status = Ok;
643 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
644 expect(ObjectBusy, status); status = Ok;
645 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
646 expect(ObjectBusy, status); status = Ok;
647 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
648 expect(ObjectBusy, status); status = Ok;
649 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
650 expect(ObjectBusy, status); status = Ok;
651 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
652 expect(ObjectBusy, status); status = Ok;
653 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
654 expect(ObjectBusy, status); status = Ok;
655 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
656 expect(ObjectBusy, status); status = Ok;
657 status = GdipFlush(graphics, FlushIntentionFlush);
658 expect(ObjectBusy, status); status = Ok;
659 status = GdipGetClipBounds(graphics, rectf);
660 expect(ObjectBusy, status); status = Ok;
661 status = GdipGetClipBoundsI(graphics, rect);
662 expect(ObjectBusy, status); status = Ok;
663 status = GdipGetCompositingMode(graphics, &compmode);
664 expect(ObjectBusy, status); status = Ok;
665 status = GdipGetCompositingQuality(graphics, &quality);
666 expect(ObjectBusy, status); status = Ok;
667 status = GdipGetInterpolationMode(graphics, &intmode);
668 expect(ObjectBusy, status); status = Ok;
669 status = GdipGetNearestColor(graphics, &color);
670 expect(ObjectBusy, status); status = Ok;
671 status = GdipGetPageScale(graphics, &r);
672 expect(ObjectBusy, status); status = Ok;
673 status = GdipGetPageUnit(graphics, &unit);
674 expect(ObjectBusy, status); status = Ok;
675 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
676 expect(ObjectBusy, status); status = Ok;
677 status = GdipGetSmoothingMode(graphics, &smoothmode);
678 expect(ObjectBusy, status); status = Ok;
679 status = GdipGetTextRenderingHint(graphics, &texthint);
680 expect(ObjectBusy, status); status = Ok;
681 status = GdipGetWorldTransform(graphics, m);
682 expect(ObjectBusy, status); status = Ok;
683 status = GdipGraphicsClear(graphics, 0xdeadbeef);
684 expect(ObjectBusy, status); status = Ok;
685 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
686 expect(ObjectBusy, status); status = Ok;
687 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
688 expect(ObjectBusy, status); status = Ok;
689 /* GdipMeasureCharacterRanges */
690 /* GdipMeasureString */
691 status = GdipResetClip(graphics);
692 expect(ObjectBusy, status); status = Ok;
693 status = GdipResetWorldTransform(graphics);
694 expect(ObjectBusy, status); status = Ok;
695 /* GdipRestoreGraphics */
696 status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
697 expect(ObjectBusy, status); status = Ok;
698 /* GdipSaveGraphics */
699 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
700 expect(ObjectBusy, status); status = Ok;
701 status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
702 expect(ObjectBusy, status); status = Ok;
703 status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
704 expect(ObjectBusy, status); status = Ok;
705 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
706 expect(ObjectBusy, status); status = Ok;
707 status = GdipSetPageScale(graphics, 1.0);
708 expect(ObjectBusy, status); status = Ok;
709 status = GdipSetPageUnit(graphics, UnitWorld);
710 expect(ObjectBusy, status); status = Ok;
711 status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
712 expect(ObjectBusy, status); status = Ok;
713 status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
714 expect(ObjectBusy, status); status = Ok;
715 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
716 expect(ObjectBusy, status); status = Ok;
717 status = GdipSetWorldTransform(graphics, m);
718 expect(ObjectBusy, status); status = Ok;
719 status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
720 expect(ObjectBusy, status); status = Ok;
721 status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
722 expect(ObjectBusy, status); status = Ok;
723 status = GdipSetClipPath(graphics, path, CombineModeReplace);
724 expect(ObjectBusy, status); status = Ok;
725 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
726 expect(ObjectBusy, status); status = Ok;
727 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
728 expect(ObjectBusy, status); status = Ok;
729 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
730 expect(ObjectBusy, status); status = Ok;
731 status = GdipTranslateClip(graphics, 0.0, 0.0);
732 expect(ObjectBusy, status); status = Ok;
733 status = GdipTranslateClipI(graphics, 0, 0);
734 expect(ObjectBusy, status); status = Ok;
735 status = GdipDrawPolygon(graphics, pen, ptf, 5);
736 expect(ObjectBusy, status); status = Ok;
737 status = GdipDrawPolygonI(graphics, pen, pt, 5);
738 expect(ObjectBusy, status); status = Ok;
739 status = GdipGetDpiX(graphics, &r);
740 expect(ObjectBusy, status); status = Ok;
741 status = GdipGetDpiY(graphics, &r);
742 expect(ObjectBusy, status); status = Ok;
743 status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
744 status = GdipGetClip(graphics, region);
745 expect(ObjectBusy, status); status = Ok;
746 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
747 expect(ObjectBusy, status); status = Ok;
748 /* try to delete before release */
749 status = GdipDeleteGraphics(graphics);
750 expect(ObjectBusy, status);
752 status = GdipReleaseDC(graphics, retdc);
753 expect(Ok, status);
755 GdipDeletePen(pen);
756 GdipDeleteGraphics(graphics);
758 GdipDeletePath(path);
759 GdipDeleteBrush((GpBrush*)brush);
760 GdipDeleteRegion(region);
761 GdipDeleteMatrix(m);
762 DeleteObject(hrgn);
764 ReleaseDC(0, hdc);
767 static void test_transformpoints(void)
769 GpStatus status;
770 GpGraphics *graphics = NULL;
771 HDC hdc = GetDC(0);
772 GpPointF ptf[2];
774 status = GdipCreateFromHDC(hdc, &graphics);
775 expect(Ok, status);
777 /* NULL arguments */
778 status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
779 expect(InvalidParameter, status);
780 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
781 expect(InvalidParameter, status);
782 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
783 expect(InvalidParameter, status);
784 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
785 expect(InvalidParameter, status);
787 ptf[0].X = 1.0;
788 ptf[0].Y = 0.0;
789 ptf[1].X = 0.0;
790 ptf[1].Y = 1.0;
791 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
792 expect(Ok, status);
793 expectf(1.0, ptf[0].X);
794 expectf(0.0, ptf[0].Y);
795 expectf(0.0, ptf[1].X);
796 expectf(1.0, ptf[1].Y);
798 status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
799 expect(Ok, status);
800 status = GdipSetPageUnit(graphics, UnitPixel);
801 expect(Ok, status);
802 status = GdipSetPageScale(graphics, 3.0);
803 expect(Ok, status);
805 ptf[0].X = 1.0;
806 ptf[0].Y = 0.0;
807 ptf[1].X = 0.0;
808 ptf[1].Y = 1.0;
809 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
810 expect(Ok, status);
811 expectf(18.0, ptf[0].X);
812 expectf(15.0, ptf[0].Y);
813 expectf(15.0, ptf[1].X);
814 expectf(18.0, ptf[1].Y);
816 ptf[0].X = 1.0;
817 ptf[0].Y = 0.0;
818 ptf[1].X = 0.0;
819 ptf[1].Y = 1.0;
820 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
821 expect(Ok, status);
822 expectf(6.0, ptf[0].X);
823 expectf(5.0, ptf[0].Y);
824 expectf(5.0, ptf[1].X);
825 expectf(6.0, ptf[1].Y);
827 ptf[0].X = 1.0;
828 ptf[0].Y = 0.0;
829 ptf[1].X = 0.0;
830 ptf[1].Y = 1.0;
831 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
832 expect(Ok, status);
833 expectf(3.0, ptf[0].X);
834 expectf(0.0, ptf[0].Y);
835 expectf(0.0, ptf[1].X);
836 expectf(3.0, ptf[1].Y);
838 ptf[0].X = 18.0;
839 ptf[0].Y = 15.0;
840 ptf[1].X = 15.0;
841 ptf[1].Y = 18.0;
842 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
843 expect(Ok, status);
844 expectf(1.0, ptf[0].X);
845 expectf(0.0, ptf[0].Y);
846 expectf(0.0, ptf[1].X);
847 expectf(1.0, ptf[1].Y);
849 ptf[0].X = 6.0;
850 ptf[0].Y = 5.0;
851 ptf[1].X = 5.0;
852 ptf[1].Y = 6.0;
853 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
854 expect(Ok, status);
855 expectf(1.0, ptf[0].X);
856 expectf(0.0, ptf[0].Y);
857 expectf(0.0, ptf[1].X);
858 expectf(1.0, ptf[1].Y);
860 ptf[0].X = 3.0;
861 ptf[0].Y = 0.0;
862 ptf[1].X = 0.0;
863 ptf[1].Y = 3.0;
864 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
865 expect(Ok, status);
866 expectf(1.0, ptf[0].X);
867 expectf(0.0, ptf[0].Y);
868 expectf(0.0, ptf[1].X);
869 expectf(1.0, ptf[1].Y);
871 GdipDeleteGraphics(graphics);
872 ReleaseDC(0, hdc);
875 static void test_get_set_clip(void)
877 GpStatus status;
878 GpGraphics *graphics = NULL;
879 HDC hdc = GetDC(0);
880 GpRegion *clip;
881 GpRectF rect;
882 BOOL res;
884 status = GdipCreateFromHDC(hdc, &graphics);
885 expect(Ok, status);
887 rect.X = rect.Y = 0.0;
888 rect.Height = rect.Width = 100.0;
890 status = GdipCreateRegionRect(&rect, &clip);
892 /* NULL arguments */
893 status = GdipGetClip(NULL, NULL);
894 expect(InvalidParameter, status);
895 status = GdipGetClip(graphics, NULL);
896 expect(InvalidParameter, status);
897 status = GdipGetClip(NULL, clip);
898 expect(InvalidParameter, status);
900 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
901 expect(InvalidParameter, status);
902 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
903 expect(InvalidParameter, status);
905 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
906 expect(InvalidParameter, status);
907 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
908 expect(InvalidParameter, status);
910 res = FALSE;
911 status = GdipGetClip(graphics, clip);
912 expect(Ok, status);
913 status = GdipIsInfiniteRegion(clip, graphics, &res);
914 expect(Ok, status);
915 expect(TRUE, res);
917 /* remains infinite after reset */
918 res = FALSE;
919 status = GdipResetClip(graphics);
920 expect(Ok, status);
921 status = GdipGetClip(graphics, clip);
922 expect(Ok, status);
923 status = GdipIsInfiniteRegion(clip, graphics, &res);
924 expect(Ok, status);
925 expect(TRUE, res);
927 /* set to empty and then reset to infinite */
928 status = GdipSetEmpty(clip);
929 expect(Ok, status);
930 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
931 expect(Ok, status);
933 status = GdipGetClip(graphics, clip);
934 expect(Ok, status);
935 res = FALSE;
936 status = GdipIsEmptyRegion(clip, graphics, &res);
937 expect(Ok, status);
938 expect(TRUE, res);
939 status = GdipResetClip(graphics);
940 expect(Ok, status);
941 status = GdipGetClip(graphics, clip);
942 expect(Ok, status);
943 res = FALSE;
944 status = GdipIsInfiniteRegion(clip, graphics, &res);
945 expect(Ok, status);
946 expect(TRUE, res);
948 GdipDeleteRegion(clip);
950 GdipDeleteGraphics(graphics);
951 ReleaseDC(0, hdc);
954 static void test_isempty(void)
956 GpStatus status;
957 GpGraphics *graphics = NULL;
958 HDC hdc = GetDC(0);
959 GpRegion *clip;
960 BOOL res;
962 status = GdipCreateFromHDC(hdc, &graphics);
963 expect(Ok, status);
965 status = GdipCreateRegion(&clip);
966 expect(Ok, status);
968 /* NULL */
969 status = GdipIsClipEmpty(NULL, NULL);
970 expect(InvalidParameter, status);
971 status = GdipIsClipEmpty(graphics, NULL);
972 expect(InvalidParameter, status);
973 status = GdipIsClipEmpty(NULL, &res);
974 expect(InvalidParameter, status);
976 /* default is infinite */
977 res = TRUE;
978 status = GdipIsClipEmpty(graphics, &res);
979 expect(Ok, status);
980 expect(FALSE, res);
982 GdipDeleteRegion(clip);
984 GdipDeleteGraphics(graphics);
985 ReleaseDC(0, hdc);
988 static void test_clear(void)
990 GpStatus status;
992 status = GdipGraphicsClear(NULL, 0xdeadbeef);
993 expect(InvalidParameter, status);
996 static void test_textcontrast(void)
998 GpStatus status;
999 HDC hdc = GetDC(0);
1000 GpGraphics *graphics;
1001 UINT contrast;
1003 status = GdipGetTextContrast(NULL, NULL);
1004 expect(InvalidParameter, status);
1006 status = GdipCreateFromHDC(hdc, &graphics);
1007 expect(Ok, status);
1009 status = GdipGetTextContrast(graphics, NULL);
1010 expect(InvalidParameter, status);
1011 status = GdipGetTextContrast(graphics, &contrast);
1012 expect(4, contrast);
1014 GdipDeleteGraphics(graphics);
1015 ReleaseDC(0, hdc);
1018 static void test_GdipDrawString(void)
1020 GpStatus status;
1021 GpGraphics *graphics = NULL;
1022 GpFont *fnt = NULL;
1023 RectF rect;
1024 GpStringFormat *format;
1025 GpBrush *brush;
1026 LOGFONTA logfont;
1027 HDC hdc = GetDC(0);
1028 static const WCHAR string[] = {'T','e','s','t',0};
1030 memset(&logfont,0,sizeof(logfont));
1031 strcpy(logfont.lfFaceName,"Arial");
1032 logfont.lfHeight = 12;
1033 logfont.lfCharSet = DEFAULT_CHARSET;
1035 status = GdipCreateFromHDC(hdc, &graphics);
1036 expect(Ok, status);
1038 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
1039 if (status == FileNotFound)
1041 skip("Arial not installed.\n");
1042 return;
1044 expect(Ok, status);
1046 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
1047 expect(Ok, status);
1049 status = GdipCreateStringFormat(0,0,&format);
1050 expect(Ok, status);
1052 rect.X = 0;
1053 rect.Y = 0;
1054 rect.Width = 0;
1055 rect.Height = 12;
1057 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
1058 expect(Ok, status);
1060 GdipDeleteGraphics(graphics);
1061 GdipDeleteBrush(brush);
1062 GdipDeleteFont(fnt);
1063 GdipDeleteStringFormat(format);
1065 ReleaseDC(0, hdc);
1069 START_TEST(graphics)
1071 struct GdiplusStartupInput gdiplusStartupInput;
1072 ULONG_PTR gdiplusToken;
1074 gdiplusStartupInput.GdiplusVersion = 1;
1075 gdiplusStartupInput.DebugEventCallback = NULL;
1076 gdiplusStartupInput.SuppressBackgroundThread = 0;
1077 gdiplusStartupInput.SuppressExternalCodecs = 0;
1079 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1081 test_constructor_destructor();
1082 test_save_restore();
1083 test_GdipDrawBezierI();
1084 test_GdipDrawArc();
1085 test_GdipDrawArcI();
1086 test_GdipDrawLineI();
1087 test_GdipDrawLinesI();
1088 test_GdipDrawString();
1089 test_Get_Release_DC();
1090 test_transformpoints();
1091 test_get_set_clip();
1092 test_isempty();
1093 test_clear();
1094 test_textcontrast();
1096 GdiplusShutdown(gdiplusToken);