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