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