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