crypt32: Make sure we show Unicode characters (Dutch translation).
[wine] / dlls / gdiplus / tests / graphics.c
1 /*
2  * Unit test suite for graphics objects
3  *
4  * Copyright (C) 2007 Google (Evan Stade)
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wingdi.h"
24 #include "wine/test.h"
25 #include <math.h>
26
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)
30
31 static void test_constructor_destructor(void)
32 {
33     GpStatus stat;
34     GpGraphics *graphics = NULL;
35     HDC hdc = GetDC(0);
36
37     stat = GdipCreateFromHDC(NULL, &graphics);
38     expect(OutOfMemory, stat);
39     stat = GdipDeleteGraphics(graphics);
40     expect(InvalidParameter, stat);
41
42     stat = GdipCreateFromHDC(hdc, &graphics);
43     expect(Ok, stat);
44     stat = GdipDeleteGraphics(graphics);
45     expect(Ok, stat);
46
47     stat = GdipCreateFromHWND(NULL, &graphics);
48     expect(Ok, stat);
49     stat = GdipDeleteGraphics(graphics);
50     expect(Ok, stat);
51
52     stat = GdipCreateFromHWNDICM(NULL, &graphics);
53     expect(Ok, stat);
54     stat = GdipDeleteGraphics(graphics);
55     expect(Ok, stat);
56
57     stat = GdipDeleteGraphics(NULL);
58     expect(InvalidParameter, stat);
59     ReleaseDC(0, hdc);
60 }
61
62 typedef struct node{
63     GraphicsState data;
64     struct node * next;
65 } node;
66
67 /* Linked list prepend function. */
68 static void log_state(GraphicsState data, node ** log)
69 {
70     node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
71
72     new_entry->data = data;
73     new_entry->next = *log;
74     *log = new_entry;
75 }
76
77 /* Checks if there are duplicates in the list, and frees it. */
78 static void check_no_duplicates(node * log)
79 {
80     INT dups = 0;
81     node * temp = NULL;
82     node * temp2 = NULL;
83     node * orig = log;
84
85     if(!log)
86         goto end;
87
88     do{
89         temp = log;
90         while((temp = temp->next)){
91             if(log->data == temp->data){
92                 dups++;
93                 break;
94             }
95             if(dups > 0)
96                 break;
97         }
98     }while((log = log->next));
99
100     temp = orig;
101     do{
102         temp2 = temp->next;
103         HeapFree(GetProcessHeap(), 0, temp);
104         temp = temp2;
105     }while(temp);
106
107 end:
108     expect(0, dups);
109 }
110
111 static void test_save_restore(void)
112 {
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;
120
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);
128
129     log_state(state_a, &state_log);
130
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);
143
144     log_state(state_a, &state_log);
145
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);
164
165     log_state(state_a, &state_log);
166     log_state(state_b, &state_log);
167
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);
190
191     log_state(state_a, &state_log);
192     log_state(state_b, &state_log);
193     log_state(state_c, &state_log);
194
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);
215
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);
228
229     log_state(state_a, &state_log);
230
231     /* The same state value should never be returned twice. */
232     todo_wine
233         check_no_duplicates(state_log);
234
235     ReleaseDC(0, hdc);
236 }
237
238 static void test_GdipDrawArc(void)
239 {
240     GpStatus status;
241     GpGraphics *graphics = NULL;
242     GpPen *pen = NULL;
243     HDC hdc = GetDC(0);
244
245     /* make a graphics object and pen object */
246     ok(hdc != NULL, "Expected HDC to be initialized\n");
247
248     status = GdipCreateFromHDC(hdc, &graphics);
249     expect(Ok, status);
250     ok(graphics != NULL, "Expected graphics to be initialized\n");
251
252     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
253     expect(Ok, status);
254     ok(pen != NULL, "Expected pen to be initialized\n");
255
256     /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
257     status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
258     expect(InvalidParameter, status);
259
260     status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
261     expect(InvalidParameter, status);
262
263     status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
264     expect(InvalidParameter, status);
265
266     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
267     expect(InvalidParameter, status);
268
269     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
270     expect(InvalidParameter, status);
271
272     /* successful case */
273     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
274     expect(Ok, status);
275
276     GdipDeletePen(pen);
277     GdipDeleteGraphics(graphics);
278
279     ReleaseDC(0, hdc);
280 }
281
282 static void test_GdipDrawArcI(void)
283 {
284     GpStatus status;
285     GpGraphics *graphics = NULL;
286     GpPen *pen = NULL;
287     HDC hdc = GetDC(0);
288
289     /* make a graphics object and pen object */
290     ok(hdc != NULL, "Expected HDC to be initialized\n");
291
292     status = GdipCreateFromHDC(hdc, &graphics);
293     expect(Ok, status);
294     ok(graphics != NULL, "Expected graphics to be initialized\n");
295
296     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
297     expect(Ok, status);
298     ok(pen != NULL, "Expected pen to be initialized\n");
299
300     /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
301     status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
302     expect(InvalidParameter, status);
303
304     status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
305     expect(InvalidParameter, status);
306
307     status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
308     expect(InvalidParameter, status);
309
310     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
311     expect(InvalidParameter, status);
312
313     status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
314     expect(InvalidParameter, status);
315
316     /* successful case */
317     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
318     expect(Ok, status);
319
320     GdipDeletePen(pen);
321     GdipDeleteGraphics(graphics);
322
323     ReleaseDC(0, hdc);
324 }
325
326 static void test_GdipDrawBezierI(void)
327 {
328     GpStatus status;
329     GpGraphics *graphics = NULL;
330     GpPen *pen = NULL;
331     HDC hdc = GetDC(0);
332
333     /* make a graphics object and pen object */
334     ok(hdc != NULL, "Expected HDC to be initialized\n");
335
336     status = GdipCreateFromHDC(hdc, &graphics);
337     expect(Ok, status);
338     ok(graphics != NULL, "Expected graphics to be initialized\n");
339
340     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
341     expect(Ok, status);
342     ok(pen != NULL, "Expected pen to be initialized\n");
343
344     /* InvalidParameter cases: null graphics, null pen */
345     status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
346     expect(InvalidParameter, status);
347
348     status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
349     expect(InvalidParameter, status);
350
351     status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
352     expect(InvalidParameter, status);
353
354     /* successful case */
355     status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
356     expect(Ok, status);
357
358     GdipDeletePen(pen);
359     GdipDeleteGraphics(graphics);
360
361     ReleaseDC(0, hdc);
362 }
363
364 static void test_GdipDrawCurve3(void)
365 {
366     GpStatus status;
367     GpGraphics *graphics = NULL;
368     GpPen *pen = NULL;
369     HDC hdc = GetDC(0);
370     GpPointF points[3];
371
372     points[0].X = 0;
373     points[0].Y = 0;
374
375     points[1].X = 40;
376     points[1].Y = 20;
377
378     points[2].X = 10;
379     points[2].Y = 40;
380
381     /* make a graphics object and pen object */
382     ok(hdc != NULL, "Expected HDC to be initialized\n");
383
384     status = GdipCreateFromHDC(hdc, &graphics);
385     expect(Ok, status);
386     ok(graphics != NULL, "Expected graphics to be initialized\n");
387
388     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
389     expect(Ok, status);
390     ok(pen != NULL, "Expected pen to be initialized\n");
391
392     /* InvalidParameter cases: null graphics, null pen */
393     status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
394     expect(InvalidParameter, status);
395
396     status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
397     expect(InvalidParameter, status);
398
399     status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
400     expect(InvalidParameter, status);
401
402     /* InvalidParameter cases: invalid count */
403     status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
404     expect(InvalidParameter, status);
405
406     status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
407     expect(InvalidParameter, status);
408
409     status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
410     expect(InvalidParameter, status);
411
412     status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
413     expect(InvalidParameter, status);
414
415     /* InvalidParameter cases: invalid number of segments */
416     status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
417     expect(InvalidParameter, status);
418
419     status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
420     expect(InvalidParameter, status);
421
422     status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
423     expect(InvalidParameter, status);
424
425     /* Valid test cases */
426     status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
427     expect(Ok, status);
428
429     status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
430     expect(Ok, status);
431
432     status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
433     expect(Ok, status);
434
435     status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
436     expect(Ok, status);
437
438     GdipDeletePen(pen);
439     GdipDeleteGraphics(graphics);
440
441     ReleaseDC(0, hdc);
442 }
443
444 static void test_GdipDrawCurve3I(void)
445 {
446     GpStatus status;
447     GpGraphics *graphics = NULL;
448     GpPen *pen = NULL;
449     HDC hdc = GetDC(0);
450     GpPoint points[3];
451
452     points[0].X = 0;
453     points[0].Y = 0;
454
455     points[1].X = 40;
456     points[1].Y = 20;
457
458     points[2].X = 10;
459     points[2].Y = 40;
460
461     /* make a graphics object and pen object */
462     ok(hdc != NULL, "Expected HDC to be initialized\n");
463
464     status = GdipCreateFromHDC(hdc, &graphics);
465     expect(Ok, status);
466     ok(graphics != NULL, "Expected graphics to be initialized\n");
467
468     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
469     expect(Ok, status);
470     ok(pen != NULL, "Expected pen to be initialized\n");
471
472     /* InvalidParameter cases: null graphics, null pen */
473     status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
474     expect(InvalidParameter, status);
475
476     status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
477     expect(InvalidParameter, status);
478
479     status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
480     expect(InvalidParameter, status);
481
482     /* InvalidParameter cases: invalid count */
483     status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
484     expect(OutOfMemory, status);
485
486     status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
487     expect(InvalidParameter, status);
488
489     status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
490     expect(InvalidParameter, status);
491
492     status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
493     expect(InvalidParameter, status);
494
495     /* InvalidParameter cases: invalid number of segments */
496     status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
497     expect(InvalidParameter, status);
498
499     status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
500     expect(InvalidParameter, status);
501
502     status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
503     expect(InvalidParameter, status);
504
505     /* Valid test cases */
506     status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
507     expect(Ok, status);
508
509     status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
510     expect(Ok, status);
511
512     status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
513     expect(Ok, status);
514
515     status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
516     expect(Ok, status);
517
518     GdipDeletePen(pen);
519     GdipDeleteGraphics(graphics);
520
521     ReleaseDC(0, hdc);
522 }
523
524 static void test_GdipDrawCurve2(void)
525 {
526     GpStatus status;
527     GpGraphics *graphics = NULL;
528     GpPen *pen = NULL;
529     HDC hdc = GetDC(0);
530     GpPointF points[3];
531
532     points[0].X = 0;
533     points[0].Y = 0;
534
535     points[1].X = 40;
536     points[1].Y = 20;
537
538     points[2].X = 10;
539     points[2].Y = 40;
540
541     /* make a graphics object and pen object */
542     ok(hdc != NULL, "Expected HDC to be initialized\n");
543
544     status = GdipCreateFromHDC(hdc, &graphics);
545     expect(Ok, status);
546     ok(graphics != NULL, "Expected graphics to be initialized\n");
547
548     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
549     expect(Ok, status);
550     ok(pen != NULL, "Expected pen to be initialized\n");
551
552     /* InvalidParameter cases: null graphics, null pen */
553     status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
554     expect(InvalidParameter, status);
555
556     status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
557     expect(InvalidParameter, status);
558
559     status = GdipDrawCurve2(NULL, pen, points, 3, 1);
560     expect(InvalidParameter, status);
561
562     /* InvalidParameter cases: invalid count */
563     status = GdipDrawCurve2(graphics, pen, points, -1, 1);
564     expect(InvalidParameter, status);
565
566     status = GdipDrawCurve2(graphics, pen, points, 0, 1);
567     expect(InvalidParameter, status);
568
569     status = GdipDrawCurve2(graphics, pen, points, 1, 1);
570     expect(InvalidParameter, status);
571
572     /* Valid test cases */
573     status = GdipDrawCurve2(graphics, pen, points, 2, 1);
574     expect(Ok, status);
575
576     status = GdipDrawCurve2(graphics, pen, points, 3, 2);
577     expect(Ok, status);
578
579     status = GdipDrawCurve2(graphics, pen, points, 3, -2);
580     expect(Ok, status);
581
582     status = GdipDrawCurve2(graphics, pen, points, 3, 0);
583     expect(Ok, status);
584
585     GdipDeletePen(pen);
586     GdipDeleteGraphics(graphics);
587
588     ReleaseDC(0, hdc);
589 }
590
591 static void test_GdipDrawCurve2I(void)
592 {
593     GpStatus status;
594     GpGraphics *graphics = NULL;
595     GpPen *pen = NULL;
596     HDC hdc = GetDC(0);
597     GpPoint points[3];
598
599     points[0].X = 0;
600     points[0].Y = 0;
601
602     points[1].X = 40;
603     points[1].Y = 20;
604
605     points[2].X = 10;
606     points[2].Y = 40;
607
608     /* make a graphics object and pen object */
609     ok(hdc != NULL, "Expected HDC to be initialized\n");
610
611     status = GdipCreateFromHDC(hdc, &graphics);
612     expect(Ok, status);
613     ok(graphics != NULL, "Expected graphics to be initialized\n");
614
615     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
616     expect(Ok, status);
617     ok(pen != NULL, "Expected pen to be initialized\n");
618
619     /* InvalidParameter cases: null graphics, null pen */
620     status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
621     expect(InvalidParameter, status);
622
623     status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
624     expect(InvalidParameter, status);
625
626     status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
627     expect(InvalidParameter, status);
628
629     /* InvalidParameter cases: invalid count */
630     status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
631     expect(OutOfMemory, status);
632
633     status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
634     expect(InvalidParameter, status);
635
636     status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
637     expect(InvalidParameter, status);
638
639     /* Valid test cases */
640     status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
641     expect(Ok, status);
642
643     status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
644     expect(Ok, status);
645
646     status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
647     expect(Ok, status);
648
649     status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
650     expect(Ok, status);
651
652     GdipDeletePen(pen);
653     GdipDeleteGraphics(graphics);
654
655     ReleaseDC(0, hdc);
656 }
657
658 static void test_GdipDrawCurve(void)
659 {
660     GpStatus status;
661     GpGraphics *graphics = NULL;
662     GpPen *pen = NULL;
663     HDC hdc = GetDC(0);
664     GpPointF points[3];
665
666     points[0].X = 0;
667     points[0].Y = 0;
668
669     points[1].X = 40;
670     points[1].Y = 20;
671
672     points[2].X = 10;
673     points[2].Y = 40;
674
675     /* make a graphics object and pen object */
676     ok(hdc != NULL, "Expected HDC to be initialized\n");
677
678     status = GdipCreateFromHDC(hdc, &graphics);
679     expect(Ok, status);
680     ok(graphics != NULL, "Expected graphics to be initialized\n");
681
682     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
683     expect(Ok, status);
684     ok(pen != NULL, "Expected pen to be initialized\n");
685
686     /* InvalidParameter cases: null graphics, null pen */
687     status = GdipDrawCurve(NULL, NULL, points, 3);
688     expect(InvalidParameter, status);
689
690     status = GdipDrawCurve(graphics, NULL, points, 3);
691     expect(InvalidParameter, status);
692
693     status = GdipDrawCurve(NULL, pen, points, 3);
694     expect(InvalidParameter, status);
695
696     /* InvalidParameter cases: invalid count */
697     status = GdipDrawCurve(graphics, pen, points, -1);
698     expect(InvalidParameter, status);
699
700     status = GdipDrawCurve(graphics, pen, points, 0);
701     expect(InvalidParameter, status);
702
703     status = GdipDrawCurve(graphics, pen, points, 1);
704     expect(InvalidParameter, status);
705
706     /* Valid test cases */
707     status = GdipDrawCurve(graphics, pen, points, 2);
708     expect(Ok, status);
709
710     status = GdipDrawCurve(graphics, pen, points, 3);
711     expect(Ok, status);
712
713     GdipDeletePen(pen);
714     GdipDeleteGraphics(graphics);
715
716     ReleaseDC(0, hdc);
717 }
718
719 static void test_GdipDrawCurveI(void)
720 {
721     GpStatus status;
722     GpGraphics *graphics = NULL;
723     GpPen *pen = NULL;
724     HDC hdc = GetDC(0);
725     GpPoint points[3];
726
727     points[0].X = 0;
728     points[0].Y = 0;
729
730     points[1].X = 40;
731     points[1].Y = 20;
732
733     points[2].X = 10;
734     points[2].Y = 40;
735
736     /* make a graphics object and pen object */
737     ok(hdc != NULL, "Expected HDC to be initialized\n");
738
739     status = GdipCreateFromHDC(hdc, &graphics);
740     expect(Ok, status);
741     ok(graphics != NULL, "Expected graphics to be initialized\n");
742
743     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
744     expect(Ok, status);
745     ok(pen != NULL, "Expected pen to be initialized\n");
746
747     /* InvalidParameter cases: null graphics, null pen */
748     status = GdipDrawCurveI(NULL, NULL, points, 3);
749     expect(InvalidParameter, status);
750
751     status = GdipDrawCurveI(graphics, NULL, points, 3);
752     expect(InvalidParameter, status);
753
754     status = GdipDrawCurveI(NULL, pen, points, 3);
755     expect(InvalidParameter, status);
756
757     /* InvalidParameter cases: invalid count */
758     status = GdipDrawCurveI(graphics, pen, points, -1);
759     expect(OutOfMemory, status);
760
761     status = GdipDrawCurveI(graphics, pen, points, 0);
762     expect(InvalidParameter, status);
763
764     status = GdipDrawCurveI(graphics, pen, points, 1);
765     expect(InvalidParameter, status);
766
767     /* Valid test cases */
768     status = GdipDrawCurveI(graphics, pen, points, 2);
769     expect(Ok, status);
770
771     status = GdipDrawCurveI(graphics, pen, points, 3);
772     expect(Ok, status);
773
774     GdipDeletePen(pen);
775     GdipDeleteGraphics(graphics);
776
777     ReleaseDC(0, hdc);
778 }
779
780 static void test_GdipDrawLineI(void)
781 {
782     GpStatus status;
783     GpGraphics *graphics = NULL;
784     GpPen *pen = NULL;
785     HDC hdc = GetDC(0);
786
787     /* make a graphics object and pen object */
788     ok(hdc != NULL, "Expected HDC to be initialized\n");
789
790     status = GdipCreateFromHDC(hdc, &graphics);
791     expect(Ok, status);
792     ok(graphics != NULL, "Expected graphics to be initialized\n");
793
794     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
795     expect(Ok, status);
796     ok(pen != NULL, "Expected pen to be initialized\n");
797
798     /* InvalidParameter cases: null graphics, null pen */
799     status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
800     expect(InvalidParameter, status);
801
802     status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
803     expect(InvalidParameter, status);
804
805     status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
806     expect(InvalidParameter, status);
807
808     /* successful case */
809     status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
810     expect(Ok, status);
811
812     GdipDeletePen(pen);
813     GdipDeleteGraphics(graphics);
814
815     ReleaseDC(0, hdc);
816 }
817
818 static void test_GdipDrawLinesI(void)
819 {
820     GpStatus status;
821     GpGraphics *graphics = NULL;
822     GpPen *pen = NULL;
823     GpPoint *ptf = NULL;
824     HDC hdc = GetDC(0);
825
826     /* make a graphics object and pen object */
827     ok(hdc != NULL, "Expected HDC to be initialized\n");
828
829     status = GdipCreateFromHDC(hdc, &graphics);
830     expect(Ok, status);
831     ok(graphics != NULL, "Expected graphics to be initialized\n");
832
833     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
834     expect(Ok, status);
835     ok(pen != NULL, "Expected pen to be initialized\n");
836
837     /* make some arbitrary valid points*/
838     ptf = GdipAlloc(2 * sizeof(GpPointF));
839
840     ptf[0].X = 1;
841     ptf[0].Y = 1;
842
843     ptf[1].X = 2;
844     ptf[1].Y = 2;
845
846     /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
847     status = GdipDrawLinesI(NULL, NULL, NULL, 0);
848     expect(InvalidParameter, status);
849
850     status = GdipDrawLinesI(graphics, pen, ptf, 0);
851     expect(InvalidParameter, status);
852
853     status = GdipDrawLinesI(graphics, NULL, ptf, 2);
854     expect(InvalidParameter, status);
855
856     status = GdipDrawLinesI(NULL, pen, ptf, 2);
857     expect(InvalidParameter, status);
858
859     /* successful case */
860     status = GdipDrawLinesI(graphics, pen, ptf, 2);
861     expect(Ok, status);
862
863     GdipFree(ptf);
864     GdipDeletePen(pen);
865     GdipDeleteGraphics(graphics);
866
867     ReleaseDC(0, hdc);
868 }
869
870 static void test_Get_Release_DC(void)
871 {
872     GpStatus status;
873     GpGraphics *graphics = NULL;
874     GpPen *pen;
875     GpSolidFill *brush;
876     GpPath *path;
877     HDC hdc = GetDC(0);
878     HDC retdc;
879     REAL r;
880     CompositingQuality quality;
881     CompositingMode compmode;
882     InterpolationMode intmode;
883     GpMatrix *m;
884     GpRegion *region;
885     GpUnit unit;
886     PixelOffsetMode offsetmode;
887     SmoothingMode smoothmode;
888     TextRenderingHint texthint;
889     GpPointF ptf[5];
890     GpPoint  pt[5];
891     GpRectF  rectf[2];
892     GpRect   rect[2];
893     GpRegion *clip;
894     INT i;
895     BOOL res;
896     ARGB color = 0x00000000;
897     HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
898
899     pt[0].X = 10;
900     pt[0].Y = 10;
901     pt[1].X = 20;
902     pt[1].Y = 15;
903     pt[2].X = 40;
904     pt[2].Y = 80;
905     pt[3].X = -20;
906     pt[3].Y = 20;
907     pt[4].X = 50;
908     pt[4].Y = 110;
909
910     for(i = 0; i < 5;i++){
911         ptf[i].X = (REAL)pt[i].X;
912         ptf[i].Y = (REAL)pt[i].Y;
913     }
914
915     rect[0].X = 0;
916     rect[0].Y = 0;
917     rect[0].Width  = 50;
918     rect[0].Height = 70;
919     rect[1].X = 0;
920     rect[1].Y = 0;
921     rect[1].Width  = 10;
922     rect[1].Height = 20;
923
924     for(i = 0; i < 2;i++){
925         rectf[i].X = (REAL)rect[i].X;
926         rectf[i].Y = (REAL)rect[i].Y;
927         rectf[i].Height = (REAL)rect[i].Height;
928         rectf[i].Width  = (REAL)rect[i].Width;
929     }
930
931     GdipCreateMatrix(&m);
932     GdipCreateRegion(&region);
933     GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
934     GdipCreatePath(FillModeAlternate, &path);
935     GdipCreateRegion(&clip);
936
937     status = GdipCreateFromHDC(hdc, &graphics);
938     expect(Ok, status);
939     ok(graphics != NULL, "Expected graphics to be initialized\n");
940     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
941     expect(Ok, status);
942
943     /* NULL arguments */
944     status = GdipGetDC(NULL, NULL);
945     expect(InvalidParameter, status);
946     status = GdipGetDC(graphics, NULL);
947     expect(InvalidParameter, status);
948     status = GdipGetDC(NULL, &retdc);
949     expect(InvalidParameter, status);
950
951     status = GdipReleaseDC(NULL, NULL);
952     expect(InvalidParameter, status);
953     status = GdipReleaseDC(graphics, NULL);
954     expect(InvalidParameter, status);
955     status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
956     expect(InvalidParameter, status);
957
958     /* Release without Get */
959     status = GdipReleaseDC(graphics, hdc);
960     expect(InvalidParameter, status);
961
962     retdc = NULL;
963     status = GdipGetDC(graphics, &retdc);
964     expect(Ok, status);
965     ok(retdc == hdc, "Invalid HDC returned\n");
966     /* call it once more */
967     status = GdipGetDC(graphics, &retdc);
968     expect(ObjectBusy, status);
969
970     /* try all Graphics calls here */
971     status = Ok;
972     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
973     expect(ObjectBusy, status); status = Ok;
974     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
975     expect(ObjectBusy, status); status = Ok;
976     status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
977     expect(ObjectBusy, status); status = Ok;
978     status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
979     expect(ObjectBusy, status); status = Ok;
980     status = GdipDrawBeziers(graphics, pen, ptf, 5);
981     expect(ObjectBusy, status); status = Ok;
982     status = GdipDrawBeziersI(graphics, pen, pt, 5);
983     expect(ObjectBusy, status); status = Ok;
984     status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
985     expect(ObjectBusy, status); status = Ok;
986     status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
987     expect(ObjectBusy, status); status = Ok;
988     status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
989     expect(ObjectBusy, status); status = Ok;
990     status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
991     expect(ObjectBusy, status); status = Ok;
992     status = GdipDrawCurve(graphics, pen, ptf, 5);
993     expect(ObjectBusy, status); status = Ok;
994     status = GdipDrawCurveI(graphics, pen, pt, 5);
995     expect(ObjectBusy, status); status = Ok;
996     status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
997     expect(ObjectBusy, status); status = Ok;
998     status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
999     expect(ObjectBusy, status); status = Ok;
1000     status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1001     expect(ObjectBusy, status); status = Ok;
1002     status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1003     expect(ObjectBusy, status); status = Ok;
1004     /* GdipDrawImage/GdipDrawImageI */
1005     /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1006     /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1007     /* GdipDrawImageRect/GdipDrawImageRectI */
1008     status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1009     expect(ObjectBusy, status); status = Ok;
1010     status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1011     expect(ObjectBusy, status); status = Ok;
1012     status = GdipDrawLines(graphics, pen, ptf, 5);
1013     expect(ObjectBusy, status); status = Ok;
1014     status = GdipDrawLinesI(graphics, pen, pt, 5);
1015     expect(ObjectBusy, status); status = Ok;
1016     status = GdipDrawPath(graphics, pen, path);
1017     expect(ObjectBusy, status); status = Ok;
1018     status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1019     expect(ObjectBusy, status); status = Ok;
1020     status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1021     expect(ObjectBusy, status); status = Ok;
1022     status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1023     expect(ObjectBusy, status); status = Ok;
1024     status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1025     expect(ObjectBusy, status); status = Ok;
1026     status = GdipDrawRectangles(graphics, pen, rectf, 2);
1027     expect(ObjectBusy, status); status = Ok;
1028     status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1029     expect(ObjectBusy, status); status = Ok;
1030     /* GdipDrawString */
1031     status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1032     expect(ObjectBusy, status); status = Ok;
1033     status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1034     expect(ObjectBusy, status); status = Ok;
1035     status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1036     expect(ObjectBusy, status); status = Ok;
1037     status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1038     expect(ObjectBusy, status); status = Ok;
1039     status = GdipFillPath(graphics, (GpBrush*)brush, path);
1040     expect(ObjectBusy, status); status = Ok;
1041     status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1042     expect(ObjectBusy, status); status = Ok;
1043     status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1044     expect(ObjectBusy, status); status = Ok;
1045     status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1046     expect(ObjectBusy, status); status = Ok;
1047     status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1048     expect(ObjectBusy, status); status = Ok;
1049     status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1050     expect(ObjectBusy, status); status = Ok;
1051     status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1052     expect(ObjectBusy, status); status = Ok;
1053     status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1054     expect(ObjectBusy, status); status = Ok;
1055     status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1056     expect(ObjectBusy, status); status = Ok;
1057     status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1058     expect(ObjectBusy, status); status = Ok;
1059     status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1060     expect(ObjectBusy, status); status = Ok;
1061     status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1062     expect(ObjectBusy, status); status = Ok;
1063     status = GdipFlush(graphics, FlushIntentionFlush);
1064     expect(ObjectBusy, status); status = Ok;
1065     status = GdipGetClipBounds(graphics, rectf);
1066     expect(ObjectBusy, status); status = Ok;
1067     status = GdipGetClipBoundsI(graphics, rect);
1068     expect(ObjectBusy, status); status = Ok;
1069     status = GdipGetCompositingMode(graphics, &compmode);
1070     expect(ObjectBusy, status); status = Ok;
1071     status = GdipGetCompositingQuality(graphics, &quality);
1072     expect(ObjectBusy, status); status = Ok;
1073     status = GdipGetInterpolationMode(graphics, &intmode);
1074     expect(ObjectBusy, status); status = Ok;
1075     status = GdipGetNearestColor(graphics, &color);
1076     expect(ObjectBusy, status); status = Ok;
1077     status = GdipGetPageScale(graphics, &r);
1078     expect(ObjectBusy, status); status = Ok;
1079     status = GdipGetPageUnit(graphics, &unit);
1080     expect(ObjectBusy, status); status = Ok;
1081     status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1082     expect(ObjectBusy, status); status = Ok;
1083     status = GdipGetSmoothingMode(graphics, &smoothmode);
1084     expect(ObjectBusy, status); status = Ok;
1085     status = GdipGetTextRenderingHint(graphics, &texthint);
1086     expect(ObjectBusy, status); status = Ok;
1087     status = GdipGetWorldTransform(graphics, m);
1088     expect(ObjectBusy, status); status = Ok;
1089     status = GdipGraphicsClear(graphics, 0xdeadbeef);
1090     expect(ObjectBusy, status); status = Ok;
1091     status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1092     expect(ObjectBusy, status); status = Ok;
1093     status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1094     expect(ObjectBusy, status); status = Ok;
1095     /* GdipMeasureCharacterRanges */
1096     /* GdipMeasureString */
1097     status = GdipResetClip(graphics);
1098     expect(ObjectBusy, status); status = Ok;
1099     status = GdipResetWorldTransform(graphics);
1100     expect(ObjectBusy, status); status = Ok;
1101     /* GdipRestoreGraphics */
1102     status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1103     expect(ObjectBusy, status); status = Ok;
1104     /*  GdipSaveGraphics */
1105     status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1106     expect(ObjectBusy, status); status = Ok;
1107     status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1108     expect(ObjectBusy, status); status = Ok;
1109     status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1110     expect(ObjectBusy, status); status = Ok;
1111     status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1112     expect(ObjectBusy, status); status = Ok;
1113     status = GdipSetPageScale(graphics, 1.0);
1114     expect(ObjectBusy, status); status = Ok;
1115     status = GdipSetPageUnit(graphics, UnitWorld);
1116     expect(ObjectBusy, status); status = Ok;
1117     status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1118     expect(ObjectBusy, status); status = Ok;
1119     status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1120     expect(ObjectBusy, status); status = Ok;
1121     status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1122     expect(ObjectBusy, status); status = Ok;
1123     status = GdipSetWorldTransform(graphics, m);
1124     expect(ObjectBusy, status); status = Ok;
1125     status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1126     expect(ObjectBusy, status); status = Ok;
1127     status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1128     expect(ObjectBusy, status); status = Ok;
1129     status = GdipSetClipPath(graphics, path, CombineModeReplace);
1130     expect(ObjectBusy, status); status = Ok;
1131     status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1132     expect(ObjectBusy, status); status = Ok;
1133     status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1134     expect(ObjectBusy, status); status = Ok;
1135     status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1136     expect(ObjectBusy, status); status = Ok;
1137     status = GdipTranslateClip(graphics, 0.0, 0.0);
1138     expect(ObjectBusy, status); status = Ok;
1139     status = GdipTranslateClipI(graphics, 0, 0);
1140     expect(ObjectBusy, status); status = Ok;
1141     status = GdipDrawPolygon(graphics, pen, ptf, 5);
1142     expect(ObjectBusy, status); status = Ok;
1143     status = GdipDrawPolygonI(graphics, pen, pt, 5);
1144     expect(ObjectBusy, status); status = Ok;
1145     status = GdipGetDpiX(graphics, &r);
1146     expect(ObjectBusy, status); status = Ok;
1147     status = GdipGetDpiY(graphics, &r);
1148     expect(ObjectBusy, status); status = Ok;
1149     status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1150     status = GdipGetClip(graphics, region);
1151     expect(ObjectBusy, status); status = Ok;
1152     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1153     expect(ObjectBusy, status); status = Ok;
1154     /* try to delete before release */
1155     status = GdipDeleteGraphics(graphics);
1156     expect(ObjectBusy, status);
1157
1158     status = GdipReleaseDC(graphics, retdc);
1159     expect(Ok, status);
1160
1161     GdipDeletePen(pen);
1162     GdipDeleteGraphics(graphics);
1163
1164     GdipDeletePath(path);
1165     GdipDeleteBrush((GpBrush*)brush);
1166     GdipDeleteRegion(region);
1167     GdipDeleteMatrix(m);
1168     DeleteObject(hrgn);
1169
1170     ReleaseDC(0, hdc);
1171 }
1172
1173 static void test_transformpoints(void)
1174 {
1175     GpStatus status;
1176     GpGraphics *graphics = NULL;
1177     HDC hdc = GetDC(0);
1178     GpPointF ptf[2];
1179     GpPoint pt[2];
1180
1181     status = GdipCreateFromHDC(hdc, &graphics);
1182     expect(Ok, status);
1183
1184     /* NULL arguments */
1185     status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1186     expect(InvalidParameter, status);
1187     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1188     expect(InvalidParameter, status);
1189     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1190     expect(InvalidParameter, status);
1191     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1192     expect(InvalidParameter, status);
1193
1194     ptf[0].X = 1.0;
1195     ptf[0].Y = 0.0;
1196     ptf[1].X = 0.0;
1197     ptf[1].Y = 1.0;
1198     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1199     expect(Ok, status);
1200     expectf(1.0, ptf[0].X);
1201     expectf(0.0, ptf[0].Y);
1202     expectf(0.0, ptf[1].X);
1203     expectf(1.0, ptf[1].Y);
1204
1205     status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1206     expect(Ok, status);
1207     status = GdipSetPageUnit(graphics, UnitPixel);
1208     expect(Ok, status);
1209     status = GdipSetPageScale(graphics, 3.0);
1210     expect(Ok, status);
1211
1212     ptf[0].X = 1.0;
1213     ptf[0].Y = 0.0;
1214     ptf[1].X = 0.0;
1215     ptf[1].Y = 1.0;
1216     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1217     expect(Ok, status);
1218     expectf(18.0, ptf[0].X);
1219     expectf(15.0, ptf[0].Y);
1220     expectf(15.0, ptf[1].X);
1221     expectf(18.0, ptf[1].Y);
1222
1223     ptf[0].X = 1.0;
1224     ptf[0].Y = 0.0;
1225     ptf[1].X = 0.0;
1226     ptf[1].Y = 1.0;
1227     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1228     expect(Ok, status);
1229     expectf(6.0, ptf[0].X);
1230     expectf(5.0, ptf[0].Y);
1231     expectf(5.0, ptf[1].X);
1232     expectf(6.0, ptf[1].Y);
1233
1234     ptf[0].X = 1.0;
1235     ptf[0].Y = 0.0;
1236     ptf[1].X = 0.0;
1237     ptf[1].Y = 1.0;
1238     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1239     expect(Ok, status);
1240     expectf(3.0, ptf[0].X);
1241     expectf(0.0, ptf[0].Y);
1242     expectf(0.0, ptf[1].X);
1243     expectf(3.0, ptf[1].Y);
1244
1245     ptf[0].X = 18.0;
1246     ptf[0].Y = 15.0;
1247     ptf[1].X = 15.0;
1248     ptf[1].Y = 18.0;
1249     status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1250     expect(Ok, status);
1251     expectf(1.0, ptf[0].X);
1252     expectf(0.0, ptf[0].Y);
1253     expectf(0.0, ptf[1].X);
1254     expectf(1.0, ptf[1].Y);
1255
1256     ptf[0].X = 6.0;
1257     ptf[0].Y = 5.0;
1258     ptf[1].X = 5.0;
1259     ptf[1].Y = 6.0;
1260     status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1261     expect(Ok, status);
1262     expectf(1.0, ptf[0].X);
1263     expectf(0.0, ptf[0].Y);
1264     expectf(0.0, ptf[1].X);
1265     expectf(1.0, ptf[1].Y);
1266
1267     ptf[0].X = 3.0;
1268     ptf[0].Y = 0.0;
1269     ptf[1].X = 0.0;
1270     ptf[1].Y = 3.0;
1271     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1272     expect(Ok, status);
1273     expectf(1.0, ptf[0].X);
1274     expectf(0.0, ptf[0].Y);
1275     expectf(0.0, ptf[1].X);
1276     expectf(1.0, ptf[1].Y);
1277
1278     pt[0].X = 1;
1279     pt[0].Y = 0;
1280     pt[1].X = 0;
1281     pt[1].Y = 1;
1282     status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1283     expect(Ok, status);
1284     expect(18, pt[0].X);
1285     expect(15, pt[0].Y);
1286     expect(15, pt[1].X);
1287     expect(18, pt[1].Y);
1288
1289     GdipDeleteGraphics(graphics);
1290     ReleaseDC(0, hdc);
1291 }
1292
1293 static void test_get_set_clip(void)
1294 {
1295     GpStatus status;
1296     GpGraphics *graphics = NULL;
1297     HDC hdc = GetDC(0);
1298     GpRegion *clip;
1299     GpRectF rect;
1300     BOOL res;
1301
1302     status = GdipCreateFromHDC(hdc, &graphics);
1303     expect(Ok, status);
1304
1305     rect.X = rect.Y = 0.0;
1306     rect.Height = rect.Width = 100.0;
1307
1308     status = GdipCreateRegionRect(&rect, &clip);
1309
1310     /* NULL arguments */
1311     status = GdipGetClip(NULL, NULL);
1312     expect(InvalidParameter, status);
1313     status = GdipGetClip(graphics, NULL);
1314     expect(InvalidParameter, status);
1315     status = GdipGetClip(NULL, clip);
1316     expect(InvalidParameter, status);
1317
1318     status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1319     expect(InvalidParameter, status);
1320     status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1321     expect(InvalidParameter, status);
1322
1323     status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
1324     expect(InvalidParameter, status);
1325     status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
1326     expect(InvalidParameter, status);
1327
1328     res = FALSE;
1329     status = GdipGetClip(graphics, clip);
1330     expect(Ok, status);
1331     status = GdipIsInfiniteRegion(clip, graphics, &res);
1332     expect(Ok, status);
1333     expect(TRUE, res);
1334
1335     /* remains infinite after reset */
1336     res = FALSE;
1337     status = GdipResetClip(graphics);
1338     expect(Ok, status);
1339     status = GdipGetClip(graphics, clip);
1340     expect(Ok, status);
1341     status = GdipIsInfiniteRegion(clip, graphics, &res);
1342     expect(Ok, status);
1343     expect(TRUE, res);
1344
1345     /* set to empty and then reset to infinite */
1346     status = GdipSetEmpty(clip);
1347     expect(Ok, status);
1348     status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1349     expect(Ok, status);
1350
1351     status = GdipGetClip(graphics, clip);
1352     expect(Ok, status);
1353     res = FALSE;
1354     status = GdipIsEmptyRegion(clip, graphics, &res);
1355     expect(Ok, status);
1356     expect(TRUE, res);
1357     status = GdipResetClip(graphics);
1358     expect(Ok, status);
1359     status = GdipGetClip(graphics, clip);
1360     expect(Ok, status);
1361     res = FALSE;
1362     status = GdipIsInfiniteRegion(clip, graphics, &res);
1363     expect(Ok, status);
1364     expect(TRUE, res);
1365
1366     GdipDeleteRegion(clip);
1367
1368     GdipDeleteGraphics(graphics);
1369     ReleaseDC(0, hdc);
1370 }
1371
1372 static void test_isempty(void)
1373 {
1374     GpStatus status;
1375     GpGraphics *graphics = NULL;
1376     HDC hdc = GetDC(0);
1377     GpRegion *clip;
1378     BOOL res;
1379
1380     status = GdipCreateFromHDC(hdc, &graphics);
1381     expect(Ok, status);
1382
1383     status = GdipCreateRegion(&clip);
1384     expect(Ok, status);
1385
1386     /* NULL */
1387     status = GdipIsClipEmpty(NULL, NULL);
1388     expect(InvalidParameter, status);
1389     status = GdipIsClipEmpty(graphics, NULL);
1390     expect(InvalidParameter, status);
1391     status = GdipIsClipEmpty(NULL, &res);
1392     expect(InvalidParameter, status);
1393
1394     /* default is infinite */
1395     res = TRUE;
1396     status = GdipIsClipEmpty(graphics, &res);
1397     expect(Ok, status);
1398     expect(FALSE, res);
1399
1400     GdipDeleteRegion(clip);
1401
1402     GdipDeleteGraphics(graphics);
1403     ReleaseDC(0, hdc);
1404 }
1405
1406 static void test_clear(void)
1407 {
1408     GpStatus status;
1409
1410     status = GdipGraphicsClear(NULL, 0xdeadbeef);
1411     expect(InvalidParameter, status);
1412 }
1413
1414 static void test_textcontrast(void)
1415 {
1416     GpStatus status;
1417     HDC hdc = GetDC(0);
1418     GpGraphics *graphics;
1419     UINT contrast;
1420
1421     status = GdipGetTextContrast(NULL, NULL);
1422     expect(InvalidParameter, status);
1423
1424     status = GdipCreateFromHDC(hdc, &graphics);
1425     expect(Ok, status);
1426
1427     status = GdipGetTextContrast(graphics, NULL);
1428     expect(InvalidParameter, status);
1429     status = GdipGetTextContrast(graphics, &contrast);
1430     expect(4, contrast);
1431
1432     GdipDeleteGraphics(graphics);
1433     ReleaseDC(0, hdc);
1434 }
1435
1436 static void test_GdipDrawString(void)
1437 {
1438     GpStatus status;
1439     GpGraphics *graphics = NULL;
1440     GpFont *fnt = NULL;
1441     RectF  rect;
1442     GpStringFormat *format;
1443     GpBrush *brush;
1444     LOGFONTA logfont;
1445     HDC hdc = GetDC(0);
1446     static const WCHAR string[] = {'T','e','s','t',0};
1447
1448     memset(&logfont,0,sizeof(logfont));
1449     strcpy(logfont.lfFaceName,"Arial");
1450     logfont.lfHeight = 12;
1451     logfont.lfCharSet = DEFAULT_CHARSET;
1452
1453     status = GdipCreateFromHDC(hdc, &graphics);
1454     expect(Ok, status);
1455
1456     status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
1457     if (status == FileNotFound)
1458     {
1459         skip("Arial not installed.\n");
1460         return;
1461     }
1462     expect(Ok, status);
1463
1464     status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
1465     expect(Ok, status);
1466
1467     status = GdipCreateStringFormat(0,0,&format);
1468     expect(Ok, status);
1469
1470     rect.X = 0;
1471     rect.Y = 0;
1472     rect.Width = 0;
1473     rect.Height = 12;
1474
1475     status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
1476     expect(Ok, status);
1477
1478     GdipDeleteGraphics(graphics);
1479     GdipDeleteBrush(brush);
1480     GdipDeleteFont(fnt);
1481     GdipDeleteStringFormat(format);
1482
1483     ReleaseDC(0, hdc);
1484 }
1485
1486
1487 START_TEST(graphics)
1488 {
1489     struct GdiplusStartupInput gdiplusStartupInput;
1490     ULONG_PTR gdiplusToken;
1491
1492     gdiplusStartupInput.GdiplusVersion              = 1;
1493     gdiplusStartupInput.DebugEventCallback          = NULL;
1494     gdiplusStartupInput.SuppressBackgroundThread    = 0;
1495     gdiplusStartupInput.SuppressExternalCodecs      = 0;
1496
1497     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1498
1499     test_constructor_destructor();
1500     test_save_restore();
1501     test_GdipDrawBezierI();
1502     test_GdipDrawArc();
1503     test_GdipDrawArcI();
1504     test_GdipDrawCurve();
1505     test_GdipDrawCurveI();
1506     test_GdipDrawCurve2();
1507     test_GdipDrawCurve2I();
1508     test_GdipDrawCurve3();
1509     test_GdipDrawCurve3I();
1510     test_GdipDrawLineI();
1511     test_GdipDrawLinesI();
1512     test_GdipDrawString();
1513     test_Get_Release_DC();
1514     test_transformpoints();
1515     test_get_set_clip();
1516     test_isempty();
1517     test_clear();
1518     test_textcontrast();
1519
1520     GdiplusShutdown(gdiplusToken);
1521 }