shdocvw: Support URLs passed by reference in WebBrowser_Navigate2.
[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     expect(InterpolationModeBilinear, mode);
141     GdipDeleteGraphics(graphics1);
142
143     log_state(state_a, &state_log);
144
145     /* Restoring garbage doesn't affect saves. */
146     GdipCreateFromHDC(hdc, &graphics1);
147     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
148     GdipSaveGraphics(graphics1, &state_a);
149     GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
150     GdipSaveGraphics(graphics1, &state_b);
151     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
152     stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
153     expect(Ok, stat);
154     GdipRestoreGraphics(graphics1, state_b);
155     GdipGetInterpolationMode(graphics1, &mode);
156     expect(InterpolationModeBicubic, mode);
157     GdipRestoreGraphics(graphics1, state_a);
158     GdipGetInterpolationMode(graphics1, &mode);
159     expect(InterpolationModeBilinear, mode);
160     GdipDeleteGraphics(graphics1);
161
162     log_state(state_a, &state_log);
163     log_state(state_b, &state_log);
164
165     /* Restoring older state invalidates newer saves (but not older saves). */
166     GdipCreateFromHDC(hdc, &graphics1);
167     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
168     GdipSaveGraphics(graphics1, &state_a);
169     GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
170     GdipSaveGraphics(graphics1, &state_b);
171     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
172     GdipSaveGraphics(graphics1, &state_c);
173     GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
174     GdipRestoreGraphics(graphics1, state_b);
175     GdipGetInterpolationMode(graphics1, &mode);
176     expect(InterpolationModeBicubic, mode);
177     GdipRestoreGraphics(graphics1, state_c);
178     GdipGetInterpolationMode(graphics1, &mode);
179     expect(InterpolationModeBicubic, mode);
180     GdipRestoreGraphics(graphics1, state_a);
181     GdipGetInterpolationMode(graphics1, &mode);
182     expect(InterpolationModeBilinear, mode);
183     GdipDeleteGraphics(graphics1);
184
185     log_state(state_a, &state_log);
186     log_state(state_b, &state_log);
187     log_state(state_c, &state_log);
188
189     /* Restoring older save from one graphics object does not invalidate
190      * newer save from other graphics object. */
191     GdipCreateFromHDC(hdc, &graphics1);
192     GdipCreateFromHDC(hdc, &graphics2);
193     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
194     GdipSaveGraphics(graphics1, &state_a);
195     GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
196     GdipSaveGraphics(graphics2, &state_b);
197     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
198     GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
199     GdipRestoreGraphics(graphics1, state_a);
200     GdipGetInterpolationMode(graphics1, &mode);
201     expect(InterpolationModeBilinear, mode);
202     GdipRestoreGraphics(graphics2, state_b);
203     GdipGetInterpolationMode(graphics2, &mode);
204     expect(InterpolationModeBicubic, mode);
205     GdipDeleteGraphics(graphics1);
206     GdipDeleteGraphics(graphics2);
207
208     /* You can't restore a state to a graphics object that didn't save it. */
209     GdipCreateFromHDC(hdc, &graphics1);
210     GdipCreateFromHDC(hdc, &graphics2);
211     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
212     GdipSaveGraphics(graphics1, &state_a);
213     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
214     GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
215     GdipRestoreGraphics(graphics2, state_a);
216     GdipGetInterpolationMode(graphics2, &mode);
217     expect(InterpolationModeNearestNeighbor, mode);
218     GdipDeleteGraphics(graphics1);
219     GdipDeleteGraphics(graphics2);
220
221     log_state(state_a, &state_log);
222
223     /* The same state value should never be returned twice. */
224     todo_wine
225         check_no_duplicates(state_log);
226
227     ReleaseDC(0, hdc);
228 }
229
230 static void test_GdipDrawArc(void)
231 {
232     GpStatus status;
233     GpGraphics *graphics = NULL;
234     GpPen *pen = NULL;
235     HDC hdc = GetDC(0);
236
237     /* make a graphics object and pen object */
238     ok(hdc != NULL, "Expected HDC to be initialized\n");
239
240     status = GdipCreateFromHDC(hdc, &graphics);
241     expect(Ok, status);
242     ok(graphics != NULL, "Expected graphics to be initialized\n");
243
244     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
245     expect(Ok, status);
246     ok(pen != NULL, "Expected pen to be initialized\n");
247
248     /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
249     status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
250     expect(InvalidParameter, status);
251
252     status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
253     expect(InvalidParameter, status);
254
255     status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
256     expect(InvalidParameter, status);
257
258     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
259     expect(InvalidParameter, status);
260
261     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
262     expect(InvalidParameter, status);
263
264     /* successful case */
265     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
266     expect(Ok, status);
267
268     GdipDeletePen(pen);
269     GdipDeleteGraphics(graphics);
270
271     ReleaseDC(0, hdc);
272 }
273
274 static void test_GdipDrawArcI(void)
275 {
276     GpStatus status;
277     GpGraphics *graphics = NULL;
278     GpPen *pen = NULL;
279     HDC hdc = GetDC(0);
280
281     /* make a graphics object and pen object */
282     ok(hdc != NULL, "Expected HDC to be initialized\n");
283
284     status = GdipCreateFromHDC(hdc, &graphics);
285     expect(Ok, status);
286     ok(graphics != NULL, "Expected graphics to be initialized\n");
287
288     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
289     expect(Ok, status);
290     ok(pen != NULL, "Expected pen to be initialized\n");
291
292     /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
293     status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
294     expect(InvalidParameter, status);
295
296     status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
297     expect(InvalidParameter, status);
298
299     status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
300     expect(InvalidParameter, status);
301
302     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
303     expect(InvalidParameter, status);
304
305     status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
306     expect(InvalidParameter, status);
307
308     /* successful case */
309     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
310     expect(Ok, status);
311
312     GdipDeletePen(pen);
313     GdipDeleteGraphics(graphics);
314
315     ReleaseDC(0, hdc);
316 }
317
318 static void test_BeginContainer2(void)
319 {
320     GpMatrix *transform;
321     GpRectF clip;
322     REAL defClip[] = {5, 10, 15, 20};
323     REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
324     GraphicsContainer cont1, cont2, cont3, cont4;
325     CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
326     CompositingMode compmode, defCompmode = CompositingModeSourceOver;
327     InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
328     REAL scale, defScale = 17;
329     GpUnit unit, defUnit = UnitPixel;
330     PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
331     SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
332     UINT contrast, defContrast = 5;
333     TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
334
335     GpStatus status;
336     GpGraphics *graphics = NULL;
337     HDC hdc = GetDC(0);
338
339     ok(hdc != NULL, "Expected HDC to be initialized\n");
340
341     status = GdipCreateFromHDC(hdc, &graphics);
342     expect(Ok, status);
343     ok(graphics != NULL, "Expected graphics to be initialized\n");
344
345     /* null graphics, null container */
346     status = GdipBeginContainer2(NULL, &cont1);
347     expect(InvalidParameter, status);
348
349     status = GdipBeginContainer2(graphics, NULL);
350     expect(InvalidParameter, status);
351
352     status = GdipEndContainer(NULL, cont1);
353     expect(InvalidParameter, status);
354
355     /* test all quality-related values */
356     GdipSetCompositingMode(graphics, defCompmode);
357     GdipSetCompositingQuality(graphics, defCompqual);
358     GdipSetInterpolationMode(graphics, defInterp);
359     GdipSetPageScale(graphics, defScale);
360     GdipSetPageUnit(graphics, defUnit);
361     GdipSetPixelOffsetMode(graphics, defOffsetmode);
362     GdipSetSmoothingMode(graphics, defSmoothmode);
363     GdipSetTextContrast(graphics, defContrast);
364     GdipSetTextRenderingHint(graphics, defTexthint);
365
366     status = GdipBeginContainer2(graphics, &cont1);
367     expect(Ok, status);
368
369     GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
370     GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
371     GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
372     GdipSetPageScale(graphics, 10);
373     GdipSetPageUnit(graphics, UnitDocument);
374     GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
375     GdipSetSmoothingMode(graphics, SmoothingModeNone);
376     GdipSetTextContrast(graphics, 7);
377     GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
378
379     status = GdipEndContainer(graphics, cont1);
380     expect(Ok, status);
381
382     GdipGetCompositingMode(graphics, &compmode);
383     ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
384
385     GdipGetCompositingQuality(graphics, &compqual);
386     ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
387
388     GdipGetInterpolationMode(graphics, &interp);
389     ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
390
391     GdipGetPageScale(graphics, &scale);
392     ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
393
394     GdipGetPageUnit(graphics, &unit);
395     ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
396
397     GdipGetPixelOffsetMode(graphics, &offsetmode);
398     ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
399
400     GdipGetSmoothingMode(graphics, &smoothmode);
401     ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
402
403     GdipGetTextContrast(graphics, &contrast);
404     ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
405
406     GdipGetTextRenderingHint(graphics, &texthint);
407     ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
408
409     /* test world transform */
410     status = GdipBeginContainer2(graphics, &cont1);
411     expect(Ok, status);
412
413     GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
414             defTrans[4], defTrans[5], &transform);
415     GdipSetWorldTransform(graphics, transform);
416     GdipDeleteMatrix(transform);
417     transform = NULL;
418
419     status = GdipBeginContainer2(graphics, &cont2);
420     expect(Ok, status);
421
422     GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
423     GdipSetWorldTransform(graphics, transform);
424     GdipDeleteMatrix(transform);
425     transform = NULL;
426
427     status = GdipEndContainer(graphics, cont2);
428     expect(Ok, status);
429
430     GdipCreateMatrix(&transform);
431     GdipGetWorldTransform(graphics, transform);
432     GdipGetMatrixElements(transform, elems);
433     ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
434             fabs(defTrans[1] - elems[1]) < 0.0001 &&
435             fabs(defTrans[2] - elems[2]) < 0.0001 &&
436             fabs(defTrans[3] - elems[3]) < 0.0001 &&
437             fabs(defTrans[4] - elems[4]) < 0.0001 &&
438             fabs(defTrans[5] - elems[5]) < 0.0001,
439             "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
440             defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
441             elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
442     GdipDeleteMatrix(transform);
443     transform = NULL;
444
445     status = GdipEndContainer(graphics, cont1);
446     expect(Ok, status);
447
448     /* test clipping */
449     status = GdipBeginContainer2(graphics, &cont1);
450     expect(Ok, status);
451
452     GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
453
454     status = GdipBeginContainer2(graphics, &cont2);
455     expect(Ok, status);
456
457     GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
458
459     status = GdipEndContainer(graphics, cont2);
460
461     GdipGetClipBounds(graphics, &clip);
462     ok(fabs(defClip[0] - clip.X) < 0.0001 &&
463             fabs(defClip[1] - clip.Y) < 0.0001 &&
464             fabs(defClip[2] - clip.Width) < 0.0001 &&
465             fabs(defClip[3] - clip.Height) < 0.0001,
466             "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
467             defClip[0], defClip[1], defClip[2], defClip[3],
468             clip.X, clip.Y, clip.Width, clip.Height);
469
470     status = GdipEndContainer(graphics, cont1);
471
472     /* nesting */
473     status = GdipBeginContainer2(graphics, &cont1);
474     expect(Ok, status);
475
476     status = GdipBeginContainer2(graphics, &cont2);
477     expect(Ok, status);
478
479     status = GdipBeginContainer2(graphics, &cont3);
480     expect(Ok, status);
481
482     status = GdipEndContainer(graphics, cont3);
483     expect(Ok, status);
484
485     status = GdipBeginContainer2(graphics, &cont4);
486     expect(Ok, status);
487
488     status = GdipEndContainer(graphics, cont4);
489     expect(Ok, status);
490
491     /* skip cont2 */
492     status = GdipEndContainer(graphics, cont1);
493     expect(Ok, status);
494
495     /* end an already-ended container */
496     status = GdipEndContainer(graphics, cont1);
497     expect(Ok, status);
498
499     GdipDeleteGraphics(graphics);
500     ReleaseDC(0, hdc);
501 }
502
503 static void test_GdipDrawBezierI(void)
504 {
505     GpStatus status;
506     GpGraphics *graphics = NULL;
507     GpPen *pen = NULL;
508     HDC hdc = GetDC(0);
509
510     /* make a graphics object and pen object */
511     ok(hdc != NULL, "Expected HDC to be initialized\n");
512
513     status = GdipCreateFromHDC(hdc, &graphics);
514     expect(Ok, status);
515     ok(graphics != NULL, "Expected graphics to be initialized\n");
516
517     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
518     expect(Ok, status);
519     ok(pen != NULL, "Expected pen to be initialized\n");
520
521     /* InvalidParameter cases: null graphics, null pen */
522     status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
523     expect(InvalidParameter, status);
524
525     status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
526     expect(InvalidParameter, status);
527
528     status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
529     expect(InvalidParameter, status);
530
531     /* successful case */
532     status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
533     expect(Ok, status);
534
535     GdipDeletePen(pen);
536     GdipDeleteGraphics(graphics);
537
538     ReleaseDC(0, hdc);
539 }
540
541 static void test_GdipDrawCurve3(void)
542 {
543     GpStatus status;
544     GpGraphics *graphics = NULL;
545     GpPen *pen = NULL;
546     HDC hdc = GetDC(0);
547     GpPointF points[3];
548
549     points[0].X = 0;
550     points[0].Y = 0;
551
552     points[1].X = 40;
553     points[1].Y = 20;
554
555     points[2].X = 10;
556     points[2].Y = 40;
557
558     /* make a graphics object and pen object */
559     ok(hdc != NULL, "Expected HDC to be initialized\n");
560
561     status = GdipCreateFromHDC(hdc, &graphics);
562     expect(Ok, status);
563     ok(graphics != NULL, "Expected graphics to be initialized\n");
564
565     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
566     expect(Ok, status);
567     ok(pen != NULL, "Expected pen to be initialized\n");
568
569     /* InvalidParameter cases: null graphics, null pen */
570     status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
571     expect(InvalidParameter, status);
572
573     status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
574     expect(InvalidParameter, status);
575
576     status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
577     expect(InvalidParameter, status);
578
579     /* InvalidParameter cases: invalid count */
580     status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
581     expect(InvalidParameter, status);
582
583     status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
584     expect(InvalidParameter, status);
585
586     status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
587     expect(InvalidParameter, status);
588
589     status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
590     expect(InvalidParameter, status);
591
592     /* InvalidParameter cases: invalid number of segments */
593     status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
594     expect(InvalidParameter, status);
595
596     status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
597     expect(InvalidParameter, status);
598
599     status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
600     expect(InvalidParameter, status);
601
602     /* Valid test cases */
603     status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
604     expect(Ok, status);
605
606     status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
607     expect(Ok, status);
608
609     status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
610     expect(Ok, status);
611
612     status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
613     expect(Ok, status);
614
615     GdipDeletePen(pen);
616     GdipDeleteGraphics(graphics);
617
618     ReleaseDC(0, hdc);
619 }
620
621 static void test_GdipDrawCurve3I(void)
622 {
623     GpStatus status;
624     GpGraphics *graphics = NULL;
625     GpPen *pen = NULL;
626     HDC hdc = GetDC(0);
627     GpPoint points[3];
628
629     points[0].X = 0;
630     points[0].Y = 0;
631
632     points[1].X = 40;
633     points[1].Y = 20;
634
635     points[2].X = 10;
636     points[2].Y = 40;
637
638     /* make a graphics object and pen object */
639     ok(hdc != NULL, "Expected HDC to be initialized\n");
640
641     status = GdipCreateFromHDC(hdc, &graphics);
642     expect(Ok, status);
643     ok(graphics != NULL, "Expected graphics to be initialized\n");
644
645     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
646     expect(Ok, status);
647     ok(pen != NULL, "Expected pen to be initialized\n");
648
649     /* InvalidParameter cases: null graphics, null pen */
650     status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
651     expect(InvalidParameter, status);
652
653     status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
654     expect(InvalidParameter, status);
655
656     status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
657     expect(InvalidParameter, status);
658
659     /* InvalidParameter cases: invalid count */
660     status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
661     expect(OutOfMemory, status);
662
663     status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
664     expect(InvalidParameter, status);
665
666     status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
667     expect(InvalidParameter, status);
668
669     status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
670     expect(InvalidParameter, status);
671
672     /* InvalidParameter cases: invalid number of segments */
673     status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
674     expect(InvalidParameter, status);
675
676     status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
677     expect(InvalidParameter, status);
678
679     status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
680     expect(InvalidParameter, status);
681
682     /* Valid test cases */
683     status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
684     expect(Ok, status);
685
686     status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
687     expect(Ok, status);
688
689     status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
690     expect(Ok, status);
691
692     status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
693     expect(Ok, status);
694
695     GdipDeletePen(pen);
696     GdipDeleteGraphics(graphics);
697
698     ReleaseDC(0, hdc);
699 }
700
701 static void test_GdipDrawCurve2(void)
702 {
703     GpStatus status;
704     GpGraphics *graphics = NULL;
705     GpPen *pen = NULL;
706     HDC hdc = GetDC(0);
707     GpPointF points[3];
708
709     points[0].X = 0;
710     points[0].Y = 0;
711
712     points[1].X = 40;
713     points[1].Y = 20;
714
715     points[2].X = 10;
716     points[2].Y = 40;
717
718     /* make a graphics object and pen object */
719     ok(hdc != NULL, "Expected HDC to be initialized\n");
720
721     status = GdipCreateFromHDC(hdc, &graphics);
722     expect(Ok, status);
723     ok(graphics != NULL, "Expected graphics to be initialized\n");
724
725     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
726     expect(Ok, status);
727     ok(pen != NULL, "Expected pen to be initialized\n");
728
729     /* InvalidParameter cases: null graphics, null pen */
730     status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
731     expect(InvalidParameter, status);
732
733     status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
734     expect(InvalidParameter, status);
735
736     status = GdipDrawCurve2(NULL, pen, points, 3, 1);
737     expect(InvalidParameter, status);
738
739     /* InvalidParameter cases: invalid count */
740     status = GdipDrawCurve2(graphics, pen, points, -1, 1);
741     expect(InvalidParameter, status);
742
743     status = GdipDrawCurve2(graphics, pen, points, 0, 1);
744     expect(InvalidParameter, status);
745
746     status = GdipDrawCurve2(graphics, pen, points, 1, 1);
747     expect(InvalidParameter, status);
748
749     /* Valid test cases */
750     status = GdipDrawCurve2(graphics, pen, points, 2, 1);
751     expect(Ok, status);
752
753     status = GdipDrawCurve2(graphics, pen, points, 3, 2);
754     expect(Ok, status);
755
756     status = GdipDrawCurve2(graphics, pen, points, 3, -2);
757     expect(Ok, status);
758
759     status = GdipDrawCurve2(graphics, pen, points, 3, 0);
760     expect(Ok, status);
761
762     GdipDeletePen(pen);
763     GdipDeleteGraphics(graphics);
764
765     ReleaseDC(0, hdc);
766 }
767
768 static void test_GdipDrawCurve2I(void)
769 {
770     GpStatus status;
771     GpGraphics *graphics = NULL;
772     GpPen *pen = NULL;
773     HDC hdc = GetDC(0);
774     GpPoint points[3];
775
776     points[0].X = 0;
777     points[0].Y = 0;
778
779     points[1].X = 40;
780     points[1].Y = 20;
781
782     points[2].X = 10;
783     points[2].Y = 40;
784
785     /* make a graphics object and pen object */
786     ok(hdc != NULL, "Expected HDC to be initialized\n");
787
788     status = GdipCreateFromHDC(hdc, &graphics);
789     expect(Ok, status);
790     ok(graphics != NULL, "Expected graphics to be initialized\n");
791
792     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
793     expect(Ok, status);
794     ok(pen != NULL, "Expected pen to be initialized\n");
795
796     /* InvalidParameter cases: null graphics, null pen */
797     status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
798     expect(InvalidParameter, status);
799
800     status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
801     expect(InvalidParameter, status);
802
803     status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
804     expect(InvalidParameter, status);
805
806     /* InvalidParameter cases: invalid count */
807     status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
808     expect(OutOfMemory, status);
809
810     status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
811     expect(InvalidParameter, status);
812
813     status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
814     expect(InvalidParameter, status);
815
816     /* Valid test cases */
817     status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
818     expect(Ok, status);
819
820     status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
821     expect(Ok, status);
822
823     status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
824     expect(Ok, status);
825
826     status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
827     expect(Ok, status);
828
829     GdipDeletePen(pen);
830     GdipDeleteGraphics(graphics);
831
832     ReleaseDC(0, hdc);
833 }
834
835 static void test_GdipDrawCurve(void)
836 {
837     GpStatus status;
838     GpGraphics *graphics = NULL;
839     GpPen *pen = NULL;
840     HDC hdc = GetDC(0);
841     GpPointF points[3];
842
843     points[0].X = 0;
844     points[0].Y = 0;
845
846     points[1].X = 40;
847     points[1].Y = 20;
848
849     points[2].X = 10;
850     points[2].Y = 40;
851
852     /* make a graphics object and pen object */
853     ok(hdc != NULL, "Expected HDC to be initialized\n");
854
855     status = GdipCreateFromHDC(hdc, &graphics);
856     expect(Ok, status);
857     ok(graphics != NULL, "Expected graphics to be initialized\n");
858
859     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
860     expect(Ok, status);
861     ok(pen != NULL, "Expected pen to be initialized\n");
862
863     /* InvalidParameter cases: null graphics, null pen */
864     status = GdipDrawCurve(NULL, NULL, points, 3);
865     expect(InvalidParameter, status);
866
867     status = GdipDrawCurve(graphics, NULL, points, 3);
868     expect(InvalidParameter, status);
869
870     status = GdipDrawCurve(NULL, pen, points, 3);
871     expect(InvalidParameter, status);
872
873     /* InvalidParameter cases: invalid count */
874     status = GdipDrawCurve(graphics, pen, points, -1);
875     expect(InvalidParameter, status);
876
877     status = GdipDrawCurve(graphics, pen, points, 0);
878     expect(InvalidParameter, status);
879
880     status = GdipDrawCurve(graphics, pen, points, 1);
881     expect(InvalidParameter, status);
882
883     /* Valid test cases */
884     status = GdipDrawCurve(graphics, pen, points, 2);
885     expect(Ok, status);
886
887     status = GdipDrawCurve(graphics, pen, points, 3);
888     expect(Ok, status);
889
890     GdipDeletePen(pen);
891     GdipDeleteGraphics(graphics);
892
893     ReleaseDC(0, hdc);
894 }
895
896 static void test_GdipDrawCurveI(void)
897 {
898     GpStatus status;
899     GpGraphics *graphics = NULL;
900     GpPen *pen = NULL;
901     HDC hdc = GetDC(0);
902     GpPoint points[3];
903
904     points[0].X = 0;
905     points[0].Y = 0;
906
907     points[1].X = 40;
908     points[1].Y = 20;
909
910     points[2].X = 10;
911     points[2].Y = 40;
912
913     /* make a graphics object and pen object */
914     ok(hdc != NULL, "Expected HDC to be initialized\n");
915
916     status = GdipCreateFromHDC(hdc, &graphics);
917     expect(Ok, status);
918     ok(graphics != NULL, "Expected graphics to be initialized\n");
919
920     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
921     expect(Ok, status);
922     ok(pen != NULL, "Expected pen to be initialized\n");
923
924     /* InvalidParameter cases: null graphics, null pen */
925     status = GdipDrawCurveI(NULL, NULL, points, 3);
926     expect(InvalidParameter, status);
927
928     status = GdipDrawCurveI(graphics, NULL, points, 3);
929     expect(InvalidParameter, status);
930
931     status = GdipDrawCurveI(NULL, pen, points, 3);
932     expect(InvalidParameter, status);
933
934     /* InvalidParameter cases: invalid count */
935     status = GdipDrawCurveI(graphics, pen, points, -1);
936     expect(OutOfMemory, status);
937
938     status = GdipDrawCurveI(graphics, pen, points, 0);
939     expect(InvalidParameter, status);
940
941     status = GdipDrawCurveI(graphics, pen, points, 1);
942     expect(InvalidParameter, status);
943
944     /* Valid test cases */
945     status = GdipDrawCurveI(graphics, pen, points, 2);
946     expect(Ok, status);
947
948     status = GdipDrawCurveI(graphics, pen, points, 3);
949     expect(Ok, status);
950
951     GdipDeletePen(pen);
952     GdipDeleteGraphics(graphics);
953
954     ReleaseDC(0, hdc);
955 }
956
957 static void test_GdipDrawLineI(void)
958 {
959     GpStatus status;
960     GpGraphics *graphics = NULL;
961     GpPen *pen = NULL;
962     HDC hdc = GetDC(0);
963
964     /* make a graphics object and pen object */
965     ok(hdc != NULL, "Expected HDC to be initialized\n");
966
967     status = GdipCreateFromHDC(hdc, &graphics);
968     expect(Ok, status);
969     ok(graphics != NULL, "Expected graphics to be initialized\n");
970
971     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
972     expect(Ok, status);
973     ok(pen != NULL, "Expected pen to be initialized\n");
974
975     /* InvalidParameter cases: null graphics, null pen */
976     status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
977     expect(InvalidParameter, status);
978
979     status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
980     expect(InvalidParameter, status);
981
982     status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
983     expect(InvalidParameter, status);
984
985     /* successful case */
986     status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
987     expect(Ok, status);
988
989     GdipDeletePen(pen);
990     GdipDeleteGraphics(graphics);
991
992     ReleaseDC(0, hdc);
993 }
994
995 static void test_GdipDrawLinesI(void)
996 {
997     GpStatus status;
998     GpGraphics *graphics = NULL;
999     GpPen *pen = NULL;
1000     GpPoint *ptf = NULL;
1001     HDC hdc = GetDC(0);
1002
1003     /* make a graphics object and pen object */
1004     ok(hdc != NULL, "Expected HDC to be initialized\n");
1005
1006     status = GdipCreateFromHDC(hdc, &graphics);
1007     expect(Ok, status);
1008     ok(graphics != NULL, "Expected graphics to be initialized\n");
1009
1010     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1011     expect(Ok, status);
1012     ok(pen != NULL, "Expected pen to be initialized\n");
1013
1014     /* make some arbitrary valid points*/
1015     ptf = GdipAlloc(2 * sizeof(GpPointF));
1016
1017     ptf[0].X = 1;
1018     ptf[0].Y = 1;
1019
1020     ptf[1].X = 2;
1021     ptf[1].Y = 2;
1022
1023     /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1024     status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1025     expect(InvalidParameter, status);
1026
1027     status = GdipDrawLinesI(graphics, pen, ptf, 0);
1028     expect(InvalidParameter, status);
1029
1030     status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1031     expect(InvalidParameter, status);
1032
1033     status = GdipDrawLinesI(NULL, pen, ptf, 2);
1034     expect(InvalidParameter, status);
1035
1036     /* successful case */
1037     status = GdipDrawLinesI(graphics, pen, ptf, 2);
1038     expect(Ok, status);
1039
1040     GdipFree(ptf);
1041     GdipDeletePen(pen);
1042     GdipDeleteGraphics(graphics);
1043
1044     ReleaseDC(0, hdc);
1045 }
1046
1047 static void test_Get_Release_DC(void)
1048 {
1049     GpStatus status;
1050     GpGraphics *graphics = NULL;
1051     GpPen *pen;
1052     GpSolidFill *brush;
1053     GpPath *path;
1054     HDC hdc = GetDC(0);
1055     HDC retdc;
1056     REAL r;
1057     CompositingQuality quality;
1058     CompositingMode compmode;
1059     InterpolationMode intmode;
1060     GpMatrix *m;
1061     GpRegion *region;
1062     GpUnit unit;
1063     PixelOffsetMode offsetmode;
1064     SmoothingMode smoothmode;
1065     TextRenderingHint texthint;
1066     GpPointF ptf[5];
1067     GpPoint  pt[5];
1068     GpRectF  rectf[2];
1069     GpRect   rect[2];
1070     GpRegion *clip;
1071     INT i;
1072     BOOL res;
1073     ARGB color = 0x00000000;
1074     HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1075
1076     pt[0].X = 10;
1077     pt[0].Y = 10;
1078     pt[1].X = 20;
1079     pt[1].Y = 15;
1080     pt[2].X = 40;
1081     pt[2].Y = 80;
1082     pt[3].X = -20;
1083     pt[3].Y = 20;
1084     pt[4].X = 50;
1085     pt[4].Y = 110;
1086
1087     for(i = 0; i < 5;i++){
1088         ptf[i].X = (REAL)pt[i].X;
1089         ptf[i].Y = (REAL)pt[i].Y;
1090     }
1091
1092     rect[0].X = 0;
1093     rect[0].Y = 0;
1094     rect[0].Width  = 50;
1095     rect[0].Height = 70;
1096     rect[1].X = 0;
1097     rect[1].Y = 0;
1098     rect[1].Width  = 10;
1099     rect[1].Height = 20;
1100
1101     for(i = 0; i < 2;i++){
1102         rectf[i].X = (REAL)rect[i].X;
1103         rectf[i].Y = (REAL)rect[i].Y;
1104         rectf[i].Height = (REAL)rect[i].Height;
1105         rectf[i].Width  = (REAL)rect[i].Width;
1106     }
1107
1108     GdipCreateMatrix(&m);
1109     GdipCreateRegion(&region);
1110     GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1111     GdipCreatePath(FillModeAlternate, &path);
1112     GdipCreateRegion(&clip);
1113
1114     status = GdipCreateFromHDC(hdc, &graphics);
1115     expect(Ok, status);
1116     ok(graphics != NULL, "Expected graphics to be initialized\n");
1117     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1118     expect(Ok, status);
1119
1120     /* NULL arguments */
1121     status = GdipGetDC(NULL, NULL);
1122     expect(InvalidParameter, status);
1123     status = GdipGetDC(graphics, NULL);
1124     expect(InvalidParameter, status);
1125     status = GdipGetDC(NULL, &retdc);
1126     expect(InvalidParameter, status);
1127
1128     status = GdipReleaseDC(NULL, NULL);
1129     expect(InvalidParameter, status);
1130     status = GdipReleaseDC(graphics, NULL);
1131     expect(InvalidParameter, status);
1132     status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1133     expect(InvalidParameter, status);
1134
1135     /* Release without Get */
1136     status = GdipReleaseDC(graphics, hdc);
1137     expect(InvalidParameter, status);
1138
1139     retdc = NULL;
1140     status = GdipGetDC(graphics, &retdc);
1141     expect(Ok, status);
1142     ok(retdc == hdc, "Invalid HDC returned\n");
1143     /* call it once more */
1144     status = GdipGetDC(graphics, &retdc);
1145     expect(ObjectBusy, status);
1146
1147     /* try all Graphics calls here */
1148     status = Ok;
1149     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1150     expect(ObjectBusy, status); status = Ok;
1151     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1152     expect(ObjectBusy, status); status = Ok;
1153     status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1154     expect(ObjectBusy, status); status = Ok;
1155     status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1156     expect(ObjectBusy, status); status = Ok;
1157     status = GdipDrawBeziers(graphics, pen, ptf, 5);
1158     expect(ObjectBusy, status); status = Ok;
1159     status = GdipDrawBeziersI(graphics, pen, pt, 5);
1160     expect(ObjectBusy, status); status = Ok;
1161     status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1162     expect(ObjectBusy, status); status = Ok;
1163     status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1164     expect(ObjectBusy, status); status = Ok;
1165     status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1166     expect(ObjectBusy, status); status = Ok;
1167     status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1168     expect(ObjectBusy, status); status = Ok;
1169     status = GdipDrawCurve(graphics, pen, ptf, 5);
1170     expect(ObjectBusy, status); status = Ok;
1171     status = GdipDrawCurveI(graphics, pen, pt, 5);
1172     expect(ObjectBusy, status); status = Ok;
1173     status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1174     expect(ObjectBusy, status); status = Ok;
1175     status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1176     expect(ObjectBusy, status); status = Ok;
1177     status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1178     expect(ObjectBusy, status); status = Ok;
1179     status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1180     expect(ObjectBusy, status); status = Ok;
1181     /* GdipDrawImage/GdipDrawImageI */
1182     /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1183     /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1184     /* GdipDrawImageRect/GdipDrawImageRectI */
1185     status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1186     expect(ObjectBusy, status); status = Ok;
1187     status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1188     expect(ObjectBusy, status); status = Ok;
1189     status = GdipDrawLines(graphics, pen, ptf, 5);
1190     expect(ObjectBusy, status); status = Ok;
1191     status = GdipDrawLinesI(graphics, pen, pt, 5);
1192     expect(ObjectBusy, status); status = Ok;
1193     status = GdipDrawPath(graphics, pen, path);
1194     expect(ObjectBusy, status); status = Ok;
1195     status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1196     expect(ObjectBusy, status); status = Ok;
1197     status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1198     expect(ObjectBusy, status); status = Ok;
1199     status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1200     expect(ObjectBusy, status); status = Ok;
1201     status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1202     expect(ObjectBusy, status); status = Ok;
1203     status = GdipDrawRectangles(graphics, pen, rectf, 2);
1204     expect(ObjectBusy, status); status = Ok;
1205     status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1206     expect(ObjectBusy, status); status = Ok;
1207     /* GdipDrawString */
1208     status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1209     expect(ObjectBusy, status); status = Ok;
1210     status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1211     expect(ObjectBusy, status); status = Ok;
1212     status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1213     expect(ObjectBusy, status); status = Ok;
1214     status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1215     expect(ObjectBusy, status); status = Ok;
1216     status = GdipFillPath(graphics, (GpBrush*)brush, path);
1217     expect(ObjectBusy, status); status = Ok;
1218     status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1219     expect(ObjectBusy, status); status = Ok;
1220     status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1221     expect(ObjectBusy, status); status = Ok;
1222     status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1223     expect(ObjectBusy, status); status = Ok;
1224     status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1225     expect(ObjectBusy, status); status = Ok;
1226     status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1227     expect(ObjectBusy, status); status = Ok;
1228     status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1229     expect(ObjectBusy, status); status = Ok;
1230     status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1231     expect(ObjectBusy, status); status = Ok;
1232     status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1233     expect(ObjectBusy, status); status = Ok;
1234     status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1235     expect(ObjectBusy, status); status = Ok;
1236     status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1237     expect(ObjectBusy, status); status = Ok;
1238     status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1239     expect(ObjectBusy, status); status = Ok;
1240     status = GdipFlush(graphics, FlushIntentionFlush);
1241     expect(ObjectBusy, status); status = Ok;
1242     status = GdipGetClipBounds(graphics, rectf);
1243     expect(ObjectBusy, status); status = Ok;
1244     status = GdipGetClipBoundsI(graphics, rect);
1245     expect(ObjectBusy, status); status = Ok;
1246     status = GdipGetCompositingMode(graphics, &compmode);
1247     expect(ObjectBusy, status); status = Ok;
1248     status = GdipGetCompositingQuality(graphics, &quality);
1249     expect(ObjectBusy, status); status = Ok;
1250     status = GdipGetInterpolationMode(graphics, &intmode);
1251     expect(ObjectBusy, status); status = Ok;
1252     status = GdipGetNearestColor(graphics, &color);
1253     expect(ObjectBusy, status); status = Ok;
1254     status = GdipGetPageScale(graphics, &r);
1255     expect(ObjectBusy, status); status = Ok;
1256     status = GdipGetPageUnit(graphics, &unit);
1257     expect(ObjectBusy, status); status = Ok;
1258     status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1259     expect(ObjectBusy, status); status = Ok;
1260     status = GdipGetSmoothingMode(graphics, &smoothmode);
1261     expect(ObjectBusy, status); status = Ok;
1262     status = GdipGetTextRenderingHint(graphics, &texthint);
1263     expect(ObjectBusy, status); status = Ok;
1264     status = GdipGetWorldTransform(graphics, m);
1265     expect(ObjectBusy, status); status = Ok;
1266     status = GdipGraphicsClear(graphics, 0xdeadbeef);
1267     expect(ObjectBusy, status); status = Ok;
1268     status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1269     expect(ObjectBusy, status); status = Ok;
1270     status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1271     expect(ObjectBusy, status); status = Ok;
1272     /* GdipMeasureCharacterRanges */
1273     /* GdipMeasureString */
1274     status = GdipResetClip(graphics);
1275     expect(ObjectBusy, status); status = Ok;
1276     status = GdipResetWorldTransform(graphics);
1277     expect(ObjectBusy, status); status = Ok;
1278     /* GdipRestoreGraphics */
1279     status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1280     expect(ObjectBusy, status); status = Ok;
1281     /*  GdipSaveGraphics */
1282     status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1283     expect(ObjectBusy, status); status = Ok;
1284     status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1285     expect(ObjectBusy, status); status = Ok;
1286     status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1287     expect(ObjectBusy, status); status = Ok;
1288     status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1289     expect(ObjectBusy, status); status = Ok;
1290     status = GdipSetPageScale(graphics, 1.0);
1291     expect(ObjectBusy, status); status = Ok;
1292     status = GdipSetPageUnit(graphics, UnitWorld);
1293     expect(ObjectBusy, status); status = Ok;
1294     status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1295     expect(ObjectBusy, status); status = Ok;
1296     status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1297     expect(ObjectBusy, status); status = Ok;
1298     status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1299     expect(ObjectBusy, status); status = Ok;
1300     status = GdipSetWorldTransform(graphics, m);
1301     expect(ObjectBusy, status); status = Ok;
1302     status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1303     expect(ObjectBusy, status); status = Ok;
1304     status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1305     expect(ObjectBusy, status); status = Ok;
1306     status = GdipSetClipPath(graphics, path, CombineModeReplace);
1307     expect(ObjectBusy, status); status = Ok;
1308     status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1309     expect(ObjectBusy, status); status = Ok;
1310     status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1311     expect(ObjectBusy, status); status = Ok;
1312     status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1313     expect(ObjectBusy, status); status = Ok;
1314     status = GdipTranslateClip(graphics, 0.0, 0.0);
1315     expect(ObjectBusy, status); status = Ok;
1316     status = GdipTranslateClipI(graphics, 0, 0);
1317     expect(ObjectBusy, status); status = Ok;
1318     status = GdipDrawPolygon(graphics, pen, ptf, 5);
1319     expect(ObjectBusy, status); status = Ok;
1320     status = GdipDrawPolygonI(graphics, pen, pt, 5);
1321     expect(ObjectBusy, status); status = Ok;
1322     status = GdipGetDpiX(graphics, &r);
1323     expect(ObjectBusy, status); status = Ok;
1324     status = GdipGetDpiY(graphics, &r);
1325     expect(ObjectBusy, status); status = Ok;
1326     status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1327     status = GdipGetClip(graphics, region);
1328     expect(ObjectBusy, status); status = Ok;
1329     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1330     expect(ObjectBusy, status); status = Ok;
1331     /* try to delete before release */
1332     status = GdipDeleteGraphics(graphics);
1333     expect(ObjectBusy, status);
1334
1335     status = GdipReleaseDC(graphics, retdc);
1336     expect(Ok, status);
1337
1338     GdipDeletePen(pen);
1339     GdipDeleteGraphics(graphics);
1340
1341     GdipDeletePath(path);
1342     GdipDeleteBrush((GpBrush*)brush);
1343     GdipDeleteRegion(region);
1344     GdipDeleteMatrix(m);
1345     DeleteObject(hrgn);
1346
1347     ReleaseDC(0, hdc);
1348 }
1349
1350 static void test_transformpoints(void)
1351 {
1352     GpStatus status;
1353     GpGraphics *graphics = NULL;
1354     HDC hdc = GetDC(0);
1355     GpPointF ptf[2];
1356     GpPoint pt[2];
1357
1358     status = GdipCreateFromHDC(hdc, &graphics);
1359     expect(Ok, status);
1360
1361     /* NULL arguments */
1362     status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1363     expect(InvalidParameter, status);
1364     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1365     expect(InvalidParameter, status);
1366     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1367     expect(InvalidParameter, status);
1368     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1369     expect(InvalidParameter, status);
1370
1371     ptf[0].X = 1.0;
1372     ptf[0].Y = 0.0;
1373     ptf[1].X = 0.0;
1374     ptf[1].Y = 1.0;
1375     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1376     expect(Ok, status);
1377     expectf(1.0, ptf[0].X);
1378     expectf(0.0, ptf[0].Y);
1379     expectf(0.0, ptf[1].X);
1380     expectf(1.0, ptf[1].Y);
1381
1382     status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1383     expect(Ok, status);
1384     status = GdipSetPageUnit(graphics, UnitPixel);
1385     expect(Ok, status);
1386     status = GdipSetPageScale(graphics, 3.0);
1387     expect(Ok, status);
1388
1389     ptf[0].X = 1.0;
1390     ptf[0].Y = 0.0;
1391     ptf[1].X = 0.0;
1392     ptf[1].Y = 1.0;
1393     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1394     expect(Ok, status);
1395     expectf(18.0, ptf[0].X);
1396     expectf(15.0, ptf[0].Y);
1397     expectf(15.0, ptf[1].X);
1398     expectf(18.0, ptf[1].Y);
1399
1400     ptf[0].X = 1.0;
1401     ptf[0].Y = 0.0;
1402     ptf[1].X = 0.0;
1403     ptf[1].Y = 1.0;
1404     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1405     expect(Ok, status);
1406     expectf(6.0, ptf[0].X);
1407     expectf(5.0, ptf[0].Y);
1408     expectf(5.0, ptf[1].X);
1409     expectf(6.0, ptf[1].Y);
1410
1411     ptf[0].X = 1.0;
1412     ptf[0].Y = 0.0;
1413     ptf[1].X = 0.0;
1414     ptf[1].Y = 1.0;
1415     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1416     expect(Ok, status);
1417     expectf(3.0, ptf[0].X);
1418     expectf(0.0, ptf[0].Y);
1419     expectf(0.0, ptf[1].X);
1420     expectf(3.0, ptf[1].Y);
1421
1422     ptf[0].X = 18.0;
1423     ptf[0].Y = 15.0;
1424     ptf[1].X = 15.0;
1425     ptf[1].Y = 18.0;
1426     status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1427     expect(Ok, status);
1428     expectf(1.0, ptf[0].X);
1429     expectf(0.0, ptf[0].Y);
1430     expectf(0.0, ptf[1].X);
1431     expectf(1.0, ptf[1].Y);
1432
1433     ptf[0].X = 6.0;
1434     ptf[0].Y = 5.0;
1435     ptf[1].X = 5.0;
1436     ptf[1].Y = 6.0;
1437     status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1438     expect(Ok, status);
1439     expectf(1.0, ptf[0].X);
1440     expectf(0.0, ptf[0].Y);
1441     expectf(0.0, ptf[1].X);
1442     expectf(1.0, ptf[1].Y);
1443
1444     ptf[0].X = 3.0;
1445     ptf[0].Y = 0.0;
1446     ptf[1].X = 0.0;
1447     ptf[1].Y = 3.0;
1448     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1449     expect(Ok, status);
1450     expectf(1.0, ptf[0].X);
1451     expectf(0.0, ptf[0].Y);
1452     expectf(0.0, ptf[1].X);
1453     expectf(1.0, ptf[1].Y);
1454
1455     pt[0].X = 1;
1456     pt[0].Y = 0;
1457     pt[1].X = 0;
1458     pt[1].Y = 1;
1459     status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1460     expect(Ok, status);
1461     expect(18, pt[0].X);
1462     expect(15, pt[0].Y);
1463     expect(15, pt[1].X);
1464     expect(18, pt[1].Y);
1465
1466     GdipDeleteGraphics(graphics);
1467     ReleaseDC(0, hdc);
1468 }
1469
1470 static void test_get_set_clip(void)
1471 {
1472     GpStatus status;
1473     GpGraphics *graphics = NULL;
1474     HDC hdc = GetDC(0);
1475     GpRegion *clip;
1476     GpRectF rect;
1477     BOOL res;
1478
1479     status = GdipCreateFromHDC(hdc, &graphics);
1480     expect(Ok, status);
1481
1482     rect.X = rect.Y = 0.0;
1483     rect.Height = rect.Width = 100.0;
1484
1485     status = GdipCreateRegionRect(&rect, &clip);
1486
1487     /* NULL arguments */
1488     status = GdipGetClip(NULL, NULL);
1489     expect(InvalidParameter, status);
1490     status = GdipGetClip(graphics, NULL);
1491     expect(InvalidParameter, status);
1492     status = GdipGetClip(NULL, clip);
1493     expect(InvalidParameter, status);
1494
1495     status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1496     expect(InvalidParameter, status);
1497     status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1498     expect(InvalidParameter, status);
1499
1500     status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
1501     expect(InvalidParameter, status);
1502     status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
1503     expect(InvalidParameter, status);
1504
1505     res = FALSE;
1506     status = GdipGetClip(graphics, clip);
1507     expect(Ok, status);
1508     status = GdipIsInfiniteRegion(clip, graphics, &res);
1509     expect(Ok, status);
1510     expect(TRUE, res);
1511
1512     /* remains infinite after reset */
1513     res = FALSE;
1514     status = GdipResetClip(graphics);
1515     expect(Ok, status);
1516     status = GdipGetClip(graphics, clip);
1517     expect(Ok, status);
1518     status = GdipIsInfiniteRegion(clip, graphics, &res);
1519     expect(Ok, status);
1520     expect(TRUE, res);
1521
1522     /* set to empty and then reset to infinite */
1523     status = GdipSetEmpty(clip);
1524     expect(Ok, status);
1525     status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1526     expect(Ok, status);
1527
1528     status = GdipGetClip(graphics, clip);
1529     expect(Ok, status);
1530     res = FALSE;
1531     status = GdipIsEmptyRegion(clip, graphics, &res);
1532     expect(Ok, status);
1533     expect(TRUE, res);
1534     status = GdipResetClip(graphics);
1535     expect(Ok, status);
1536     status = GdipGetClip(graphics, clip);
1537     expect(Ok, status);
1538     res = FALSE;
1539     status = GdipIsInfiniteRegion(clip, graphics, &res);
1540     expect(Ok, status);
1541     expect(TRUE, res);
1542
1543     GdipDeleteRegion(clip);
1544
1545     GdipDeleteGraphics(graphics);
1546     ReleaseDC(0, hdc);
1547 }
1548
1549 static void test_isempty(void)
1550 {
1551     GpStatus status;
1552     GpGraphics *graphics = NULL;
1553     HDC hdc = GetDC(0);
1554     GpRegion *clip;
1555     BOOL res;
1556
1557     status = GdipCreateFromHDC(hdc, &graphics);
1558     expect(Ok, status);
1559
1560     status = GdipCreateRegion(&clip);
1561     expect(Ok, status);
1562
1563     /* NULL */
1564     status = GdipIsClipEmpty(NULL, NULL);
1565     expect(InvalidParameter, status);
1566     status = GdipIsClipEmpty(graphics, NULL);
1567     expect(InvalidParameter, status);
1568     status = GdipIsClipEmpty(NULL, &res);
1569     expect(InvalidParameter, status);
1570
1571     /* default is infinite */
1572     res = TRUE;
1573     status = GdipIsClipEmpty(graphics, &res);
1574     expect(Ok, status);
1575     expect(FALSE, res);
1576
1577     GdipDeleteRegion(clip);
1578
1579     GdipDeleteGraphics(graphics);
1580     ReleaseDC(0, hdc);
1581 }
1582
1583 static void test_clear(void)
1584 {
1585     GpStatus status;
1586
1587     status = GdipGraphicsClear(NULL, 0xdeadbeef);
1588     expect(InvalidParameter, status);
1589 }
1590
1591 static void test_textcontrast(void)
1592 {
1593     GpStatus status;
1594     HDC hdc = GetDC(0);
1595     GpGraphics *graphics;
1596     UINT contrast;
1597
1598     status = GdipGetTextContrast(NULL, NULL);
1599     expect(InvalidParameter, status);
1600
1601     status = GdipCreateFromHDC(hdc, &graphics);
1602     expect(Ok, status);
1603
1604     status = GdipGetTextContrast(graphics, NULL);
1605     expect(InvalidParameter, status);
1606     status = GdipGetTextContrast(graphics, &contrast);
1607     expect(4, contrast);
1608
1609     GdipDeleteGraphics(graphics);
1610     ReleaseDC(0, hdc);
1611 }
1612
1613 static void test_GdipDrawString(void)
1614 {
1615     GpStatus status;
1616     GpGraphics *graphics = NULL;
1617     GpFont *fnt = NULL;
1618     RectF  rect;
1619     GpStringFormat *format;
1620     GpBrush *brush;
1621     LOGFONTA logfont;
1622     HDC hdc = GetDC(0);
1623     static const WCHAR string[] = {'T','e','s','t',0};
1624
1625     memset(&logfont,0,sizeof(logfont));
1626     strcpy(logfont.lfFaceName,"Arial");
1627     logfont.lfHeight = 12;
1628     logfont.lfCharSet = DEFAULT_CHARSET;
1629
1630     status = GdipCreateFromHDC(hdc, &graphics);
1631     expect(Ok, status);
1632
1633     status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
1634     if (status == FileNotFound)
1635     {
1636         skip("Arial not installed.\n");
1637         return;
1638     }
1639     expect(Ok, status);
1640
1641     status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
1642     expect(Ok, status);
1643
1644     status = GdipCreateStringFormat(0,0,&format);
1645     expect(Ok, status);
1646
1647     rect.X = 0;
1648     rect.Y = 0;
1649     rect.Width = 0;
1650     rect.Height = 12;
1651
1652     status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
1653     expect(Ok, status);
1654
1655     GdipDeleteGraphics(graphics);
1656     GdipDeleteBrush(brush);
1657     GdipDeleteFont(fnt);
1658     GdipDeleteStringFormat(format);
1659
1660     ReleaseDC(0, hdc);
1661 }
1662
1663 static void test_GdipGetVisibleClipBounds_screen(void)
1664 {
1665     GpStatus status;
1666     GpGraphics *graphics = NULL;
1667     HDC hdc = GetDC(0);
1668     GpRectF rectf, exp, clipr;
1669     GpRect recti;
1670
1671     ok(hdc != NULL, "Expected HDC to be initialized\n");
1672
1673     status = GdipCreateFromHDC(hdc, &graphics);
1674     expect(Ok, status);
1675     ok(graphics != NULL, "Expected graphics to be initialized\n");
1676
1677     /* no clipping rect */
1678     exp.X = 0;
1679     exp.Y = 0;
1680     exp.Width = GetDeviceCaps(hdc, HORZRES);
1681     exp.Height = GetDeviceCaps(hdc, VERTRES);
1682
1683     status = GdipGetVisibleClipBounds(graphics, &rectf);
1684     expect(Ok, status);
1685     ok(rectf.X == exp.X &&
1686         rectf.Y == exp.Y &&
1687         rectf.Width == exp.Width &&
1688         rectf.Height == exp.Height,
1689         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1690         "the screen (%0.f, %0.f, %0.f, %0.f)\n",
1691         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1692         exp.X, exp.Y, exp.Width, exp.Height);
1693
1694     /* clipping rect entirely within window */
1695     exp.X = clipr.X = 10;
1696     exp.Y = clipr.Y = 12;
1697     exp.Width = clipr.Width = 14;
1698     exp.Height = clipr.Height = 16;
1699
1700     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1701     expect(Ok, status);
1702
1703     status = GdipGetVisibleClipBounds(graphics, &rectf);
1704     expect(Ok, status);
1705     ok(rectf.X == exp.X &&
1706         rectf.Y == exp.Y &&
1707         rectf.Width == exp.Width &&
1708         rectf.Height == exp.Height,
1709         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1710         "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1711         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1712         exp.X, exp.Y, exp.Width, exp.Height);
1713
1714     /* clipping rect partially outside of screen */
1715     clipr.X = -10;
1716     clipr.Y = -12;
1717     clipr.Width = 20;
1718     clipr.Height = 24;
1719
1720     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1721     expect(Ok, status);
1722
1723     exp.X = 0;
1724     exp.Y = 0;
1725     exp.Width = 10;
1726     exp.Height = 12;
1727
1728     status = GdipGetVisibleClipBounds(graphics, &rectf);
1729     expect(Ok, status);
1730     ok(rectf.X == exp.X &&
1731         rectf.Y == exp.Y &&
1732         rectf.Width == exp.Width &&
1733         rectf.Height == exp.Height,
1734         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1735         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1736         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1737         exp.X, exp.Y, exp.Width, exp.Height);
1738
1739     status = GdipGetVisibleClipBoundsI(graphics, &recti);
1740     expect(Ok, status);
1741     ok(recti.X == exp.X &&
1742         recti.Y == exp.Y &&
1743         recti.Width == exp.Width &&
1744         recti.Height == exp.Height,
1745         "Expected clip bounds (%d, %d, %d, %d) to be the size of "
1746         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1747         recti.X, recti.Y, recti.Width, recti.Height,
1748         exp.X, exp.Y, exp.Width, exp.Height);
1749
1750     GdipDeleteGraphics(graphics);
1751     ReleaseDC(0, hdc);
1752 }
1753
1754 static void test_GdipGetVisibleClipBounds_window(void)
1755 {
1756     GpStatus status;
1757     GpGraphics *graphics = NULL;
1758     GpRectF rectf, window, exp, clipr;
1759     GpRect recti;
1760     HWND hwnd;
1761     WNDCLASSA class;
1762     HDC hdc;
1763     PAINTSTRUCT ps;
1764     HINSTANCE hInstance = GetModuleHandle(NULL);
1765     RECT wnd_rect;
1766
1767     window.X = 0;
1768     window.Y = 0;
1769     window.Width = 200;
1770     window.Height = 300;
1771
1772     class.lpszClassName = "ClipBoundsTestClass";
1773     class.style = CS_HREDRAW | CS_VREDRAW;
1774     class.lpfnWndProc = DefWindowProcA;
1775     class.hInstance = hInstance;
1776     class.hIcon = LoadIcon(0, IDI_APPLICATION);
1777     class.hCursor = LoadCursor(NULL, IDC_ARROW);
1778     class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
1779     class.lpszMenuName = 0;
1780     class.cbClsExtra = 0;
1781     class.cbWndExtra = 0;
1782     RegisterClass(&class);
1783
1784     hwnd = CreateWindow(class.lpszClassName, "ClipboundsTest",
1785         WS_OVERLAPPEDWINDOW, window.X, window.Y, window.Width, window.Height,
1786         NULL, NULL, hInstance, NULL);
1787
1788     ok(hwnd != NULL, "Expected window to be created\n");
1789
1790     /* get client area size */
1791     ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded");
1792     window.X = wnd_rect.left;
1793     window.Y = wnd_rect.top;
1794     window.Width = wnd_rect.right - wnd_rect.left;
1795     window.Height = wnd_rect.bottom - wnd_rect.top;
1796
1797     hdc = BeginPaint(hwnd, &ps);
1798
1799     status = GdipCreateFromHDC(hdc, &graphics);
1800     expect(Ok, status);
1801     ok(graphics != NULL, "Expected graphics to be initialized\n");
1802
1803     status = GdipGetVisibleClipBounds(graphics, &rectf);
1804     expect(Ok, status);
1805     ok(rectf.X == window.X &&
1806         rectf.Y == window.Y &&
1807         rectf.Width == window.Width &&
1808         rectf.Height == window.Height,
1809         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1810         "the window (%0.f, %0.f, %0.f, %0.f)\n",
1811         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1812         window.X, window.Y, window.Width, window.Height);
1813
1814     /* clipping rect entirely within window */
1815     exp.X = clipr.X = 20;
1816     exp.Y = clipr.Y = 8;
1817     exp.Width = clipr.Width = 30;
1818     exp.Height = clipr.Height = 20;
1819
1820     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1821     expect(Ok, status);
1822
1823     status = GdipGetVisibleClipBounds(graphics, &rectf);
1824     expect(Ok, status);
1825     ok(rectf.X == exp.X &&
1826         rectf.Y == exp.Y &&
1827         rectf.Width == exp.Width &&
1828         rectf.Height == exp.Height,
1829         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1830         "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1831         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1832         exp.X, exp.Y, exp.Width, exp.Height);
1833
1834     /* clipping rect partially outside of window */
1835     clipr.X = window.Width - 10;
1836     clipr.Y = window.Height - 15;
1837     clipr.Width = 20;
1838     clipr.Height = 30;
1839
1840     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1841     expect(Ok, status);
1842
1843     exp.X = window.Width - 10;
1844     exp.Y = window.Height - 15;
1845     exp.Width = 10;
1846     exp.Height = 15;
1847
1848     status = GdipGetVisibleClipBounds(graphics, &rectf);
1849     expect(Ok, status);
1850     ok(rectf.X == exp.X &&
1851         rectf.Y == exp.Y &&
1852         rectf.Width == exp.Width &&
1853         rectf.Height == exp.Height,
1854         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1855         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1856         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1857         exp.X, exp.Y, exp.Width, exp.Height);
1858
1859     status = GdipGetVisibleClipBoundsI(graphics, &recti);
1860     expect(Ok, status);
1861     ok(recti.X == exp.X &&
1862         recti.Y == exp.Y &&
1863         recti.Width == exp.Width &&
1864         recti.Height == exp.Height,
1865         "Expected clip bounds (%d, %d, %d, %d) to be the size of "
1866         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1867         recti.X, recti.Y, recti.Width, recti.Height,
1868         exp.X, exp.Y, exp.Width, exp.Height);
1869
1870     GdipDeleteGraphics(graphics);
1871     EndPaint(hwnd, &ps);
1872     DestroyWindow(hwnd);
1873 }
1874
1875 static void test_GdipGetVisibleClipBounds(void)
1876 {
1877     GpGraphics* graphics = NULL;
1878     GpRectF rectf;
1879     GpRect rect;
1880     HDC hdc = GetDC(0);
1881     GpStatus status;
1882
1883     status = GdipCreateFromHDC(hdc, &graphics);
1884     expect(Ok, status);
1885     ok(graphics != NULL, "Expected graphics to be initialized\n");
1886
1887     /* test null parameters */
1888     status = GdipGetVisibleClipBounds(graphics, NULL);
1889     expect(InvalidParameter, status);
1890
1891     status = GdipGetVisibleClipBounds(NULL, &rectf);
1892     expect(InvalidParameter, status);
1893
1894     status = GdipGetVisibleClipBoundsI(graphics, NULL);
1895     expect(InvalidParameter, status);
1896
1897     status = GdipGetVisibleClipBoundsI(NULL, &rect);
1898     expect(InvalidParameter, status);
1899
1900     GdipDeleteGraphics(graphics);
1901     ReleaseDC(0, hdc);
1902
1903     test_GdipGetVisibleClipBounds_screen();
1904     test_GdipGetVisibleClipBounds_window();
1905 }
1906
1907 START_TEST(graphics)
1908 {
1909     struct GdiplusStartupInput gdiplusStartupInput;
1910     ULONG_PTR gdiplusToken;
1911
1912     gdiplusStartupInput.GdiplusVersion              = 1;
1913     gdiplusStartupInput.DebugEventCallback          = NULL;
1914     gdiplusStartupInput.SuppressBackgroundThread    = 0;
1915     gdiplusStartupInput.SuppressExternalCodecs      = 0;
1916
1917     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
1918
1919     test_constructor_destructor();
1920     test_save_restore();
1921     test_GdipDrawBezierI();
1922     test_GdipDrawArc();
1923     test_GdipDrawArcI();
1924     test_GdipDrawCurve();
1925     test_GdipDrawCurveI();
1926     test_GdipDrawCurve2();
1927     test_GdipDrawCurve2I();
1928     test_GdipDrawCurve3();
1929     test_GdipDrawCurve3I();
1930     test_GdipDrawLineI();
1931     test_GdipDrawLinesI();
1932     test_GdipDrawString();
1933     test_GdipGetVisibleClipBounds();
1934     test_Get_Release_DC();
1935     test_BeginContainer2();
1936     test_transformpoints();
1937     test_get_set_clip();
1938     test_isempty();
1939     test_clear();
1940     test_textcontrast();
1941
1942     GdiplusShutdown(gdiplusToken);
1943 }