gdiplus: Create HBITMAP-less bitmap objects for exotic pixel formats.
[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
2161     status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2162     expect(Ok, status);
2163
2164     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2165     expect(Ok, status);
2166
2167     status = GdipGraphicsClear(graphics, 0xff686868);
2168     expect(Ok, status);
2169
2170     GdipDeleteGraphics(graphics);
2171
2172     /* drawing writes to the memory provided */
2173     todo_wine expect(0x68, bits[10]);
2174
2175     GdipDisposeImage((GpImage*)bitmap);
2176 }
2177
2178 static void test_GdipIsVisiblePoint(void)
2179 {
2180     GpStatus status;
2181     GpGraphics *graphics = NULL;
2182     HDC hdc = GetDC( hwnd );
2183     REAL x, y;
2184     BOOL val;
2185
2186     ok(hdc != NULL, "Expected HDC to be initialized\n");
2187
2188     status = GdipCreateFromHDC(hdc, &graphics);
2189     expect(Ok, status);
2190     ok(graphics != NULL, "Expected graphics to be initialized\n");
2191
2192     /* null parameters */
2193     status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2194     expect(InvalidParameter, status);
2195
2196     status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2197     expect(InvalidParameter, status);
2198
2199     status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2200     expect(InvalidParameter, status);
2201
2202     status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2203     expect(InvalidParameter, status);
2204
2205     x = 0;
2206     y = 0;
2207     status = GdipIsVisiblePoint(graphics, x, y, &val);
2208     expect(Ok, status);
2209     ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2210
2211     x = -10;
2212     y = 0;
2213     status = GdipIsVisiblePoint(graphics, x, y, &val);
2214     expect(Ok, status);
2215     ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2216
2217     x = 0;
2218     y = -5;
2219     status = GdipIsVisiblePoint(graphics, x, y, &val);
2220     expect(Ok, status);
2221     ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2222
2223     x = 1;
2224     y = 1;
2225     status = GdipIsVisiblePoint(graphics, x, y, &val);
2226     expect(Ok, status);
2227     ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2228
2229     status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2230     expect(Ok, status);
2231
2232     x = 1;
2233     y = 1;
2234     status = GdipIsVisiblePoint(graphics, x, y, &val);
2235     expect(Ok, status);
2236     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2237
2238     x = 15.5;
2239     y = 40.5;
2240     status = GdipIsVisiblePoint(graphics, x, y, &val);
2241     expect(Ok, status);
2242     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2243
2244     /* translate into the center of the rect */
2245     GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2246
2247     x = 0;
2248     y = 0;
2249     status = GdipIsVisiblePoint(graphics, x, y, &val);
2250     expect(Ok, status);
2251     ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2252
2253     x = 25;
2254     y = 40;
2255     status = GdipIsVisiblePoint(graphics, x, y, &val);
2256     expect(Ok, status);
2257     ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2258
2259     GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2260
2261     /* corner cases */
2262     x = 9;
2263     y = 19;
2264     status = GdipIsVisiblePoint(graphics, x, y, &val);
2265     expect(Ok, status);
2266     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2267
2268     x = 9.25;
2269     y = 19.25;
2270     status = GdipIsVisiblePoint(graphics, x, y, &val);
2271     expect(Ok, status);
2272     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2273
2274     x = 9.5;
2275     y = 19.5;
2276     status = GdipIsVisiblePoint(graphics, x, y, &val);
2277     expect(Ok, status);
2278     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2279
2280     x = 9.75;
2281     y = 19.75;
2282     status = GdipIsVisiblePoint(graphics, x, y, &val);
2283     expect(Ok, status);
2284     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2285
2286     x = 10;
2287     y = 20;
2288     status = GdipIsVisiblePoint(graphics, x, y, &val);
2289     expect(Ok, status);
2290     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2291
2292     x = 40;
2293     y = 20;
2294     status = GdipIsVisiblePoint(graphics, x, y, &val);
2295     expect(Ok, status);
2296     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2297
2298     x = 39;
2299     y = 59;
2300     status = GdipIsVisiblePoint(graphics, x, y, &val);
2301     expect(Ok, status);
2302     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2303
2304     x = 39.25;
2305     y = 59.25;
2306     status = GdipIsVisiblePoint(graphics, x, y, &val);
2307     expect(Ok, status);
2308     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2309
2310     x = 39.5;
2311     y = 39.5;
2312     status = GdipIsVisiblePoint(graphics, x, y, &val);
2313     expect(Ok, status);
2314     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2315
2316     x = 39.75;
2317     y = 59.75;
2318     status = GdipIsVisiblePoint(graphics, x, y, &val);
2319     expect(Ok, status);
2320     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2321
2322     x = 40;
2323     y = 60;
2324     status = GdipIsVisiblePoint(graphics, x, y, &val);
2325     expect(Ok, status);
2326     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2327
2328     x = 40.15;
2329     y = 60.15;
2330     status = GdipIsVisiblePoint(graphics, x, y, &val);
2331     expect(Ok, status);
2332     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2333
2334     x = 10;
2335     y = 60;
2336     status = GdipIsVisiblePoint(graphics, x, y, &val);
2337     expect(Ok, status);
2338     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2339
2340     /* integer version */
2341     x = 25;
2342     y = 30;
2343     status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2344     expect(Ok, status);
2345     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2346
2347     x = 50;
2348     y = 100;
2349     status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2350     expect(Ok, status);
2351     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2352
2353     GdipDeleteGraphics(graphics);
2354     ReleaseDC(hwnd, hdc);
2355 }
2356
2357 static void test_GdipIsVisibleRect(void)
2358 {
2359     GpStatus status;
2360     GpGraphics *graphics = NULL;
2361     HDC hdc = GetDC( hwnd );
2362     REAL x, y, width, height;
2363     BOOL val;
2364
2365     ok(hdc != NULL, "Expected HDC to be initialized\n");
2366
2367     status = GdipCreateFromHDC(hdc, &graphics);
2368     expect(Ok, status);
2369     ok(graphics != NULL, "Expected graphics to be initialized\n");
2370
2371     status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2372     expect(InvalidParameter, status);
2373
2374     status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2375     expect(InvalidParameter, status);
2376
2377     status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2378     expect(InvalidParameter, status);
2379
2380     status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2381     expect(InvalidParameter, status);
2382
2383     /* entirely within the visible region */
2384     x = 0; width = 10;
2385     y = 0; height = 10;
2386     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2387     expect(Ok, status);
2388     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2389
2390     /* partially outside */
2391     x = -10; width = 20;
2392     y = -10; height = 20;
2393     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2394     expect(Ok, status);
2395     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2396
2397     /* entirely outside */
2398     x = -10; width = 5;
2399     y = -10; height = 5;
2400     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2401     expect(Ok, status);
2402     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2403
2404     status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2405     expect(Ok, status);
2406
2407     /* entirely within the visible region */
2408     x = 12; width = 10;
2409     y = 22; height = 10;
2410     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2411     expect(Ok, status);
2412     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2413
2414     /* partially outside */
2415     x = 35; width = 10;
2416     y = 55; height = 10;
2417     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2418     expect(Ok, status);
2419     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2420
2421     /* entirely outside */
2422     x = 45; width = 5;
2423     y = 65; height = 5;
2424     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2425     expect(Ok, status);
2426     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2427
2428     /* translate into center of clipping rect */
2429     GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2430
2431     x = 0; width = 10;
2432     y = 0; height = 10;
2433     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2434     expect(Ok, status);
2435     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2436
2437     x = 25; width = 5;
2438     y = 40; height = 5;
2439     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2440     expect(Ok, status);
2441     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2442
2443     GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2444
2445     /* corners entirely outside, but some intersections */
2446     x = 0; width = 70;
2447     y = 0; height = 90;
2448     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2449     expect(Ok, status);
2450     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2451
2452     x = 0; width = 70;
2453     y = 0; height = 30;
2454     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2455     expect(Ok, status);
2456     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2457
2458     x = 0; width = 30;
2459     y = 0; height = 90;
2460     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2461     expect(Ok, status);
2462     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2463
2464     /* edge cases */
2465     x = 0; width = 10;
2466     y = 20; height = 40;
2467     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2468     expect(Ok, status);
2469     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2470
2471     x = 10; width = 30;
2472     y = 0; height = 20;
2473     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2474     expect(Ok, status);
2475     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2476
2477     x = 40; width = 10;
2478     y = 20; height = 40;
2479     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2480     expect(Ok, status);
2481     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2482
2483     x = 10; width = 30;
2484     y = 60; height = 10;
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     /* rounding tests */
2490     x = 0.4; width = 10.4;
2491     y = 20; height = 40;
2492     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2493     expect(Ok, status);
2494     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2495
2496     x = 10; width = 30;
2497     y = 0.4; height = 20.4;
2498     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2499     expect(Ok, status);
2500     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2501
2502     /* integer version */
2503     x = 0; width = 30;
2504     y = 0; height = 90;
2505     status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2506     expect(Ok, status);
2507     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2508
2509     x = 12; width = 10;
2510     y = 22; height = 10;
2511     status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2512     expect(Ok, status);
2513     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2514
2515     GdipDeleteGraphics(graphics);
2516     ReleaseDC(hwnd, hdc);
2517 }
2518
2519 static void test_GdipGetNearestColor(void)
2520 {
2521     GpStatus status;
2522     GpGraphics *graphics;
2523     GpBitmap *bitmap;
2524     ARGB color = 0xdeadbeef;
2525     HDC hdc = GetDC( hwnd );
2526
2527     /* create a graphics object */
2528     ok(hdc != NULL, "Expected HDC to be initialized\n");
2529
2530     status = GdipCreateFromHDC(hdc, &graphics);
2531     expect(Ok, status);
2532     ok(graphics != NULL, "Expected graphics to be initialized\n");
2533
2534     status = GdipGetNearestColor(graphics, NULL);
2535     expect(InvalidParameter, status);
2536
2537     status = GdipGetNearestColor(NULL, &color);
2538     expect(InvalidParameter, status);
2539     GdipDeleteGraphics(graphics);
2540
2541     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2542     expect(Ok, status);
2543     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2544     ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2545     if (status == Ok)
2546     {
2547         status = GdipGetNearestColor(graphics, &color);
2548         expect(Ok, status);
2549         expect(0xdeadbeef, color);
2550         GdipDeleteGraphics(graphics);
2551     }
2552     GdipDisposeImage((GpImage*)bitmap);
2553
2554     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2555     expect(Ok, status);
2556     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2557     ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2558     if (status == Ok)
2559     {
2560         status = GdipGetNearestColor(graphics, &color);
2561         expect(Ok, status);
2562         expect(0xdeadbeef, color);
2563         GdipDeleteGraphics(graphics);
2564     }
2565     GdipDisposeImage((GpImage*)bitmap);
2566
2567     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2568     expect(Ok, status);
2569     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2570     ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2571     if (status == Ok)
2572     {
2573         status = GdipGetNearestColor(graphics, &color);
2574         expect(Ok, status);
2575         expect(0xdeadbeef, color);
2576         GdipDeleteGraphics(graphics);
2577     }
2578     GdipDisposeImage((GpImage*)bitmap);
2579
2580     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2581     expect(Ok, status);
2582     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2583     todo_wine expect(OutOfMemory, status);
2584     if (status == Ok)
2585         GdipDeleteGraphics(graphics);
2586     GdipDisposeImage((GpImage*)bitmap);
2587
2588     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2589     expect(Ok, status);
2590     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2591     expect(Ok, status);
2592     status = GdipGetNearestColor(graphics, &color);
2593     expect(Ok, status);
2594     expect(0xdeadbeef, color);
2595     GdipDeleteGraphics(graphics);
2596     GdipDisposeImage((GpImage*)bitmap);
2597
2598     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2599     expect(Ok, status);
2600     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2601     expect(Ok, status);
2602     status = GdipGetNearestColor(graphics, &color);
2603     expect(Ok, status);
2604     expect(0xdeadbeef, color);
2605     GdipDeleteGraphics(graphics);
2606     GdipDisposeImage((GpImage*)bitmap);
2607
2608     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2609     expect(Ok, status);
2610     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2611     expect(Ok, status);
2612     status = GdipGetNearestColor(graphics, &color);
2613     expect(Ok, status);
2614     expect(0xdeadbeef, color);
2615     GdipDeleteGraphics(graphics);
2616     GdipDisposeImage((GpImage*)bitmap);
2617
2618     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2619     expect(Ok, status);
2620     if (status == Ok)
2621     {
2622         status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2623         expect(Ok, status);
2624         status = GdipGetNearestColor(graphics, &color);
2625         expect(Ok, status);
2626         expect(0xdeadbeef, color);
2627         GdipDeleteGraphics(graphics);
2628         GdipDisposeImage((GpImage*)bitmap);
2629     }
2630
2631     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2632     expect(Ok, status);
2633     if (status == Ok)
2634     {
2635         status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2636         expect(Ok, status);
2637         status = GdipGetNearestColor(graphics, &color);
2638         expect(Ok, status);
2639         expect(0xdeadbeef, color);
2640         GdipDeleteGraphics(graphics);
2641         GdipDisposeImage((GpImage*)bitmap);
2642     }
2643
2644     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2645     expect(Ok, status);
2646     if (status == Ok)
2647     {
2648         status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2649         expect(Ok, status);
2650         status = GdipGetNearestColor(graphics, &color);
2651         expect(Ok, status);
2652         expect(0xdeadbeef, color);
2653         GdipDeleteGraphics(graphics);
2654         GdipDisposeImage((GpImage*)bitmap);
2655     }
2656
2657     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
2658     expect(Ok, status);
2659     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2660     expect(Ok, status);
2661     status = GdipGetNearestColor(graphics, &color);
2662     expect(Ok, status);
2663     todo_wine expect(0xffa8bce8, color);
2664     GdipDeleteGraphics(graphics);
2665     GdipDisposeImage((GpImage*)bitmap);
2666
2667     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
2668     expect(Ok, status);
2669     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2670     expect(Ok, status);
2671     status = GdipGetNearestColor(graphics, &color);
2672     expect(Ok, status);
2673     todo_wine
2674     ok(color == 0xffa8b8e8 ||
2675        broken(color == 0xffa0b8e0), /* Win98/WinMe */
2676        "Expected ffa8b8e8, got %.8x\n", color);
2677     GdipDeleteGraphics(graphics);
2678     GdipDisposeImage((GpImage*)bitmap);
2679
2680     ReleaseDC(hwnd, hdc);
2681 }
2682
2683 static void test_string_functions(void)
2684 {
2685     GpStatus status;
2686     GpGraphics *graphics;
2687     GpFontFamily *family;
2688     GpFont *font;
2689     RectF rc, char_bounds, bounds;
2690     GpBrush *brush;
2691     ARGB color = 0xff000000;
2692     HDC hdc = GetDC( hwnd );
2693     const WCHAR fontname[] = {'T','a','h','o','m','a',0};
2694     const WCHAR teststring[] = {'M','M',' ','M','\n','M',0};
2695     REAL char_width, char_height;
2696     INT codepointsfitted, linesfilled;
2697     GpStringFormat *format;
2698     CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
2699     GpRegion *regions[4] = {0};
2700     BOOL region_isempty[4];
2701     int i;
2702
2703     ok(hdc != NULL, "Expected HDC to be initialized\n");
2704     status = GdipCreateFromHDC(hdc, &graphics);
2705     expect(Ok, status);
2706     ok(graphics != NULL, "Expected graphics to be initialized\n");
2707
2708     status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
2709     expect(Ok, status);
2710
2711     status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
2712     expect(Ok, status);
2713
2714     status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
2715     expect(Ok, status);
2716
2717     status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
2718     expect(Ok, status);
2719
2720     rc.X = 0;
2721     rc.Y = 0;
2722     rc.Width = 100.0;
2723     rc.Height = 100.0;
2724
2725     status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
2726     expect(InvalidParameter, status);
2727
2728     status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
2729     expect(InvalidParameter, status);
2730
2731     status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
2732     expect(InvalidParameter, status);
2733
2734     status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
2735     expect(InvalidParameter, status);
2736
2737     status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
2738     expect(InvalidParameter, status);
2739
2740     status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
2741     expect(Ok, status);
2742
2743     status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2744     expect(InvalidParameter, status);
2745
2746     status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2747     expect(InvalidParameter, status);
2748
2749     status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2750     expect(InvalidParameter, status);
2751
2752     status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
2753     expect(InvalidParameter, status);
2754
2755     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
2756     expect(InvalidParameter, status);
2757
2758     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
2759     expect(Ok, status);
2760
2761     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
2762     expect(Ok, status);
2763
2764     status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
2765     expect(Ok, status);
2766     expectf(0.0, char_bounds.X);
2767     expectf(0.0, char_bounds.Y);
2768     ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
2769     ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
2770     expect(1, codepointsfitted);
2771     expect(1, linesfilled);
2772
2773     status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2774     expect(Ok, status);
2775     expectf(0.0, bounds.X);
2776     expectf(0.0, bounds.Y);
2777     ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
2778     expectf(char_bounds.Height, bounds.Height);
2779     expect(2, codepointsfitted);
2780     expect(1, linesfilled);
2781     char_width = bounds.Width - char_bounds.Width;
2782
2783     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2784     expect(Ok, status);
2785     expectf(0.0, bounds.X);
2786     expectf(0.0, bounds.Y);
2787     ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
2788        bounds.Width, char_bounds.Width + char_width * 2);
2789     ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
2790     expect(6, codepointsfitted);
2791     expect(2, linesfilled);
2792     char_height = bounds.Height - char_bounds.Height;
2793
2794     /* Cut off everything after the first space. */
2795     rc.Width = char_bounds.Width + char_width * 2.1;
2796
2797     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2798     expect(Ok, status);
2799     expectf(0.0, bounds.X);
2800     expectf(0.0, bounds.Y);
2801     expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
2802     expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
2803     expect(6, codepointsfitted);
2804     expect(3, linesfilled);
2805
2806     /* Cut off everything including the first space. */
2807     rc.Width = char_bounds.Width + char_width * 1.5;
2808
2809     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2810     expect(Ok, status);
2811     expectf(0.0, bounds.X);
2812     expectf(0.0, bounds.Y);
2813     expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
2814     expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
2815     expect(6, codepointsfitted);
2816     expect(3, linesfilled);
2817
2818     /* Cut off everything after the first character. */
2819     rc.Width = char_bounds.Width + char_width * 0.5;
2820
2821     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2822     expect(Ok, status);
2823     expectf(0.0, bounds.X);
2824     expectf(0.0, bounds.Y);
2825     expectf_(char_bounds.Width, bounds.Width, 0.01);
2826     todo_wine expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
2827     expect(6, codepointsfitted);
2828     todo_wine expect(4, linesfilled);
2829
2830     status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
2831     expect(Ok, status);
2832
2833     rc.Width = 100.0;
2834
2835     for (i=0; i<4; i++)
2836     {
2837         status = GdipCreateRegion(&regions[i]);
2838         expect(Ok, status);
2839     }
2840
2841     status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
2842     expect(InvalidParameter, status);
2843
2844     status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
2845     expect(InvalidParameter, status);
2846
2847     status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
2848     expect(InvalidParameter, status);
2849
2850     status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
2851     expect(InvalidParameter, status);
2852
2853     if (0)
2854     {
2855         /* Crashes on Windows XP */
2856         status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
2857         expect(InvalidParameter, status);
2858     }
2859
2860     status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
2861     expect(InvalidParameter, status);
2862
2863     status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
2864     expect(InvalidParameter, status);
2865
2866     status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
2867     expect(Ok, status);
2868
2869     for (i=0; i<4; i++)
2870     {
2871         status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
2872         expect(Ok, status);
2873     }
2874
2875     ok(!region_isempty[0], "region shouldn't be empty\n");
2876     ok(!region_isempty[1], "region shouldn't be empty\n");
2877     ok(!region_isempty[2], "region shouldn't be empty\n");
2878     ok(!region_isempty[3], "region shouldn't be empty\n");
2879
2880     /* Cut off everything after the first space, and the second line. */
2881     rc.Width = char_bounds.Width + char_width * 2.1;
2882     rc.Height = char_bounds.Height + char_height * 0.5;
2883
2884     status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
2885     expect(Ok, status);
2886
2887     for (i=0; i<4; i++)
2888     {
2889         status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
2890         expect(Ok, status);
2891     }
2892
2893     ok(!region_isempty[0], "region shouldn't be empty\n");
2894     ok(!region_isempty[1], "region shouldn't be empty\n");
2895     ok(region_isempty[2], "region should be empty\n");
2896     ok(!region_isempty[3], "region shouldn't be empty\n");
2897
2898     for (i=0; i<4; i++)
2899         GdipDeleteRegion(regions[i]);
2900
2901     GdipDeleteStringFormat(format);
2902     GdipDeleteBrush(brush);
2903     GdipDeleteFont(font);
2904     GdipDeleteFontFamily(family);
2905     GdipDeleteGraphics(graphics);
2906
2907     ReleaseDC(hwnd, hdc);
2908 }
2909
2910 START_TEST(graphics)
2911 {
2912     struct GdiplusStartupInput gdiplusStartupInput;
2913     ULONG_PTR gdiplusToken;
2914     WNDCLASSA class;
2915
2916     memset( &class, 0, sizeof(class) );
2917     class.lpszClassName = "gdiplus_test";
2918     class.style = CS_HREDRAW | CS_VREDRAW;
2919     class.lpfnWndProc = DefWindowProcA;
2920     class.hInstance = GetModuleHandleA(0);
2921     class.hIcon = LoadIcon(0, IDI_APPLICATION);
2922     class.hCursor = LoadCursor(NULL, IDC_ARROW);
2923     class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2924     RegisterClassA( &class );
2925     hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2926                           CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
2927     ok(hwnd != NULL, "Expected window to be created\n");
2928
2929     gdiplusStartupInput.GdiplusVersion              = 1;
2930     gdiplusStartupInput.DebugEventCallback          = NULL;
2931     gdiplusStartupInput.SuppressBackgroundThread    = 0;
2932     gdiplusStartupInput.SuppressExternalCodecs      = 0;
2933
2934     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2935
2936     test_constructor_destructor();
2937     test_save_restore();
2938     test_GdipFillClosedCurve2();
2939     test_GdipFillClosedCurve2I();
2940     test_GdipDrawBezierI();
2941     test_GdipDrawArc();
2942     test_GdipDrawArcI();
2943     test_GdipDrawCurve();
2944     test_GdipDrawCurveI();
2945     test_GdipDrawCurve2();
2946     test_GdipDrawCurve2I();
2947     test_GdipDrawCurve3();
2948     test_GdipDrawCurve3I();
2949     test_GdipDrawLineI();
2950     test_GdipDrawLinesI();
2951     test_GdipFillClosedCurve();
2952     test_GdipFillClosedCurveI();
2953     test_GdipDrawString();
2954     test_GdipGetNearestColor();
2955     test_GdipGetVisibleClipBounds();
2956     test_GdipIsVisiblePoint();
2957     test_GdipIsVisibleRect();
2958     test_Get_Release_DC();
2959     test_BeginContainer2();
2960     test_transformpoints();
2961     test_get_set_clip();
2962     test_isempty();
2963     test_clear();
2964     test_textcontrast();
2965     test_fromMemoryBitmap();
2966     test_string_functions();
2967
2968     GdiplusShutdown(gdiplusToken);
2969     DestroyWindow( hwnd );
2970 }