gdiplus: Add tests for GdipDrawString.
[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 HWND hwnd;
32
33 static void test_constructor_destructor(void)
34 {
35     GpStatus stat;
36     GpGraphics *graphics = NULL;
37     HDC hdc = GetDC( hwnd );
38
39     stat = GdipCreateFromHDC(NULL, &graphics);
40     expect(OutOfMemory, stat);
41     stat = GdipDeleteGraphics(graphics);
42     expect(InvalidParameter, stat);
43
44     stat = GdipCreateFromHDC(hdc, &graphics);
45     expect(Ok, stat);
46     stat = GdipDeleteGraphics(graphics);
47     expect(Ok, stat);
48
49     stat = GdipCreateFromHWND(NULL, &graphics);
50     expect(Ok, stat);
51     stat = GdipDeleteGraphics(graphics);
52     expect(Ok, stat);
53
54     stat = GdipCreateFromHWNDICM(NULL, &graphics);
55     expect(Ok, stat);
56     stat = GdipDeleteGraphics(graphics);
57     expect(Ok, stat);
58
59     stat = GdipDeleteGraphics(NULL);
60     expect(InvalidParameter, stat);
61     ReleaseDC(hwnd, hdc);
62 }
63
64 typedef struct node{
65     GraphicsState data;
66     struct node * next;
67 } node;
68
69 /* Linked list prepend function. */
70 static void log_state(GraphicsState data, node ** log)
71 {
72     node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
73
74     new_entry->data = data;
75     new_entry->next = *log;
76     *log = new_entry;
77 }
78
79 /* Checks if there are duplicates in the list, and frees it. */
80 static void check_no_duplicates(node * log)
81 {
82     INT dups = 0;
83     node * temp = NULL;
84     node * temp2 = NULL;
85     node * orig = log;
86
87     if(!log)
88         goto end;
89
90     do{
91         temp = log;
92         while((temp = temp->next)){
93             if(log->data == temp->data){
94                 dups++;
95                 break;
96             }
97             if(dups > 0)
98                 break;
99         }
100     }while((log = log->next));
101
102     temp = orig;
103     do{
104         temp2 = temp->next;
105         HeapFree(GetProcessHeap(), 0, temp);
106         temp = temp2;
107     }while(temp);
108
109 end:
110     expect(0, dups);
111 }
112
113 static void test_save_restore(void)
114 {
115     GpStatus stat;
116     GraphicsState state_a, state_b, state_c;
117     InterpolationMode mode;
118     GpGraphics *graphics1, *graphics2;
119     node * state_log = NULL;
120     HDC hdc = GetDC( hwnd );
121     state_a = state_b = state_c = 0xdeadbeef;
122
123     /* Invalid saving. */
124     GdipCreateFromHDC(hdc, &graphics1);
125     stat = GdipSaveGraphics(graphics1, NULL);
126     expect(InvalidParameter, stat);
127     stat = GdipSaveGraphics(NULL, &state_a);
128     expect(InvalidParameter, stat);
129     GdipDeleteGraphics(graphics1);
130
131     log_state(state_a, &state_log);
132
133     /* Basic save/restore. */
134     GdipCreateFromHDC(hdc, &graphics1);
135     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
136     stat = GdipSaveGraphics(graphics1, &state_a);
137     expect(Ok, stat);
138     GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
139     stat = GdipRestoreGraphics(graphics1, state_a);
140     expect(Ok, stat);
141     GdipGetInterpolationMode(graphics1, &mode);
142     expect(InterpolationModeBilinear, mode);
143     GdipDeleteGraphics(graphics1);
144
145     log_state(state_a, &state_log);
146
147     /* Restoring garbage doesn't affect saves. */
148     GdipCreateFromHDC(hdc, &graphics1);
149     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
150     GdipSaveGraphics(graphics1, &state_a);
151     GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
152     GdipSaveGraphics(graphics1, &state_b);
153     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
154     stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
155     expect(Ok, stat);
156     GdipRestoreGraphics(graphics1, state_b);
157     GdipGetInterpolationMode(graphics1, &mode);
158     expect(InterpolationModeBicubic, mode);
159     GdipRestoreGraphics(graphics1, state_a);
160     GdipGetInterpolationMode(graphics1, &mode);
161     expect(InterpolationModeBilinear, mode);
162     GdipDeleteGraphics(graphics1);
163
164     log_state(state_a, &state_log);
165     log_state(state_b, &state_log);
166
167     /* Restoring older state invalidates newer saves (but not older saves). */
168     GdipCreateFromHDC(hdc, &graphics1);
169     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
170     GdipSaveGraphics(graphics1, &state_a);
171     GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
172     GdipSaveGraphics(graphics1, &state_b);
173     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
174     GdipSaveGraphics(graphics1, &state_c);
175     GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
176     GdipRestoreGraphics(graphics1, state_b);
177     GdipGetInterpolationMode(graphics1, &mode);
178     expect(InterpolationModeBicubic, mode);
179     GdipRestoreGraphics(graphics1, state_c);
180     GdipGetInterpolationMode(graphics1, &mode);
181     expect(InterpolationModeBicubic, mode);
182     GdipRestoreGraphics(graphics1, state_a);
183     GdipGetInterpolationMode(graphics1, &mode);
184     expect(InterpolationModeBilinear, mode);
185     GdipDeleteGraphics(graphics1);
186
187     log_state(state_a, &state_log);
188     log_state(state_b, &state_log);
189     log_state(state_c, &state_log);
190
191     /* Restoring older save from one graphics object does not invalidate
192      * newer save from other graphics object. */
193     GdipCreateFromHDC(hdc, &graphics1);
194     GdipCreateFromHDC(hdc, &graphics2);
195     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
196     GdipSaveGraphics(graphics1, &state_a);
197     GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
198     GdipSaveGraphics(graphics2, &state_b);
199     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
200     GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
201     GdipRestoreGraphics(graphics1, state_a);
202     GdipGetInterpolationMode(graphics1, &mode);
203     expect(InterpolationModeBilinear, mode);
204     GdipRestoreGraphics(graphics2, state_b);
205     GdipGetInterpolationMode(graphics2, &mode);
206     expect(InterpolationModeBicubic, mode);
207     GdipDeleteGraphics(graphics1);
208     GdipDeleteGraphics(graphics2);
209
210     /* You can't restore a state to a graphics object that didn't save it. */
211     GdipCreateFromHDC(hdc, &graphics1);
212     GdipCreateFromHDC(hdc, &graphics2);
213     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
214     GdipSaveGraphics(graphics1, &state_a);
215     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
216     GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
217     GdipRestoreGraphics(graphics2, state_a);
218     GdipGetInterpolationMode(graphics2, &mode);
219     expect(InterpolationModeNearestNeighbor, mode);
220     GdipDeleteGraphics(graphics1);
221     GdipDeleteGraphics(graphics2);
222
223     log_state(state_a, &state_log);
224
225     /* The same state value should never be returned twice. */
226     todo_wine
227         check_no_duplicates(state_log);
228
229     ReleaseDC(hwnd, hdc);
230 }
231
232 static void test_GdipDrawArc(void)
233 {
234     GpStatus status;
235     GpGraphics *graphics = NULL;
236     GpPen *pen = NULL;
237     HDC hdc = GetDC( hwnd );
238
239     /* make a graphics object and pen object */
240     ok(hdc != NULL, "Expected HDC to be initialized\n");
241
242     status = GdipCreateFromHDC(hdc, &graphics);
243     expect(Ok, status);
244     ok(graphics != NULL, "Expected graphics to be initialized\n");
245
246     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
247     expect(Ok, status);
248     ok(pen != NULL, "Expected pen to be initialized\n");
249
250     /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
251     status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
252     expect(InvalidParameter, status);
253
254     status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
255     expect(InvalidParameter, status);
256
257     status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
258     expect(InvalidParameter, status);
259
260     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
261     expect(InvalidParameter, status);
262
263     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
264     expect(InvalidParameter, status);
265
266     /* successful case */
267     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
268     expect(Ok, status);
269
270     GdipDeletePen(pen);
271     GdipDeleteGraphics(graphics);
272
273     ReleaseDC(hwnd, hdc);
274 }
275
276 static void test_GdipDrawArcI(void)
277 {
278     GpStatus status;
279     GpGraphics *graphics = NULL;
280     GpPen *pen = NULL;
281     HDC hdc = GetDC( hwnd );
282
283     /* make a graphics object and pen object */
284     ok(hdc != NULL, "Expected HDC to be initialized\n");
285
286     status = GdipCreateFromHDC(hdc, &graphics);
287     expect(Ok, status);
288     ok(graphics != NULL, "Expected graphics to be initialized\n");
289
290     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
291     expect(Ok, status);
292     ok(pen != NULL, "Expected pen to be initialized\n");
293
294     /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
295     status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
296     expect(InvalidParameter, status);
297
298     status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
299     expect(InvalidParameter, status);
300
301     status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
302     expect(InvalidParameter, status);
303
304     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
305     expect(InvalidParameter, status);
306
307     status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
308     expect(InvalidParameter, status);
309
310     /* successful case */
311     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
312     expect(Ok, status);
313
314     GdipDeletePen(pen);
315     GdipDeleteGraphics(graphics);
316
317     ReleaseDC(hwnd, hdc);
318 }
319
320 static void test_BeginContainer2(void)
321 {
322     GpMatrix *transform;
323     GpRectF clip;
324     REAL defClip[] = {5, 10, 15, 20};
325     REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
326     GraphicsContainer cont1, cont2, cont3, cont4;
327     CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
328     CompositingMode compmode, defCompmode = CompositingModeSourceOver;
329     InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
330     REAL scale, defScale = 17;
331     GpUnit unit, defUnit = UnitPixel;
332     PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
333     SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
334     UINT contrast, defContrast = 5;
335     TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
336
337     GpStatus status;
338     GpGraphics *graphics = NULL;
339     HDC hdc = GetDC( hwnd );
340
341     ok(hdc != NULL, "Expected HDC to be initialized\n");
342
343     status = GdipCreateFromHDC(hdc, &graphics);
344     expect(Ok, status);
345     ok(graphics != NULL, "Expected graphics to be initialized\n");
346
347     /* null graphics, null container */
348     status = GdipBeginContainer2(NULL, &cont1);
349     expect(InvalidParameter, status);
350
351     status = GdipBeginContainer2(graphics, NULL);
352     expect(InvalidParameter, status);
353
354     status = GdipEndContainer(NULL, cont1);
355     expect(InvalidParameter, status);
356
357     /* test all quality-related values */
358     GdipSetCompositingMode(graphics, defCompmode);
359     GdipSetCompositingQuality(graphics, defCompqual);
360     GdipSetInterpolationMode(graphics, defInterp);
361     GdipSetPageScale(graphics, defScale);
362     GdipSetPageUnit(graphics, defUnit);
363     GdipSetPixelOffsetMode(graphics, defOffsetmode);
364     GdipSetSmoothingMode(graphics, defSmoothmode);
365     GdipSetTextContrast(graphics, defContrast);
366     GdipSetTextRenderingHint(graphics, defTexthint);
367
368     status = GdipBeginContainer2(graphics, &cont1);
369     expect(Ok, status);
370
371     GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
372     GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
373     GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
374     GdipSetPageScale(graphics, 10);
375     GdipSetPageUnit(graphics, UnitDocument);
376     GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
377     GdipSetSmoothingMode(graphics, SmoothingModeNone);
378     GdipSetTextContrast(graphics, 7);
379     GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
380
381     status = GdipEndContainer(graphics, cont1);
382     expect(Ok, status);
383
384     GdipGetCompositingMode(graphics, &compmode);
385     ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
386
387     GdipGetCompositingQuality(graphics, &compqual);
388     ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
389
390     GdipGetInterpolationMode(graphics, &interp);
391     ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
392
393     GdipGetPageScale(graphics, &scale);
394     ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
395
396     GdipGetPageUnit(graphics, &unit);
397     ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
398
399     GdipGetPixelOffsetMode(graphics, &offsetmode);
400     ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
401
402     GdipGetSmoothingMode(graphics, &smoothmode);
403     ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
404
405     GdipGetTextContrast(graphics, &contrast);
406     ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
407
408     GdipGetTextRenderingHint(graphics, &texthint);
409     ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
410
411     /* test world transform */
412     status = GdipBeginContainer2(graphics, &cont1);
413     expect(Ok, status);
414
415     GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
416             defTrans[4], defTrans[5], &transform);
417     GdipSetWorldTransform(graphics, transform);
418     GdipDeleteMatrix(transform);
419     transform = NULL;
420
421     status = GdipBeginContainer2(graphics, &cont2);
422     expect(Ok, status);
423
424     GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
425     GdipSetWorldTransform(graphics, transform);
426     GdipDeleteMatrix(transform);
427     transform = NULL;
428
429     status = GdipEndContainer(graphics, cont2);
430     expect(Ok, status);
431
432     GdipCreateMatrix(&transform);
433     GdipGetWorldTransform(graphics, transform);
434     GdipGetMatrixElements(transform, elems);
435     ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
436             fabs(defTrans[1] - elems[1]) < 0.0001 &&
437             fabs(defTrans[2] - elems[2]) < 0.0001 &&
438             fabs(defTrans[3] - elems[3]) < 0.0001 &&
439             fabs(defTrans[4] - elems[4]) < 0.0001 &&
440             fabs(defTrans[5] - elems[5]) < 0.0001,
441             "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
442             defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
443             elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
444     GdipDeleteMatrix(transform);
445     transform = NULL;
446
447     status = GdipEndContainer(graphics, cont1);
448     expect(Ok, status);
449
450     /* test clipping */
451     status = GdipBeginContainer2(graphics, &cont1);
452     expect(Ok, status);
453
454     GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
455
456     status = GdipBeginContainer2(graphics, &cont2);
457     expect(Ok, status);
458
459     GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
460
461     status = GdipEndContainer(graphics, cont2);
462
463     GdipGetClipBounds(graphics, &clip);
464     ok(fabs(defClip[0] - clip.X) < 0.0001 &&
465             fabs(defClip[1] - clip.Y) < 0.0001 &&
466             fabs(defClip[2] - clip.Width) < 0.0001 &&
467             fabs(defClip[3] - clip.Height) < 0.0001,
468             "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
469             defClip[0], defClip[1], defClip[2], defClip[3],
470             clip.X, clip.Y, clip.Width, clip.Height);
471
472     status = GdipEndContainer(graphics, cont1);
473
474     /* nesting */
475     status = GdipBeginContainer2(graphics, &cont1);
476     expect(Ok, status);
477
478     status = GdipBeginContainer2(graphics, &cont2);
479     expect(Ok, status);
480
481     status = GdipBeginContainer2(graphics, &cont3);
482     expect(Ok, status);
483
484     status = GdipEndContainer(graphics, cont3);
485     expect(Ok, status);
486
487     status = GdipBeginContainer2(graphics, &cont4);
488     expect(Ok, status);
489
490     status = GdipEndContainer(graphics, cont4);
491     expect(Ok, status);
492
493     /* skip cont2 */
494     status = GdipEndContainer(graphics, cont1);
495     expect(Ok, status);
496
497     /* end an already-ended container */
498     status = GdipEndContainer(graphics, cont1);
499     expect(Ok, status);
500
501     GdipDeleteGraphics(graphics);
502     ReleaseDC(hwnd, hdc);
503 }
504
505 static void test_GdipDrawBezierI(void)
506 {
507     GpStatus status;
508     GpGraphics *graphics = NULL;
509     GpPen *pen = NULL;
510     HDC hdc = GetDC( hwnd );
511
512     /* make a graphics object and pen object */
513     ok(hdc != NULL, "Expected HDC to be initialized\n");
514
515     status = GdipCreateFromHDC(hdc, &graphics);
516     expect(Ok, status);
517     ok(graphics != NULL, "Expected graphics to be initialized\n");
518
519     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
520     expect(Ok, status);
521     ok(pen != NULL, "Expected pen to be initialized\n");
522
523     /* InvalidParameter cases: null graphics, null pen */
524     status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
525     expect(InvalidParameter, status);
526
527     status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
528     expect(InvalidParameter, status);
529
530     status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
531     expect(InvalidParameter, status);
532
533     /* successful case */
534     status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
535     expect(Ok, status);
536
537     GdipDeletePen(pen);
538     GdipDeleteGraphics(graphics);
539
540     ReleaseDC(hwnd, hdc);
541 }
542
543 static void test_GdipDrawCurve3(void)
544 {
545     GpStatus status;
546     GpGraphics *graphics = NULL;
547     GpPen *pen = NULL;
548     HDC hdc = GetDC( hwnd );
549     GpPointF points[3];
550
551     points[0].X = 0;
552     points[0].Y = 0;
553
554     points[1].X = 40;
555     points[1].Y = 20;
556
557     points[2].X = 10;
558     points[2].Y = 40;
559
560     /* make a graphics object and pen object */
561     ok(hdc != NULL, "Expected HDC to be initialized\n");
562
563     status = GdipCreateFromHDC(hdc, &graphics);
564     expect(Ok, status);
565     ok(graphics != NULL, "Expected graphics to be initialized\n");
566
567     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
568     expect(Ok, status);
569     ok(pen != NULL, "Expected pen to be initialized\n");
570
571     /* InvalidParameter cases: null graphics, null pen */
572     status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
573     expect(InvalidParameter, status);
574
575     status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
576     expect(InvalidParameter, status);
577
578     status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
579     expect(InvalidParameter, status);
580
581     /* InvalidParameter cases: invalid count */
582     status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
583     expect(InvalidParameter, status);
584
585     status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
586     expect(InvalidParameter, status);
587
588     status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
589     expect(InvalidParameter, status);
590
591     status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
592     expect(InvalidParameter, status);
593
594     /* InvalidParameter cases: invalid number of segments */
595     status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
596     expect(InvalidParameter, status);
597
598     status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
599     expect(InvalidParameter, status);
600
601     status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
602     expect(InvalidParameter, status);
603
604     /* Valid test cases */
605     status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
606     expect(Ok, status);
607
608     status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
609     expect(Ok, status);
610
611     status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
612     expect(Ok, status);
613
614     status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
615     expect(Ok, status);
616
617     GdipDeletePen(pen);
618     GdipDeleteGraphics(graphics);
619
620     ReleaseDC(hwnd, hdc);
621 }
622
623 static void test_GdipDrawCurve3I(void)
624 {
625     GpStatus status;
626     GpGraphics *graphics = NULL;
627     GpPen *pen = NULL;
628     HDC hdc = GetDC( hwnd );
629     GpPoint points[3];
630
631     points[0].X = 0;
632     points[0].Y = 0;
633
634     points[1].X = 40;
635     points[1].Y = 20;
636
637     points[2].X = 10;
638     points[2].Y = 40;
639
640     /* make a graphics object and pen object */
641     ok(hdc != NULL, "Expected HDC to be initialized\n");
642
643     status = GdipCreateFromHDC(hdc, &graphics);
644     expect(Ok, status);
645     ok(graphics != NULL, "Expected graphics to be initialized\n");
646
647     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
648     expect(Ok, status);
649     ok(pen != NULL, "Expected pen to be initialized\n");
650
651     /* InvalidParameter cases: null graphics, null pen */
652     status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
653     expect(InvalidParameter, status);
654
655     status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
656     expect(InvalidParameter, status);
657
658     status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
659     expect(InvalidParameter, status);
660
661     /* InvalidParameter cases: invalid count */
662     status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
663     expect(OutOfMemory, status);
664
665     status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
666     expect(InvalidParameter, status);
667
668     status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
669     expect(InvalidParameter, status);
670
671     status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
672     expect(InvalidParameter, status);
673
674     /* InvalidParameter cases: invalid number of segments */
675     status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
676     expect(InvalidParameter, status);
677
678     status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
679     expect(InvalidParameter, status);
680
681     status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
682     expect(InvalidParameter, status);
683
684     /* Valid test cases */
685     status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
686     expect(Ok, status);
687
688     status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
689     expect(Ok, status);
690
691     status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
692     expect(Ok, status);
693
694     status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
695     expect(Ok, status);
696
697     GdipDeletePen(pen);
698     GdipDeleteGraphics(graphics);
699
700     ReleaseDC(hwnd, hdc);
701 }
702
703 static void test_GdipDrawCurve2(void)
704 {
705     GpStatus status;
706     GpGraphics *graphics = NULL;
707     GpPen *pen = NULL;
708     HDC hdc = GetDC( hwnd );
709     GpPointF points[3];
710
711     points[0].X = 0;
712     points[0].Y = 0;
713
714     points[1].X = 40;
715     points[1].Y = 20;
716
717     points[2].X = 10;
718     points[2].Y = 40;
719
720     /* make a graphics object and pen object */
721     ok(hdc != NULL, "Expected HDC to be initialized\n");
722
723     status = GdipCreateFromHDC(hdc, &graphics);
724     expect(Ok, status);
725     ok(graphics != NULL, "Expected graphics to be initialized\n");
726
727     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
728     expect(Ok, status);
729     ok(pen != NULL, "Expected pen to be initialized\n");
730
731     /* InvalidParameter cases: null graphics, null pen */
732     status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
733     expect(InvalidParameter, status);
734
735     status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
736     expect(InvalidParameter, status);
737
738     status = GdipDrawCurve2(NULL, pen, points, 3, 1);
739     expect(InvalidParameter, status);
740
741     /* InvalidParameter cases: invalid count */
742     status = GdipDrawCurve2(graphics, pen, points, -1, 1);
743     expect(InvalidParameter, status);
744
745     status = GdipDrawCurve2(graphics, pen, points, 0, 1);
746     expect(InvalidParameter, status);
747
748     status = GdipDrawCurve2(graphics, pen, points, 1, 1);
749     expect(InvalidParameter, status);
750
751     /* Valid test cases */
752     status = GdipDrawCurve2(graphics, pen, points, 2, 1);
753     expect(Ok, status);
754
755     status = GdipDrawCurve2(graphics, pen, points, 3, 2);
756     expect(Ok, status);
757
758     status = GdipDrawCurve2(graphics, pen, points, 3, -2);
759     expect(Ok, status);
760
761     status = GdipDrawCurve2(graphics, pen, points, 3, 0);
762     expect(Ok, status);
763
764     GdipDeletePen(pen);
765     GdipDeleteGraphics(graphics);
766
767     ReleaseDC(hwnd, hdc);
768 }
769
770 static void test_GdipDrawCurve2I(void)
771 {
772     GpStatus status;
773     GpGraphics *graphics = NULL;
774     GpPen *pen = NULL;
775     HDC hdc = GetDC( hwnd );
776     GpPoint points[3];
777
778     points[0].X = 0;
779     points[0].Y = 0;
780
781     points[1].X = 40;
782     points[1].Y = 20;
783
784     points[2].X = 10;
785     points[2].Y = 40;
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 = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
800     expect(InvalidParameter, status);
801
802     status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
803     expect(InvalidParameter, status);
804
805     status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
806     expect(InvalidParameter, status);
807
808     /* InvalidParameter cases: invalid count */
809     status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
810     expect(OutOfMemory, status);
811
812     status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
813     expect(InvalidParameter, status);
814
815     status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
816     expect(InvalidParameter, status);
817
818     /* Valid test cases */
819     status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
820     expect(Ok, status);
821
822     status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
823     expect(Ok, status);
824
825     status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
826     expect(Ok, status);
827
828     status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
829     expect(Ok, status);
830
831     GdipDeletePen(pen);
832     GdipDeleteGraphics(graphics);
833
834     ReleaseDC(hwnd, hdc);
835 }
836
837 static void test_GdipDrawCurve(void)
838 {
839     GpStatus status;
840     GpGraphics *graphics = NULL;
841     GpPen *pen = NULL;
842     HDC hdc = GetDC( hwnd );
843     GpPointF points[3];
844
845     points[0].X = 0;
846     points[0].Y = 0;
847
848     points[1].X = 40;
849     points[1].Y = 20;
850
851     points[2].X = 10;
852     points[2].Y = 40;
853
854     /* make a graphics object and pen object */
855     ok(hdc != NULL, "Expected HDC to be initialized\n");
856
857     status = GdipCreateFromHDC(hdc, &graphics);
858     expect(Ok, status);
859     ok(graphics != NULL, "Expected graphics to be initialized\n");
860
861     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
862     expect(Ok, status);
863     ok(pen != NULL, "Expected pen to be initialized\n");
864
865     /* InvalidParameter cases: null graphics, null pen */
866     status = GdipDrawCurve(NULL, NULL, points, 3);
867     expect(InvalidParameter, status);
868
869     status = GdipDrawCurve(graphics, NULL, points, 3);
870     expect(InvalidParameter, status);
871
872     status = GdipDrawCurve(NULL, pen, points, 3);
873     expect(InvalidParameter, status);
874
875     /* InvalidParameter cases: invalid count */
876     status = GdipDrawCurve(graphics, pen, points, -1);
877     expect(InvalidParameter, status);
878
879     status = GdipDrawCurve(graphics, pen, points, 0);
880     expect(InvalidParameter, status);
881
882     status = GdipDrawCurve(graphics, pen, points, 1);
883     expect(InvalidParameter, status);
884
885     /* Valid test cases */
886     status = GdipDrawCurve(graphics, pen, points, 2);
887     expect(Ok, status);
888
889     status = GdipDrawCurve(graphics, pen, points, 3);
890     expect(Ok, status);
891
892     GdipDeletePen(pen);
893     GdipDeleteGraphics(graphics);
894
895     ReleaseDC(hwnd, hdc);
896 }
897
898 static void test_GdipDrawCurveI(void)
899 {
900     GpStatus status;
901     GpGraphics *graphics = NULL;
902     GpPen *pen = NULL;
903     HDC hdc = GetDC( hwnd );
904     GpPoint points[3];
905
906     points[0].X = 0;
907     points[0].Y = 0;
908
909     points[1].X = 40;
910     points[1].Y = 20;
911
912     points[2].X = 10;
913     points[2].Y = 40;
914
915     /* make a graphics object and pen object */
916     ok(hdc != NULL, "Expected HDC to be initialized\n");
917
918     status = GdipCreateFromHDC(hdc, &graphics);
919     expect(Ok, status);
920     ok(graphics != NULL, "Expected graphics to be initialized\n");
921
922     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
923     expect(Ok, status);
924     ok(pen != NULL, "Expected pen to be initialized\n");
925
926     /* InvalidParameter cases: null graphics, null pen */
927     status = GdipDrawCurveI(NULL, NULL, points, 3);
928     expect(InvalidParameter, status);
929
930     status = GdipDrawCurveI(graphics, NULL, points, 3);
931     expect(InvalidParameter, status);
932
933     status = GdipDrawCurveI(NULL, pen, points, 3);
934     expect(InvalidParameter, status);
935
936     /* InvalidParameter cases: invalid count */
937     status = GdipDrawCurveI(graphics, pen, points, -1);
938     expect(OutOfMemory, status);
939
940     status = GdipDrawCurveI(graphics, pen, points, 0);
941     expect(InvalidParameter, status);
942
943     status = GdipDrawCurveI(graphics, pen, points, 1);
944     expect(InvalidParameter, status);
945
946     /* Valid test cases */
947     status = GdipDrawCurveI(graphics, pen, points, 2);
948     expect(Ok, status);
949
950     status = GdipDrawCurveI(graphics, pen, points, 3);
951     expect(Ok, status);
952
953     GdipDeletePen(pen);
954     GdipDeleteGraphics(graphics);
955
956     ReleaseDC(hwnd, hdc);
957 }
958
959 static void test_GdipDrawLineI(void)
960 {
961     GpStatus status;
962     GpGraphics *graphics = NULL;
963     GpPen *pen = NULL;
964     HDC hdc = GetDC( hwnd );
965
966     /* make a graphics object and pen object */
967     ok(hdc != NULL, "Expected HDC to be initialized\n");
968
969     status = GdipCreateFromHDC(hdc, &graphics);
970     expect(Ok, status);
971     ok(graphics != NULL, "Expected graphics to be initialized\n");
972
973     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
974     expect(Ok, status);
975     ok(pen != NULL, "Expected pen to be initialized\n");
976
977     /* InvalidParameter cases: null graphics, null pen */
978     status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
979     expect(InvalidParameter, status);
980
981     status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
982     expect(InvalidParameter, status);
983
984     status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
985     expect(InvalidParameter, status);
986
987     /* successful case */
988     status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
989     expect(Ok, status);
990
991     GdipDeletePen(pen);
992     GdipDeleteGraphics(graphics);
993
994     ReleaseDC(hwnd, hdc);
995 }
996
997 static void test_GdipDrawLinesI(void)
998 {
999     GpStatus status;
1000     GpGraphics *graphics = NULL;
1001     GpPen *pen = NULL;
1002     GpPoint *ptf = NULL;
1003     HDC hdc = GetDC( hwnd );
1004
1005     /* make a graphics object and pen object */
1006     ok(hdc != NULL, "Expected HDC to be initialized\n");
1007
1008     status = GdipCreateFromHDC(hdc, &graphics);
1009     expect(Ok, status);
1010     ok(graphics != NULL, "Expected graphics to be initialized\n");
1011
1012     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1013     expect(Ok, status);
1014     ok(pen != NULL, "Expected pen to be initialized\n");
1015
1016     /* make some arbitrary valid points*/
1017     ptf = GdipAlloc(2 * sizeof(GpPointF));
1018
1019     ptf[0].X = 1;
1020     ptf[0].Y = 1;
1021
1022     ptf[1].X = 2;
1023     ptf[1].Y = 2;
1024
1025     /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1026     status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1027     expect(InvalidParameter, status);
1028
1029     status = GdipDrawLinesI(graphics, pen, ptf, 0);
1030     expect(InvalidParameter, status);
1031
1032     status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1033     expect(InvalidParameter, status);
1034
1035     status = GdipDrawLinesI(NULL, pen, ptf, 2);
1036     expect(InvalidParameter, status);
1037
1038     /* successful case */
1039     status = GdipDrawLinesI(graphics, pen, ptf, 2);
1040     expect(Ok, status);
1041
1042     GdipFree(ptf);
1043     GdipDeletePen(pen);
1044     GdipDeleteGraphics(graphics);
1045
1046     ReleaseDC(hwnd, hdc);
1047 }
1048
1049 static void test_Get_Release_DC(void)
1050 {
1051     GpStatus status;
1052     GpGraphics *graphics = NULL;
1053     GpPen *pen;
1054     GpSolidFill *brush;
1055     GpPath *path;
1056     HDC hdc = GetDC( hwnd );
1057     HDC retdc;
1058     REAL r;
1059     CompositingQuality quality;
1060     CompositingMode compmode;
1061     InterpolationMode intmode;
1062     GpMatrix *m;
1063     GpRegion *region;
1064     GpUnit unit;
1065     PixelOffsetMode offsetmode;
1066     SmoothingMode smoothmode;
1067     TextRenderingHint texthint;
1068     GpPointF ptf[5];
1069     GpPoint  pt[5];
1070     GpRectF  rectf[2];
1071     GpRect   rect[2];
1072     GpRegion *clip;
1073     INT i;
1074     BOOL res;
1075     ARGB color = 0x00000000;
1076     HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1077
1078     pt[0].X = 10;
1079     pt[0].Y = 10;
1080     pt[1].X = 20;
1081     pt[1].Y = 15;
1082     pt[2].X = 40;
1083     pt[2].Y = 80;
1084     pt[3].X = -20;
1085     pt[3].Y = 20;
1086     pt[4].X = 50;
1087     pt[4].Y = 110;
1088
1089     for(i = 0; i < 5;i++){
1090         ptf[i].X = (REAL)pt[i].X;
1091         ptf[i].Y = (REAL)pt[i].Y;
1092     }
1093
1094     rect[0].X = 0;
1095     rect[0].Y = 0;
1096     rect[0].Width  = 50;
1097     rect[0].Height = 70;
1098     rect[1].X = 0;
1099     rect[1].Y = 0;
1100     rect[1].Width  = 10;
1101     rect[1].Height = 20;
1102
1103     for(i = 0; i < 2;i++){
1104         rectf[i].X = (REAL)rect[i].X;
1105         rectf[i].Y = (REAL)rect[i].Y;
1106         rectf[i].Height = (REAL)rect[i].Height;
1107         rectf[i].Width  = (REAL)rect[i].Width;
1108     }
1109
1110     GdipCreateMatrix(&m);
1111     GdipCreateRegion(&region);
1112     GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1113     GdipCreatePath(FillModeAlternate, &path);
1114     GdipCreateRegion(&clip);
1115
1116     status = GdipCreateFromHDC(hdc, &graphics);
1117     expect(Ok, status);
1118     ok(graphics != NULL, "Expected graphics to be initialized\n");
1119     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1120     expect(Ok, status);
1121
1122     /* NULL arguments */
1123     status = GdipGetDC(NULL, NULL);
1124     expect(InvalidParameter, status);
1125     status = GdipGetDC(graphics, NULL);
1126     expect(InvalidParameter, status);
1127     status = GdipGetDC(NULL, &retdc);
1128     expect(InvalidParameter, status);
1129
1130     status = GdipReleaseDC(NULL, NULL);
1131     expect(InvalidParameter, status);
1132     status = GdipReleaseDC(graphics, NULL);
1133     expect(InvalidParameter, status);
1134     status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1135     expect(InvalidParameter, status);
1136
1137     /* Release without Get */
1138     status = GdipReleaseDC(graphics, hdc);
1139     expect(InvalidParameter, status);
1140
1141     retdc = NULL;
1142     status = GdipGetDC(graphics, &retdc);
1143     expect(Ok, status);
1144     ok(retdc == hdc, "Invalid HDC returned\n");
1145     /* call it once more */
1146     status = GdipGetDC(graphics, &retdc);
1147     expect(ObjectBusy, status);
1148
1149     /* try all Graphics calls here */
1150     status = Ok;
1151     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1152     expect(ObjectBusy, status); status = Ok;
1153     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1154     expect(ObjectBusy, status); status = Ok;
1155     status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1156     expect(ObjectBusy, status); status = Ok;
1157     status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1158     expect(ObjectBusy, status); status = Ok;
1159     status = GdipDrawBeziers(graphics, pen, ptf, 5);
1160     expect(ObjectBusy, status); status = Ok;
1161     status = GdipDrawBeziersI(graphics, pen, pt, 5);
1162     expect(ObjectBusy, status); status = Ok;
1163     status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1164     expect(ObjectBusy, status); status = Ok;
1165     status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1166     expect(ObjectBusy, status); status = Ok;
1167     status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1168     expect(ObjectBusy, status); status = Ok;
1169     status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1170     expect(ObjectBusy, status); status = Ok;
1171     status = GdipDrawCurve(graphics, pen, ptf, 5);
1172     expect(ObjectBusy, status); status = Ok;
1173     status = GdipDrawCurveI(graphics, pen, pt, 5);
1174     expect(ObjectBusy, status); status = Ok;
1175     status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1176     expect(ObjectBusy, status); status = Ok;
1177     status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1178     expect(ObjectBusy, status); status = Ok;
1179     status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1180     expect(ObjectBusy, status); status = Ok;
1181     status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1182     expect(ObjectBusy, status); status = Ok;
1183     /* GdipDrawImage/GdipDrawImageI */
1184     /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1185     /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1186     /* GdipDrawImageRect/GdipDrawImageRectI */
1187     status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1188     expect(ObjectBusy, status); status = Ok;
1189     status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1190     expect(ObjectBusy, status); status = Ok;
1191     status = GdipDrawLines(graphics, pen, ptf, 5);
1192     expect(ObjectBusy, status); status = Ok;
1193     status = GdipDrawLinesI(graphics, pen, pt, 5);
1194     expect(ObjectBusy, status); status = Ok;
1195     status = GdipDrawPath(graphics, pen, path);
1196     expect(ObjectBusy, status); status = Ok;
1197     status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1198     expect(ObjectBusy, status); status = Ok;
1199     status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1200     expect(ObjectBusy, status); status = Ok;
1201     status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1202     expect(ObjectBusy, status); status = Ok;
1203     status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1204     expect(ObjectBusy, status); status = Ok;
1205     status = GdipDrawRectangles(graphics, pen, rectf, 2);
1206     expect(ObjectBusy, status); status = Ok;
1207     status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1208     expect(ObjectBusy, status); status = Ok;
1209     /* GdipDrawString */
1210     status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1211     expect(ObjectBusy, status); status = Ok;
1212     status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1213     expect(ObjectBusy, status); status = Ok;
1214     status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1215     expect(ObjectBusy, status); status = Ok;
1216     status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1217     expect(ObjectBusy, status); status = Ok;
1218     status = GdipFillPath(graphics, (GpBrush*)brush, path);
1219     expect(ObjectBusy, status); status = Ok;
1220     status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1221     expect(ObjectBusy, status); status = Ok;
1222     status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1223     expect(ObjectBusy, status); status = Ok;
1224     status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1225     expect(ObjectBusy, status); status = Ok;
1226     status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1227     expect(ObjectBusy, status); status = Ok;
1228     status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1229     expect(ObjectBusy, status); status = Ok;
1230     status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1231     expect(ObjectBusy, status); status = Ok;
1232     status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1233     expect(ObjectBusy, status); status = Ok;
1234     status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1235     expect(ObjectBusy, status); status = Ok;
1236     status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1237     expect(ObjectBusy, status); status = Ok;
1238     status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1239     expect(ObjectBusy, status); status = Ok;
1240     status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1241     expect(ObjectBusy, status); status = Ok;
1242     status = GdipFlush(graphics, FlushIntentionFlush);
1243     expect(ObjectBusy, status); status = Ok;
1244     status = GdipGetClipBounds(graphics, rectf);
1245     expect(ObjectBusy, status); status = Ok;
1246     status = GdipGetClipBoundsI(graphics, rect);
1247     expect(ObjectBusy, status); status = Ok;
1248     status = GdipGetCompositingMode(graphics, &compmode);
1249     expect(ObjectBusy, status); status = Ok;
1250     status = GdipGetCompositingQuality(graphics, &quality);
1251     expect(ObjectBusy, status); status = Ok;
1252     status = GdipGetInterpolationMode(graphics, &intmode);
1253     expect(ObjectBusy, status); status = Ok;
1254     status = GdipGetNearestColor(graphics, &color);
1255     expect(ObjectBusy, status); status = Ok;
1256     status = GdipGetPageScale(graphics, &r);
1257     expect(ObjectBusy, status); status = Ok;
1258     status = GdipGetPageUnit(graphics, &unit);
1259     expect(ObjectBusy, status); status = Ok;
1260     status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1261     expect(ObjectBusy, status); status = Ok;
1262     status = GdipGetSmoothingMode(graphics, &smoothmode);
1263     expect(ObjectBusy, status); status = Ok;
1264     status = GdipGetTextRenderingHint(graphics, &texthint);
1265     expect(ObjectBusy, status); status = Ok;
1266     status = GdipGetWorldTransform(graphics, m);
1267     expect(ObjectBusy, status); status = Ok;
1268     status = GdipGraphicsClear(graphics, 0xdeadbeef);
1269     expect(ObjectBusy, status); status = Ok;
1270     status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1271     expect(ObjectBusy, status); status = Ok;
1272     status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1273     expect(ObjectBusy, status); status = Ok;
1274     /* GdipMeasureCharacterRanges */
1275     /* GdipMeasureString */
1276     status = GdipResetClip(graphics);
1277     expect(ObjectBusy, status); status = Ok;
1278     status = GdipResetWorldTransform(graphics);
1279     expect(ObjectBusy, status); status = Ok;
1280     /* GdipRestoreGraphics */
1281     status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1282     expect(ObjectBusy, status); status = Ok;
1283     /*  GdipSaveGraphics */
1284     status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1285     expect(ObjectBusy, status); status = Ok;
1286     status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1287     expect(ObjectBusy, status); status = Ok;
1288     status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1289     expect(ObjectBusy, status); status = Ok;
1290     status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1291     expect(ObjectBusy, status); status = Ok;
1292     status = GdipSetPageScale(graphics, 1.0);
1293     expect(ObjectBusy, status); status = Ok;
1294     status = GdipSetPageUnit(graphics, UnitWorld);
1295     expect(ObjectBusy, status); status = Ok;
1296     status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1297     expect(ObjectBusy, status); status = Ok;
1298     status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1299     expect(ObjectBusy, status); status = Ok;
1300     status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1301     expect(ObjectBusy, status); status = Ok;
1302     status = GdipSetWorldTransform(graphics, m);
1303     expect(ObjectBusy, status); status = Ok;
1304     status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1305     expect(ObjectBusy, status); status = Ok;
1306     status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1307     expect(ObjectBusy, status); status = Ok;
1308     status = GdipSetClipPath(graphics, path, CombineModeReplace);
1309     expect(ObjectBusy, status); status = Ok;
1310     status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1311     expect(ObjectBusy, status); status = Ok;
1312     status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1313     expect(ObjectBusy, status); status = Ok;
1314     status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1315     expect(ObjectBusy, status); status = Ok;
1316     status = GdipTranslateClip(graphics, 0.0, 0.0);
1317     expect(ObjectBusy, status); status = Ok;
1318     status = GdipTranslateClipI(graphics, 0, 0);
1319     expect(ObjectBusy, status); status = Ok;
1320     status = GdipDrawPolygon(graphics, pen, ptf, 5);
1321     expect(ObjectBusy, status); status = Ok;
1322     status = GdipDrawPolygonI(graphics, pen, pt, 5);
1323     expect(ObjectBusy, status); status = Ok;
1324     status = GdipGetDpiX(graphics, &r);
1325     expect(ObjectBusy, status); status = Ok;
1326     status = GdipGetDpiY(graphics, &r);
1327     expect(ObjectBusy, status); status = Ok;
1328     status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1329     status = GdipGetClip(graphics, region);
1330     expect(ObjectBusy, status); status = Ok;
1331     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1332     expect(ObjectBusy, status); status = Ok;
1333     /* try to delete before release */
1334     status = GdipDeleteGraphics(graphics);
1335     expect(ObjectBusy, status);
1336
1337     status = GdipReleaseDC(graphics, retdc);
1338     expect(Ok, status);
1339
1340     GdipDeletePen(pen);
1341     GdipDeleteGraphics(graphics);
1342
1343     GdipDeleteRegion(clip);
1344     GdipDeletePath(path);
1345     GdipDeleteBrush((GpBrush*)brush);
1346     GdipDeleteRegion(region);
1347     GdipDeleteMatrix(m);
1348     DeleteObject(hrgn);
1349
1350     ReleaseDC(hwnd, hdc);
1351 }
1352
1353 static void test_transformpoints(void)
1354 {
1355     GpStatus status;
1356     GpGraphics *graphics = NULL;
1357     HDC hdc = GetDC( hwnd );
1358     GpPointF ptf[2];
1359     GpPoint pt[2];
1360
1361     status = GdipCreateFromHDC(hdc, &graphics);
1362     expect(Ok, status);
1363
1364     /* NULL arguments */
1365     status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1366     expect(InvalidParameter, status);
1367     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1368     expect(InvalidParameter, status);
1369     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1370     expect(InvalidParameter, status);
1371     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1372     expect(InvalidParameter, status);
1373
1374     ptf[0].X = 1.0;
1375     ptf[0].Y = 0.0;
1376     ptf[1].X = 0.0;
1377     ptf[1].Y = 1.0;
1378     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1379     expect(Ok, status);
1380     expectf(1.0, ptf[0].X);
1381     expectf(0.0, ptf[0].Y);
1382     expectf(0.0, ptf[1].X);
1383     expectf(1.0, ptf[1].Y);
1384
1385     status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1386     expect(Ok, status);
1387     status = GdipSetPageUnit(graphics, UnitPixel);
1388     expect(Ok, status);
1389     status = GdipSetPageScale(graphics, 3.0);
1390     expect(Ok, status);
1391
1392     ptf[0].X = 1.0;
1393     ptf[0].Y = 0.0;
1394     ptf[1].X = 0.0;
1395     ptf[1].Y = 1.0;
1396     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1397     expect(Ok, status);
1398     expectf(18.0, ptf[0].X);
1399     expectf(15.0, ptf[0].Y);
1400     expectf(15.0, ptf[1].X);
1401     expectf(18.0, ptf[1].Y);
1402
1403     ptf[0].X = 1.0;
1404     ptf[0].Y = 0.0;
1405     ptf[1].X = 0.0;
1406     ptf[1].Y = 1.0;
1407     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1408     expect(Ok, status);
1409     expectf(6.0, ptf[0].X);
1410     expectf(5.0, ptf[0].Y);
1411     expectf(5.0, ptf[1].X);
1412     expectf(6.0, ptf[1].Y);
1413
1414     ptf[0].X = 1.0;
1415     ptf[0].Y = 0.0;
1416     ptf[1].X = 0.0;
1417     ptf[1].Y = 1.0;
1418     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1419     expect(Ok, status);
1420     expectf(3.0, ptf[0].X);
1421     expectf(0.0, ptf[0].Y);
1422     expectf(0.0, ptf[1].X);
1423     expectf(3.0, ptf[1].Y);
1424
1425     ptf[0].X = 18.0;
1426     ptf[0].Y = 15.0;
1427     ptf[1].X = 15.0;
1428     ptf[1].Y = 18.0;
1429     status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1430     expect(Ok, status);
1431     expectf(1.0, ptf[0].X);
1432     expectf(0.0, ptf[0].Y);
1433     expectf(0.0, ptf[1].X);
1434     expectf(1.0, ptf[1].Y);
1435
1436     ptf[0].X = 6.0;
1437     ptf[0].Y = 5.0;
1438     ptf[1].X = 5.0;
1439     ptf[1].Y = 6.0;
1440     status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1441     expect(Ok, status);
1442     expectf(1.0, ptf[0].X);
1443     expectf(0.0, ptf[0].Y);
1444     expectf(0.0, ptf[1].X);
1445     expectf(1.0, ptf[1].Y);
1446
1447     ptf[0].X = 3.0;
1448     ptf[0].Y = 0.0;
1449     ptf[1].X = 0.0;
1450     ptf[1].Y = 3.0;
1451     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1452     expect(Ok, status);
1453     expectf(1.0, ptf[0].X);
1454     expectf(0.0, ptf[0].Y);
1455     expectf(0.0, ptf[1].X);
1456     expectf(1.0, ptf[1].Y);
1457
1458     pt[0].X = 1;
1459     pt[0].Y = 0;
1460     pt[1].X = 0;
1461     pt[1].Y = 1;
1462     status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1463     expect(Ok, status);
1464     expect(18, pt[0].X);
1465     expect(15, pt[0].Y);
1466     expect(15, pt[1].X);
1467     expect(18, pt[1].Y);
1468
1469     GdipDeleteGraphics(graphics);
1470     ReleaseDC(hwnd, hdc);
1471 }
1472
1473 static void test_get_set_clip(void)
1474 {
1475     GpStatus status;
1476     GpGraphics *graphics = NULL;
1477     HDC hdc = GetDC( hwnd );
1478     GpRegion *clip;
1479     GpRectF rect;
1480     BOOL res;
1481
1482     status = GdipCreateFromHDC(hdc, &graphics);
1483     expect(Ok, status);
1484
1485     rect.X = rect.Y = 0.0;
1486     rect.Height = rect.Width = 100.0;
1487
1488     status = GdipCreateRegionRect(&rect, &clip);
1489
1490     /* NULL arguments */
1491     status = GdipGetClip(NULL, NULL);
1492     expect(InvalidParameter, status);
1493     status = GdipGetClip(graphics, NULL);
1494     expect(InvalidParameter, status);
1495     status = GdipGetClip(NULL, clip);
1496     expect(InvalidParameter, status);
1497
1498     status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1499     expect(InvalidParameter, status);
1500     status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1501     expect(InvalidParameter, status);
1502
1503     status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
1504     expect(InvalidParameter, status);
1505     status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
1506     expect(InvalidParameter, status);
1507
1508     res = FALSE;
1509     status = GdipGetClip(graphics, clip);
1510     expect(Ok, status);
1511     status = GdipIsInfiniteRegion(clip, graphics, &res);
1512     expect(Ok, status);
1513     expect(TRUE, res);
1514
1515     /* remains infinite after reset */
1516     res = FALSE;
1517     status = GdipResetClip(graphics);
1518     expect(Ok, status);
1519     status = GdipGetClip(graphics, clip);
1520     expect(Ok, status);
1521     status = GdipIsInfiniteRegion(clip, graphics, &res);
1522     expect(Ok, status);
1523     expect(TRUE, res);
1524
1525     /* set to empty and then reset to infinite */
1526     status = GdipSetEmpty(clip);
1527     expect(Ok, status);
1528     status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1529     expect(Ok, status);
1530
1531     status = GdipGetClip(graphics, clip);
1532     expect(Ok, status);
1533     res = FALSE;
1534     status = GdipIsEmptyRegion(clip, graphics, &res);
1535     expect(Ok, status);
1536     expect(TRUE, res);
1537     status = GdipResetClip(graphics);
1538     expect(Ok, status);
1539     status = GdipGetClip(graphics, clip);
1540     expect(Ok, status);
1541     res = FALSE;
1542     status = GdipIsInfiniteRegion(clip, graphics, &res);
1543     expect(Ok, status);
1544     expect(TRUE, res);
1545
1546     GdipDeleteRegion(clip);
1547
1548     GdipDeleteGraphics(graphics);
1549     ReleaseDC(hwnd, hdc);
1550 }
1551
1552 static void test_isempty(void)
1553 {
1554     GpStatus status;
1555     GpGraphics *graphics = NULL;
1556     HDC hdc = GetDC( hwnd );
1557     GpRegion *clip;
1558     BOOL res;
1559
1560     status = GdipCreateFromHDC(hdc, &graphics);
1561     expect(Ok, status);
1562
1563     status = GdipCreateRegion(&clip);
1564     expect(Ok, status);
1565
1566     /* NULL */
1567     status = GdipIsClipEmpty(NULL, NULL);
1568     expect(InvalidParameter, status);
1569     status = GdipIsClipEmpty(graphics, NULL);
1570     expect(InvalidParameter, status);
1571     status = GdipIsClipEmpty(NULL, &res);
1572     expect(InvalidParameter, status);
1573
1574     /* default is infinite */
1575     res = TRUE;
1576     status = GdipIsClipEmpty(graphics, &res);
1577     expect(Ok, status);
1578     expect(FALSE, res);
1579
1580     GdipDeleteRegion(clip);
1581
1582     GdipDeleteGraphics(graphics);
1583     ReleaseDC(hwnd, hdc);
1584 }
1585
1586 static void test_clear(void)
1587 {
1588     GpStatus status;
1589
1590     status = GdipGraphicsClear(NULL, 0xdeadbeef);
1591     expect(InvalidParameter, status);
1592 }
1593
1594 static void test_textcontrast(void)
1595 {
1596     GpStatus status;
1597     HDC hdc = GetDC( hwnd );
1598     GpGraphics *graphics;
1599     UINT contrast;
1600
1601     status = GdipGetTextContrast(NULL, NULL);
1602     expect(InvalidParameter, status);
1603
1604     status = GdipCreateFromHDC(hdc, &graphics);
1605     expect(Ok, status);
1606
1607     status = GdipGetTextContrast(graphics, NULL);
1608     expect(InvalidParameter, status);
1609     status = GdipGetTextContrast(graphics, &contrast);
1610     expect(4, contrast);
1611
1612     GdipDeleteGraphics(graphics);
1613     ReleaseDC(hwnd, hdc);
1614 }
1615
1616 static void test_GdipDrawString(void)
1617 {
1618     GpStatus status;
1619     GpGraphics *graphics = NULL;
1620     GpFont *fnt = NULL;
1621     RectF  rect;
1622     GpStringFormat *format;
1623     GpBrush *brush;
1624     LOGFONTA logfont;
1625     HDC hdc = GetDC( hwnd );
1626     static const WCHAR string[] = {'T','e','s','t',0};
1627
1628     memset(&logfont,0,sizeof(logfont));
1629     strcpy(logfont.lfFaceName,"Arial");
1630     logfont.lfHeight = 12;
1631     logfont.lfCharSet = DEFAULT_CHARSET;
1632
1633     status = GdipCreateFromHDC(hdc, &graphics);
1634     expect(Ok, status);
1635
1636     status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
1637     if (status == FileNotFound)
1638     {
1639         skip("Arial not installed.\n");
1640         return;
1641     }
1642     expect(Ok, status);
1643
1644     status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
1645     expect(Ok, status);
1646
1647     status = GdipCreateStringFormat(0,0,&format);
1648     expect(Ok, status);
1649
1650     rect.X = 0;
1651     rect.Y = 0;
1652     rect.Width = 0;
1653     rect.Height = 12;
1654
1655     status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
1656     expect(Ok, status);
1657
1658     GdipDeleteGraphics(graphics);
1659     GdipDeleteBrush(brush);
1660     GdipDeleteFont(fnt);
1661     GdipDeleteStringFormat(format);
1662
1663     ReleaseDC(hwnd, hdc);
1664 }
1665
1666 static void test_GdipGetVisibleClipBounds_screen(void)
1667 {
1668     GpStatus status;
1669     GpGraphics *graphics = NULL;
1670     HDC hdc = GetDC(0);
1671     GpRectF rectf, exp, clipr;
1672     GpRect recti;
1673
1674     ok(hdc != NULL, "Expected HDC to be initialized\n");
1675
1676     status = GdipCreateFromHDC(hdc, &graphics);
1677     expect(Ok, status);
1678     ok(graphics != NULL, "Expected graphics to be initialized\n");
1679
1680     /* no clipping rect */
1681     exp.X = 0;
1682     exp.Y = 0;
1683     exp.Width = GetDeviceCaps(hdc, HORZRES);
1684     exp.Height = GetDeviceCaps(hdc, VERTRES);
1685
1686     status = GdipGetVisibleClipBounds(graphics, &rectf);
1687     expect(Ok, status);
1688     ok(rectf.X == exp.X &&
1689         rectf.Y == exp.Y &&
1690         rectf.Width == exp.Width &&
1691         rectf.Height == exp.Height,
1692         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1693         "the screen (%0.f, %0.f, %0.f, %0.f)\n",
1694         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1695         exp.X, exp.Y, exp.Width, exp.Height);
1696
1697     /* clipping rect entirely within window */
1698     exp.X = clipr.X = 10;
1699     exp.Y = clipr.Y = 12;
1700     exp.Width = clipr.Width = 14;
1701     exp.Height = clipr.Height = 16;
1702
1703     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1704     expect(Ok, status);
1705
1706     status = GdipGetVisibleClipBounds(graphics, &rectf);
1707     expect(Ok, status);
1708     ok(rectf.X == exp.X &&
1709         rectf.Y == exp.Y &&
1710         rectf.Width == exp.Width &&
1711         rectf.Height == exp.Height,
1712         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1713         "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1714         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1715         exp.X, exp.Y, exp.Width, exp.Height);
1716
1717     /* clipping rect partially outside of screen */
1718     clipr.X = -10;
1719     clipr.Y = -12;
1720     clipr.Width = 20;
1721     clipr.Height = 24;
1722
1723     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1724     expect(Ok, status);
1725
1726     exp.X = 0;
1727     exp.Y = 0;
1728     exp.Width = 10;
1729     exp.Height = 12;
1730
1731     status = GdipGetVisibleClipBounds(graphics, &rectf);
1732     expect(Ok, status);
1733     ok(rectf.X == exp.X &&
1734         rectf.Y == exp.Y &&
1735         rectf.Width == exp.Width &&
1736         rectf.Height == exp.Height,
1737         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1738         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1739         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1740         exp.X, exp.Y, exp.Width, exp.Height);
1741
1742     status = GdipGetVisibleClipBoundsI(graphics, &recti);
1743     expect(Ok, status);
1744     ok(recti.X == exp.X &&
1745         recti.Y == exp.Y &&
1746         recti.Width == exp.Width &&
1747         recti.Height == exp.Height,
1748         "Expected clip bounds (%d, %d, %d, %d) to be the size of "
1749         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1750         recti.X, recti.Y, recti.Width, recti.Height,
1751         exp.X, exp.Y, exp.Width, exp.Height);
1752
1753     GdipDeleteGraphics(graphics);
1754     ReleaseDC(0, hdc);
1755 }
1756
1757 static void test_GdipGetVisibleClipBounds_window(void)
1758 {
1759     GpStatus status;
1760     GpGraphics *graphics = NULL;
1761     GpRectF rectf, window, exp, clipr;
1762     GpRect recti;
1763     HDC hdc;
1764     PAINTSTRUCT ps;
1765     RECT wnd_rect;
1766
1767     /* get client area size */
1768     ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
1769     window.X = wnd_rect.left;
1770     window.Y = wnd_rect.top;
1771     window.Width = wnd_rect.right - wnd_rect.left;
1772     window.Height = wnd_rect.bottom - wnd_rect.top;
1773
1774     hdc = BeginPaint(hwnd, &ps);
1775
1776     status = GdipCreateFromHDC(hdc, &graphics);
1777     expect(Ok, status);
1778     ok(graphics != NULL, "Expected graphics to be initialized\n");
1779
1780     status = GdipGetVisibleClipBounds(graphics, &rectf);
1781     expect(Ok, status);
1782     ok(rectf.X == window.X &&
1783         rectf.Y == window.Y &&
1784         rectf.Width == window.Width &&
1785         rectf.Height == window.Height,
1786         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1787         "the window (%0.f, %0.f, %0.f, %0.f)\n",
1788         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1789         window.X, window.Y, window.Width, window.Height);
1790
1791     /* clipping rect entirely within window */
1792     exp.X = clipr.X = 20;
1793     exp.Y = clipr.Y = 8;
1794     exp.Width = clipr.Width = 30;
1795     exp.Height = clipr.Height = 20;
1796
1797     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1798     expect(Ok, status);
1799
1800     status = GdipGetVisibleClipBounds(graphics, &rectf);
1801     expect(Ok, status);
1802     ok(rectf.X == exp.X &&
1803         rectf.Y == exp.Y &&
1804         rectf.Width == exp.Width &&
1805         rectf.Height == exp.Height,
1806         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1807         "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1808         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1809         exp.X, exp.Y, exp.Width, exp.Height);
1810
1811     /* clipping rect partially outside of window */
1812     clipr.X = window.Width - 10;
1813     clipr.Y = window.Height - 15;
1814     clipr.Width = 20;
1815     clipr.Height = 30;
1816
1817     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1818     expect(Ok, status);
1819
1820     exp.X = window.Width - 10;
1821     exp.Y = window.Height - 15;
1822     exp.Width = 10;
1823     exp.Height = 15;
1824
1825     status = GdipGetVisibleClipBounds(graphics, &rectf);
1826     expect(Ok, status);
1827     ok(rectf.X == exp.X &&
1828         rectf.Y == exp.Y &&
1829         rectf.Width == exp.Width &&
1830         rectf.Height == exp.Height,
1831         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1832         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1833         rectf.X, rectf.Y, rectf.Width, rectf.Height,
1834         exp.X, exp.Y, exp.Width, exp.Height);
1835
1836     status = GdipGetVisibleClipBoundsI(graphics, &recti);
1837     expect(Ok, status);
1838     ok(recti.X == exp.X &&
1839         recti.Y == exp.Y &&
1840         recti.Width == exp.Width &&
1841         recti.Height == exp.Height,
1842         "Expected clip bounds (%d, %d, %d, %d) to be the size of "
1843         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1844         recti.X, recti.Y, recti.Width, recti.Height,
1845         exp.X, exp.Y, exp.Width, exp.Height);
1846
1847     GdipDeleteGraphics(graphics);
1848     EndPaint(hwnd, &ps);
1849 }
1850
1851 static void test_GdipGetVisibleClipBounds(void)
1852 {
1853     GpGraphics* graphics = NULL;
1854     GpRectF rectf;
1855     GpRect rect;
1856     HDC hdc = GetDC( hwnd );
1857     GpStatus status;
1858
1859     status = GdipCreateFromHDC(hdc, &graphics);
1860     expect(Ok, status);
1861     ok(graphics != NULL, "Expected graphics to be initialized\n");
1862
1863     /* test null parameters */
1864     status = GdipGetVisibleClipBounds(graphics, NULL);
1865     expect(InvalidParameter, status);
1866
1867     status = GdipGetVisibleClipBounds(NULL, &rectf);
1868     expect(InvalidParameter, status);
1869
1870     status = GdipGetVisibleClipBoundsI(graphics, NULL);
1871     expect(InvalidParameter, status);
1872
1873     status = GdipGetVisibleClipBoundsI(NULL, &rect);
1874     expect(InvalidParameter, status);
1875
1876     GdipDeleteGraphics(graphics);
1877     ReleaseDC(hwnd, hdc);
1878
1879     test_GdipGetVisibleClipBounds_screen();
1880     test_GdipGetVisibleClipBounds_window();
1881 }
1882
1883 static void test_fromMemoryBitmap(void)
1884 {
1885     GpStatus status;
1886     GpGraphics *graphics = NULL;
1887     GpBitmap *bitmap = NULL;
1888     BYTE bits[48] = {0};
1889
1890     status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
1891     expect(Ok, status);
1892
1893     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
1894     expect(Ok, status);
1895
1896     status = GdipGraphicsClear(graphics, 0xff686868);
1897     expect(Ok, status);
1898
1899     GdipDeleteGraphics(graphics);
1900
1901     /* drawing writes to the memory provided */
1902     todo_wine expect(0x68, bits[10]);
1903
1904     GdipDisposeImage((GpImage*)bitmap);
1905 }
1906
1907 static void test_GdipIsVisiblePoint(void)
1908 {
1909     GpStatus status;
1910     GpGraphics *graphics = NULL;
1911     HDC hdc = GetDC( hwnd );
1912     REAL x, y;
1913     BOOL val;
1914
1915     ok(hdc != NULL, "Expected HDC to be initialized\n");
1916
1917     status = GdipCreateFromHDC(hdc, &graphics);
1918     expect(Ok, status);
1919     ok(graphics != NULL, "Expected graphics to be initialized\n");
1920
1921     /* null parameters */
1922     status = GdipIsVisiblePoint(NULL, 0, 0, &val);
1923     expect(InvalidParameter, status);
1924
1925     status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
1926     expect(InvalidParameter, status);
1927
1928     status = GdipIsVisiblePointI(NULL, 0, 0, &val);
1929     expect(InvalidParameter, status);
1930
1931     status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
1932     expect(InvalidParameter, status);
1933
1934     x = 0;
1935     y = 0;
1936     status = GdipIsVisiblePoint(graphics, x, y, &val);
1937     expect(Ok, status);
1938     ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1939
1940     x = -10;
1941     y = 0;
1942     status = GdipIsVisiblePoint(graphics, x, y, &val);
1943     expect(Ok, status);
1944     ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1945
1946     x = 0;
1947     y = -5;
1948     status = GdipIsVisiblePoint(graphics, x, y, &val);
1949     expect(Ok, status);
1950     ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1951
1952     x = 1;
1953     y = 1;
1954     status = GdipIsVisiblePoint(graphics, x, y, &val);
1955     expect(Ok, status);
1956     ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1957
1958     status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
1959     expect(Ok, status);
1960
1961     x = 1;
1962     y = 1;
1963     status = GdipIsVisiblePoint(graphics, x, y, &val);
1964     expect(Ok, status);
1965     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
1966
1967     x = 15.5;
1968     y = 40.5;
1969     status = GdipIsVisiblePoint(graphics, x, y, &val);
1970     expect(Ok, status);
1971     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
1972
1973     /* translate into the center of the rect */
1974     GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1975
1976     x = 0;
1977     y = 0;
1978     status = GdipIsVisiblePoint(graphics, x, y, &val);
1979     expect(Ok, status);
1980     ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1981
1982     x = 25;
1983     y = 40;
1984     status = GdipIsVisiblePoint(graphics, x, y, &val);
1985     expect(Ok, status);
1986     ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1987
1988     GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1989
1990     /* corner cases */
1991     x = 9;
1992     y = 19;
1993     status = GdipIsVisiblePoint(graphics, x, y, &val);
1994     expect(Ok, status);
1995     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
1996
1997     x = 9.25;
1998     y = 19.25;
1999     status = GdipIsVisiblePoint(graphics, x, y, &val);
2000     expect(Ok, status);
2001     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2002
2003     x = 9.5;
2004     y = 19.5;
2005     status = GdipIsVisiblePoint(graphics, x, y, &val);
2006     expect(Ok, status);
2007     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2008
2009     x = 9.75;
2010     y = 19.75;
2011     status = GdipIsVisiblePoint(graphics, x, y, &val);
2012     expect(Ok, status);
2013     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2014
2015     x = 10;
2016     y = 20;
2017     status = GdipIsVisiblePoint(graphics, x, y, &val);
2018     expect(Ok, status);
2019     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2020
2021     x = 40;
2022     y = 20;
2023     status = GdipIsVisiblePoint(graphics, x, y, &val);
2024     expect(Ok, status);
2025     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2026
2027     x = 39;
2028     y = 59;
2029     status = GdipIsVisiblePoint(graphics, x, y, &val);
2030     expect(Ok, status);
2031     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2032
2033     x = 39.25;
2034     y = 59.25;
2035     status = GdipIsVisiblePoint(graphics, x, y, &val);
2036     expect(Ok, status);
2037     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2038
2039     x = 39.5;
2040     y = 39.5;
2041     status = GdipIsVisiblePoint(graphics, x, y, &val);
2042     expect(Ok, status);
2043     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2044
2045     x = 39.75;
2046     y = 59.75;
2047     status = GdipIsVisiblePoint(graphics, x, y, &val);
2048     expect(Ok, status);
2049     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2050
2051     x = 40;
2052     y = 60;
2053     status = GdipIsVisiblePoint(graphics, x, y, &val);
2054     expect(Ok, status);
2055     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2056
2057     x = 40.15;
2058     y = 60.15;
2059     status = GdipIsVisiblePoint(graphics, x, y, &val);
2060     expect(Ok, status);
2061     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2062
2063     x = 10;
2064     y = 60;
2065     status = GdipIsVisiblePoint(graphics, x, y, &val);
2066     expect(Ok, status);
2067     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2068
2069     /* integer version */
2070     x = 25;
2071     y = 30;
2072     status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2073     expect(Ok, status);
2074     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2075
2076     x = 50;
2077     y = 100;
2078     status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2079     expect(Ok, status);
2080     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2081
2082     GdipDeleteGraphics(graphics);
2083     ReleaseDC(hwnd, hdc);
2084 }
2085
2086 static void test_GdipIsVisibleRect(void)
2087 {
2088     GpStatus status;
2089     GpGraphics *graphics = NULL;
2090     HDC hdc = GetDC( hwnd );
2091     REAL x, y, width, height;
2092     BOOL val;
2093
2094     ok(hdc != NULL, "Expected HDC to be initialized\n");
2095
2096     status = GdipCreateFromHDC(hdc, &graphics);
2097     expect(Ok, status);
2098     ok(graphics != NULL, "Expected graphics to be initialized\n");
2099
2100     status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2101     expect(InvalidParameter, status);
2102
2103     status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2104     expect(InvalidParameter, status);
2105
2106     status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2107     expect(InvalidParameter, status);
2108
2109     status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2110     expect(InvalidParameter, status);
2111
2112     /* entirely within the visible region */
2113     x = 0; width = 10;
2114     y = 0; height = 10;
2115     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2116     expect(Ok, status);
2117     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2118
2119     /* partially outside */
2120     x = -10; width = 20;
2121     y = -10; height = 20;
2122     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2123     expect(Ok, status);
2124     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2125
2126     /* entirely outside */
2127     x = -10; width = 5;
2128     y = -10; height = 5;
2129     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2130     expect(Ok, status);
2131     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2132
2133     status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2134     expect(Ok, status);
2135
2136     /* entirely within the visible region */
2137     x = 12; width = 10;
2138     y = 22; height = 10;
2139     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2140     expect(Ok, status);
2141     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2142
2143     /* partially outside */
2144     x = 35; width = 10;
2145     y = 55; height = 10;
2146     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2147     expect(Ok, status);
2148     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2149
2150     /* entirely outside */
2151     x = 45; width = 5;
2152     y = 65; height = 5;
2153     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2154     expect(Ok, status);
2155     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2156
2157     /* translate into center of clipping rect */
2158     GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2159
2160     x = 0; width = 10;
2161     y = 0; height = 10;
2162     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2163     expect(Ok, status);
2164     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2165
2166     x = 25; width = 5;
2167     y = 40; height = 5;
2168     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2169     expect(Ok, status);
2170     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2171
2172     GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2173
2174     /* corners entirely outside, but some intersections */
2175     x = 0; width = 70;
2176     y = 0; height = 90;
2177     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2178     expect(Ok, status);
2179     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2180
2181     x = 0; width = 70;
2182     y = 0; height = 30;
2183     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2184     expect(Ok, status);
2185     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2186
2187     x = 0; width = 30;
2188     y = 0; height = 90;
2189     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2190     expect(Ok, status);
2191     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2192
2193     /* edge cases */
2194     x = 0; width = 10;
2195     y = 20; height = 40;
2196     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2197     expect(Ok, status);
2198     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2199
2200     x = 10; width = 30;
2201     y = 0; height = 20;
2202     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2203     expect(Ok, status);
2204     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2205
2206     x = 40; width = 10;
2207     y = 20; height = 40;
2208     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2209     expect(Ok, status);
2210     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2211
2212     x = 10; width = 30;
2213     y = 60; height = 10;
2214     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2215     expect(Ok, status);
2216     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2217
2218     /* rounding tests */
2219     x = 0.4; width = 10.4;
2220     y = 20; height = 40;
2221     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2222     expect(Ok, status);
2223     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2224
2225     x = 10; width = 30;
2226     y = 0.4; height = 20.4;
2227     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2228     expect(Ok, status);
2229     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2230
2231     /* integer version */
2232     x = 0; width = 30;
2233     y = 0; height = 90;
2234     status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2235     expect(Ok, status);
2236     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2237
2238     x = 12; width = 10;
2239     y = 22; height = 10;
2240     status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2241     expect(Ok, status);
2242     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2243
2244     GdipDeleteGraphics(graphics);
2245     ReleaseDC(hwnd, hdc);
2246 }
2247
2248 static void test_GdipGetNearestColor(void)
2249 {
2250     GpStatus status;
2251     GpGraphics *graphics;
2252     GpBitmap *bitmap;
2253     ARGB color = 0xdeadbeef;
2254     HDC hdc = GetDC( hwnd );
2255
2256     /* create a graphics object */
2257     ok(hdc != NULL, "Expected HDC to be initialized\n");
2258
2259     status = GdipCreateFromHDC(hdc, &graphics);
2260     expect(Ok, status);
2261     ok(graphics != NULL, "Expected graphics to be initialized\n");
2262
2263     status = GdipGetNearestColor(graphics, NULL);
2264     expect(InvalidParameter, status);
2265
2266     status = GdipGetNearestColor(NULL, &color);
2267     expect(InvalidParameter, status);
2268     GdipDeleteGraphics(graphics);
2269
2270     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2271     expect(Ok, status);
2272     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2273     ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2274     if (status == Ok)
2275     {
2276         status = GdipGetNearestColor(graphics, &color);
2277         expect(Ok, status);
2278         expect(0xdeadbeef, color);
2279         GdipDeleteGraphics(graphics);
2280     }
2281     GdipDisposeImage((GpImage*)bitmap);
2282
2283     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2284     expect(Ok, status);
2285     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2286     ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2287     if (status == Ok)
2288     {
2289         status = GdipGetNearestColor(graphics, &color);
2290         expect(Ok, status);
2291         expect(0xdeadbeef, color);
2292         GdipDeleteGraphics(graphics);
2293     }
2294     GdipDisposeImage((GpImage*)bitmap);
2295
2296     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2297     expect(Ok, status);
2298     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2299     ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2300     if (status == Ok)
2301     {
2302         status = GdipGetNearestColor(graphics, &color);
2303         expect(Ok, status);
2304         expect(0xdeadbeef, color);
2305         GdipDeleteGraphics(graphics);
2306     }
2307     GdipDisposeImage((GpImage*)bitmap);
2308
2309     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2310     expect(Ok, status);
2311     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2312     todo_wine expect(OutOfMemory, status);
2313     if (status == Ok)
2314         GdipDeleteGraphics(graphics);
2315     GdipDisposeImage((GpImage*)bitmap);
2316
2317     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2318     expect(Ok, status);
2319     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2320     expect(Ok, status);
2321     status = GdipGetNearestColor(graphics, &color);
2322     expect(Ok, status);
2323     expect(0xdeadbeef, color);
2324     GdipDeleteGraphics(graphics);
2325     GdipDisposeImage((GpImage*)bitmap);
2326
2327     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2328     expect(Ok, status);
2329     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2330     expect(Ok, status);
2331     status = GdipGetNearestColor(graphics, &color);
2332     expect(Ok, status);
2333     expect(0xdeadbeef, color);
2334     GdipDeleteGraphics(graphics);
2335     GdipDisposeImage((GpImage*)bitmap);
2336
2337     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2338     expect(Ok, status);
2339     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2340     expect(Ok, status);
2341     status = GdipGetNearestColor(graphics, &color);
2342     expect(Ok, status);
2343     expect(0xdeadbeef, color);
2344     GdipDeleteGraphics(graphics);
2345     GdipDisposeImage((GpImage*)bitmap);
2346
2347     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2348     expect(Ok, status);
2349     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2350     expect(Ok, status);
2351     status = GdipGetNearestColor(graphics, &color);
2352     expect(Ok, status);
2353     expect(0xdeadbeef, color);
2354     GdipDeleteGraphics(graphics);
2355     GdipDisposeImage((GpImage*)bitmap);
2356
2357     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2358     expect(Ok, status);
2359     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2360     expect(Ok, status);
2361     status = GdipGetNearestColor(graphics, &color);
2362     expect(Ok, status);
2363     expect(0xdeadbeef, color);
2364     GdipDeleteGraphics(graphics);
2365     GdipDisposeImage((GpImage*)bitmap);
2366
2367     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2368     expect(Ok, status);
2369     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2370     expect(Ok, status);
2371     status = GdipGetNearestColor(graphics, &color);
2372     expect(Ok, status);
2373     expect(0xdeadbeef, color);
2374     GdipDeleteGraphics(graphics);
2375     GdipDisposeImage((GpImage*)bitmap);
2376
2377     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
2378     expect(Ok, status);
2379     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2380     expect(Ok, status);
2381     status = GdipGetNearestColor(graphics, &color);
2382     expect(Ok, status);
2383     todo_wine expect(0xffa8bce8, color);
2384     GdipDeleteGraphics(graphics);
2385     GdipDisposeImage((GpImage*)bitmap);
2386
2387     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
2388     expect(Ok, status);
2389     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2390     expect(Ok, status);
2391     status = GdipGetNearestColor(graphics, &color);
2392     expect(Ok, status);
2393     todo_wine
2394     ok(color == 0xffa8b8e8 ||
2395        broken(color == 0xffa0b8e0), /* Win98/WinMe */
2396        "Expected ffa8b8e8, got %.8x\n", color);
2397     GdipDeleteGraphics(graphics);
2398     GdipDisposeImage((GpImage*)bitmap);
2399
2400     ReleaseDC(hwnd, hdc);
2401 }
2402
2403 static void test_string_functions(void)
2404 {
2405     GpStatus status;
2406     GpGraphics *graphics;
2407     GpFontFamily *family;
2408     GpFont *font;
2409     RectF rc;
2410     GpBrush *brush;
2411     ARGB color = 0xff000000;
2412     HDC hdc = GetDC( hwnd );
2413     const WCHAR fontname[] = {'C','o','u','r','i','e','r',' ','N','e','w',0};
2414     const WCHAR fontname2[] = {'C','o','u','r','i','e','r',0};
2415     const WCHAR teststring[] = {'o','o',' ','o','\n','o',0};
2416
2417     ok(hdc != NULL, "Expected HDC to be initialized\n");
2418     status = GdipCreateFromHDC(hdc, &graphics);
2419     expect(Ok, status);
2420     ok(graphics != NULL, "Expected graphics to be initialized\n");
2421
2422     status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
2423
2424     if (status != Ok)
2425     {
2426         /* Wine doesn't have Courier New? */
2427         todo_wine expect(Ok, status);
2428         status = GdipCreateFontFamilyFromName(fontname2, NULL, &family);
2429     }
2430
2431     expect(Ok, status);
2432
2433     status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
2434     expect(Ok, status);
2435
2436     status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
2437     expect(Ok, status);
2438
2439     rc.X = 0;
2440     rc.Y = 0;
2441     rc.Width = 100.0;
2442     rc.Height = 100.0;
2443
2444     status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
2445     expect(InvalidParameter, status);
2446
2447     status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
2448     expect(InvalidParameter, status);
2449
2450     status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
2451     expect(InvalidParameter, status);
2452
2453     status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
2454     expect(InvalidParameter, status);
2455
2456     status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
2457     expect(InvalidParameter, status);
2458
2459     status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
2460     expect(Ok, status);
2461
2462     GdipDeleteBrush(brush);
2463     GdipDeleteFont(font);
2464     GdipDeleteFontFamily(family);
2465     GdipDeleteGraphics(graphics);
2466
2467     ReleaseDC(hwnd, hdc);
2468 }
2469
2470 START_TEST(graphics)
2471 {
2472     struct GdiplusStartupInput gdiplusStartupInput;
2473     ULONG_PTR gdiplusToken;
2474     WNDCLASSA class;
2475
2476     memset( &class, 0, sizeof(class) );
2477     class.lpszClassName = "gdiplus_test";
2478     class.style = CS_HREDRAW | CS_VREDRAW;
2479     class.lpfnWndProc = DefWindowProcA;
2480     class.hInstance = GetModuleHandleA(0);
2481     class.hIcon = LoadIcon(0, IDI_APPLICATION);
2482     class.hCursor = LoadCursor(NULL, IDC_ARROW);
2483     class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2484     RegisterClassA( &class );
2485     hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2486                           CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
2487     ok(hwnd != NULL, "Expected window to be created\n");
2488
2489     gdiplusStartupInput.GdiplusVersion              = 1;
2490     gdiplusStartupInput.DebugEventCallback          = NULL;
2491     gdiplusStartupInput.SuppressBackgroundThread    = 0;
2492     gdiplusStartupInput.SuppressExternalCodecs      = 0;
2493
2494     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2495
2496     test_constructor_destructor();
2497     test_save_restore();
2498     test_GdipDrawBezierI();
2499     test_GdipDrawArc();
2500     test_GdipDrawArcI();
2501     test_GdipDrawCurve();
2502     test_GdipDrawCurveI();
2503     test_GdipDrawCurve2();
2504     test_GdipDrawCurve2I();
2505     test_GdipDrawCurve3();
2506     test_GdipDrawCurve3I();
2507     test_GdipDrawLineI();
2508     test_GdipDrawLinesI();
2509     test_GdipDrawString();
2510     test_GdipGetNearestColor();
2511     test_GdipGetVisibleClipBounds();
2512     test_GdipIsVisiblePoint();
2513     test_GdipIsVisibleRect();
2514     test_Get_Release_DC();
2515     test_BeginContainer2();
2516     test_transformpoints();
2517     test_get_set_clip();
2518     test_isempty();
2519     test_clear();
2520     test_textcontrast();
2521     test_fromMemoryBitmap();
2522     test_string_functions();
2523
2524     GdiplusShutdown(gdiplusToken);
2525     DestroyWindow( hwnd );
2526 }