wined3d: Remove COM from the shader implementation.
[wine] / dlls / gdiplus / tests / graphics.c
1 /*
2  * Unit test suite for graphics objects
3  *
4  * Copyright (C) 2007 Google (Evan Stade)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wingdi.h"
24 #include "wine/test.h"
25 #include <math.h>
26
27 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
28 #define expectf_(expected, got, precision) ok(fabs(expected - got) < precision, "Expected %.2f, got %.2f\n", expected, got)
29 #define expectf(expected, got) expectf_(expected, got, 0.0001)
30 #define TABLE_LEN (23)
31
32 static HWND hwnd;
33
34 static void test_constructor_destructor(void)
35 {
36     GpStatus stat;
37     GpGraphics *graphics = NULL;
38     HDC hdc = GetDC( hwnd );
39
40     stat = GdipCreateFromHDC(NULL, &graphics);
41     expect(OutOfMemory, stat);
42     stat = GdipDeleteGraphics(graphics);
43     expect(InvalidParameter, stat);
44
45     stat = GdipCreateFromHDC(hdc, &graphics);
46     expect(Ok, stat);
47     stat = GdipDeleteGraphics(graphics);
48     expect(Ok, stat);
49
50     stat = GdipCreateFromHWND(NULL, &graphics);
51     expect(Ok, stat);
52     stat = GdipDeleteGraphics(graphics);
53     expect(Ok, stat);
54
55     stat = GdipCreateFromHWNDICM(NULL, &graphics);
56     expect(Ok, stat);
57     stat = GdipDeleteGraphics(graphics);
58     expect(Ok, stat);
59
60     stat = GdipDeleteGraphics(NULL);
61     expect(InvalidParameter, stat);
62     ReleaseDC(hwnd, hdc);
63 }
64
65 typedef struct node{
66     GraphicsState data;
67     struct node * next;
68 } node;
69
70 /* Linked list prepend function. */
71 static void log_state(GraphicsState data, node ** log)
72 {
73     node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
74
75     new_entry->data = data;
76     new_entry->next = *log;
77     *log = new_entry;
78 }
79
80 /* Checks if there are duplicates in the list, and frees it. */
81 static void check_no_duplicates(node * log)
82 {
83     INT dups = 0;
84     node * temp = NULL;
85     node * temp2 = NULL;
86     node * orig = log;
87
88     if(!log)
89         goto end;
90
91     do{
92         temp = log;
93         while((temp = temp->next)){
94             if(log->data == temp->data){
95                 dups++;
96                 break;
97             }
98             if(dups > 0)
99                 break;
100         }
101     }while((log = log->next));
102
103     temp = orig;
104     do{
105         temp2 = temp->next;
106         HeapFree(GetProcessHeap(), 0, temp);
107         temp = temp2;
108     }while(temp);
109
110 end:
111     expect(0, dups);
112 }
113
114 static void test_save_restore(void)
115 {
116     GpStatus stat;
117     GraphicsState state_a, state_b, state_c;
118     InterpolationMode mode;
119     GpGraphics *graphics1, *graphics2;
120     node * state_log = NULL;
121     HDC hdc = GetDC( hwnd );
122     state_a = state_b = state_c = 0xdeadbeef;
123
124     /* Invalid saving. */
125     GdipCreateFromHDC(hdc, &graphics1);
126     stat = GdipSaveGraphics(graphics1, NULL);
127     expect(InvalidParameter, stat);
128     stat = GdipSaveGraphics(NULL, &state_a);
129     expect(InvalidParameter, stat);
130     GdipDeleteGraphics(graphics1);
131
132     log_state(state_a, &state_log);
133
134     /* Basic save/restore. */
135     GdipCreateFromHDC(hdc, &graphics1);
136     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
137     stat = GdipSaveGraphics(graphics1, &state_a);
138     expect(Ok, stat);
139     GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
140     stat = GdipRestoreGraphics(graphics1, state_a);
141     expect(Ok, stat);
142     GdipGetInterpolationMode(graphics1, &mode);
143     expect(InterpolationModeBilinear, mode);
144     GdipDeleteGraphics(graphics1);
145
146     log_state(state_a, &state_log);
147
148     /* Restoring garbage doesn't affect saves. */
149     GdipCreateFromHDC(hdc, &graphics1);
150     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
151     GdipSaveGraphics(graphics1, &state_a);
152     GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
153     GdipSaveGraphics(graphics1, &state_b);
154     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
155     stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
156     expect(Ok, stat);
157     GdipRestoreGraphics(graphics1, state_b);
158     GdipGetInterpolationMode(graphics1, &mode);
159     expect(InterpolationModeBicubic, mode);
160     GdipRestoreGraphics(graphics1, state_a);
161     GdipGetInterpolationMode(graphics1, &mode);
162     expect(InterpolationModeBilinear, mode);
163     GdipDeleteGraphics(graphics1);
164
165     log_state(state_a, &state_log);
166     log_state(state_b, &state_log);
167
168     /* Restoring older state invalidates newer saves (but not older saves). */
169     GdipCreateFromHDC(hdc, &graphics1);
170     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
171     GdipSaveGraphics(graphics1, &state_a);
172     GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
173     GdipSaveGraphics(graphics1, &state_b);
174     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
175     GdipSaveGraphics(graphics1, &state_c);
176     GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
177     GdipRestoreGraphics(graphics1, state_b);
178     GdipGetInterpolationMode(graphics1, &mode);
179     expect(InterpolationModeBicubic, mode);
180     GdipRestoreGraphics(graphics1, state_c);
181     GdipGetInterpolationMode(graphics1, &mode);
182     expect(InterpolationModeBicubic, mode);
183     GdipRestoreGraphics(graphics1, state_a);
184     GdipGetInterpolationMode(graphics1, &mode);
185     expect(InterpolationModeBilinear, mode);
186     GdipDeleteGraphics(graphics1);
187
188     log_state(state_a, &state_log);
189     log_state(state_b, &state_log);
190     log_state(state_c, &state_log);
191
192     /* Restoring older save from one graphics object does not invalidate
193      * newer save from other graphics object. */
194     GdipCreateFromHDC(hdc, &graphics1);
195     GdipCreateFromHDC(hdc, &graphics2);
196     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
197     GdipSaveGraphics(graphics1, &state_a);
198     GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
199     GdipSaveGraphics(graphics2, &state_b);
200     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
201     GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
202     GdipRestoreGraphics(graphics1, state_a);
203     GdipGetInterpolationMode(graphics1, &mode);
204     expect(InterpolationModeBilinear, mode);
205     GdipRestoreGraphics(graphics2, state_b);
206     GdipGetInterpolationMode(graphics2, &mode);
207     expect(InterpolationModeBicubic, mode);
208     GdipDeleteGraphics(graphics1);
209     GdipDeleteGraphics(graphics2);
210
211     /* You can't restore a state to a graphics object that didn't save it. */
212     GdipCreateFromHDC(hdc, &graphics1);
213     GdipCreateFromHDC(hdc, &graphics2);
214     GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
215     GdipSaveGraphics(graphics1, &state_a);
216     GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
217     GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
218     GdipRestoreGraphics(graphics2, state_a);
219     GdipGetInterpolationMode(graphics2, &mode);
220     expect(InterpolationModeNearestNeighbor, mode);
221     GdipDeleteGraphics(graphics1);
222     GdipDeleteGraphics(graphics2);
223
224     log_state(state_a, &state_log);
225
226     /* The same state value should never be returned twice. */
227     todo_wine
228         check_no_duplicates(state_log);
229
230     ReleaseDC(hwnd, hdc);
231 }
232
233 static void test_GdipFillClosedCurve2(void)
234 {
235     GpStatus status;
236     GpGraphics *graphics = NULL;
237     GpSolidFill *brush = NULL;
238     HDC hdc = GetDC( hwnd );
239     GpPointF points[3];
240
241     points[0].X = 0;
242     points[0].Y = 0;
243
244     points[1].X = 40;
245     points[1].Y = 20;
246
247     points[2].X = 10;
248     points[2].Y = 40;
249
250     /* make a graphics object and brush object */
251     ok(hdc != NULL, "Expected HDC to be initialized\n");
252
253     status = GdipCreateFromHDC(hdc, &graphics);
254     expect(Ok, status);
255     ok(graphics != NULL, "Expected graphics to be initialized\n");
256
257     GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
258
259     /* InvalidParameter cases: null graphics, null brush, null points */
260     status = GdipFillClosedCurve2(NULL, NULL, NULL, 3, 0.5, FillModeAlternate);
261     expect(InvalidParameter, status);
262
263     status = GdipFillClosedCurve2(graphics, NULL, NULL, 3, 0.5, FillModeAlternate);
264     expect(InvalidParameter, status);
265
266     status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
267     expect(InvalidParameter, status);
268
269     status = GdipFillClosedCurve2(NULL, NULL, points, 3, 0.5, FillModeAlternate);
270     expect(InvalidParameter, status);
271
272     status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
273     expect(InvalidParameter, status);
274
275     status = GdipFillClosedCurve2(graphics, NULL, points, 3, 0.5, FillModeAlternate);
276     expect(InvalidParameter, status);
277
278     status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
279     expect(InvalidParameter, status);
280
281     /* InvalidParameter cases: invalid count */
282     status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
283     expect(InvalidParameter, status);
284
285     status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
286     expect(InvalidParameter, status);
287
288     /* Valid test cases */
289     status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
290     expect(Ok, status);
291
292     status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
293     expect(Ok, status);
294
295     status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
296     expect(Ok, status);
297
298     GdipDeleteGraphics(graphics);
299     GdipDeleteBrush((GpBrush*)brush);
300
301     ReleaseDC(hwnd, hdc);
302 }
303
304 static void test_GdipFillClosedCurve2I(void)
305 {
306     GpStatus status;
307     GpGraphics *graphics = NULL;
308     GpSolidFill *brush = NULL;
309     HDC hdc = GetDC( hwnd );
310     GpPoint points[3];
311
312     points[0].X = 0;
313     points[0].Y = 0;
314
315     points[1].X = 40;
316     points[1].Y = 20;
317
318     points[2].X = 10;
319     points[2].Y = 40;
320
321     /* make a graphics object and brush object */
322     ok(hdc != NULL, "Expected HDC to be initialized\n");
323
324     status = GdipCreateFromHDC(hdc, &graphics);
325     expect(Ok, status);
326     ok(graphics != NULL, "Expected graphics to be initialized\n");
327
328     GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
329
330     /* InvalidParameter cases: null graphics, null brush */
331     /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
332              when points == NULL, so don't test this condition */
333     status = GdipFillClosedCurve2I(NULL, NULL, points, 3, 0.5, FillModeAlternate);
334     expect(InvalidParameter, status);
335
336     status = GdipFillClosedCurve2I(graphics, NULL, points, 3, 0.5, FillModeAlternate);
337     expect(InvalidParameter, status);
338
339     status = GdipFillClosedCurve2I(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
340     expect(InvalidParameter, status);
341
342     /* InvalidParameter cases: invalid count */
343     status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
344     expect(InvalidParameter, status);
345
346     /* OutOfMemory cases: large (unsigned) int */
347     status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
348     expect(OutOfMemory, status);
349
350     /* Valid test cases */
351     status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
352     expect(Ok, status);
353
354     status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
355     expect(Ok, status);
356
357     status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
358     expect(Ok, status);
359
360     GdipDeleteGraphics(graphics);
361     GdipDeleteBrush((GpBrush*)brush);
362
363     ReleaseDC(hwnd, hdc);
364 }
365
366 static void test_GdipDrawArc(void)
367 {
368     GpStatus status;
369     GpGraphics *graphics = NULL;
370     GpPen *pen = NULL;
371     HDC hdc = GetDC( hwnd );
372
373     /* make a graphics object and pen object */
374     ok(hdc != NULL, "Expected HDC to be initialized\n");
375
376     status = GdipCreateFromHDC(hdc, &graphics);
377     expect(Ok, status);
378     ok(graphics != NULL, "Expected graphics to be initialized\n");
379
380     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
381     expect(Ok, status);
382     ok(pen != NULL, "Expected pen to be initialized\n");
383
384     /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
385     status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
386     expect(InvalidParameter, status);
387
388     status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
389     expect(InvalidParameter, status);
390
391     status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
392     expect(InvalidParameter, status);
393
394     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
395     expect(InvalidParameter, status);
396
397     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
398     expect(InvalidParameter, status);
399
400     /* successful case */
401     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
402     expect(Ok, status);
403
404     GdipDeletePen(pen);
405     GdipDeleteGraphics(graphics);
406
407     ReleaseDC(hwnd, hdc);
408 }
409
410 static void test_GdipDrawArcI(void)
411 {
412     GpStatus status;
413     GpGraphics *graphics = NULL;
414     GpPen *pen = NULL;
415     HDC hdc = GetDC( hwnd );
416
417     /* make a graphics object and pen object */
418     ok(hdc != NULL, "Expected HDC to be initialized\n");
419
420     status = GdipCreateFromHDC(hdc, &graphics);
421     expect(Ok, status);
422     ok(graphics != NULL, "Expected graphics to be initialized\n");
423
424     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
425     expect(Ok, status);
426     ok(pen != NULL, "Expected pen to be initialized\n");
427
428     /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
429     status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
430     expect(InvalidParameter, status);
431
432     status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
433     expect(InvalidParameter, status);
434
435     status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
436     expect(InvalidParameter, status);
437
438     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
439     expect(InvalidParameter, status);
440
441     status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
442     expect(InvalidParameter, status);
443
444     /* successful case */
445     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
446     expect(Ok, status);
447
448     GdipDeletePen(pen);
449     GdipDeleteGraphics(graphics);
450
451     ReleaseDC(hwnd, hdc);
452 }
453
454 static void test_BeginContainer2(void)
455 {
456     GpMatrix *transform;
457     GpRectF clip;
458     REAL defClip[] = {5, 10, 15, 20};
459     REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
460     GraphicsContainer cont1, cont2, cont3, cont4;
461     CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
462     CompositingMode compmode, defCompmode = CompositingModeSourceOver;
463     InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
464     REAL scale, defScale = 17;
465     GpUnit unit, defUnit = UnitPixel;
466     PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
467     SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
468     UINT contrast, defContrast = 5;
469     TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
470
471     GpStatus status;
472     GpGraphics *graphics = NULL;
473     HDC hdc = GetDC( hwnd );
474
475     ok(hdc != NULL, "Expected HDC to be initialized\n");
476
477     status = GdipCreateFromHDC(hdc, &graphics);
478     expect(Ok, status);
479     ok(graphics != NULL, "Expected graphics to be initialized\n");
480
481     /* null graphics, null container */
482     status = GdipBeginContainer2(NULL, &cont1);
483     expect(InvalidParameter, status);
484
485     status = GdipBeginContainer2(graphics, NULL);
486     expect(InvalidParameter, status);
487
488     status = GdipEndContainer(NULL, cont1);
489     expect(InvalidParameter, status);
490
491     /* test all quality-related values */
492     GdipSetCompositingMode(graphics, defCompmode);
493     GdipSetCompositingQuality(graphics, defCompqual);
494     GdipSetInterpolationMode(graphics, defInterp);
495     GdipSetPageScale(graphics, defScale);
496     GdipSetPageUnit(graphics, defUnit);
497     GdipSetPixelOffsetMode(graphics, defOffsetmode);
498     GdipSetSmoothingMode(graphics, defSmoothmode);
499     GdipSetTextContrast(graphics, defContrast);
500     GdipSetTextRenderingHint(graphics, defTexthint);
501
502     status = GdipBeginContainer2(graphics, &cont1);
503     expect(Ok, status);
504
505     GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
506     GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
507     GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
508     GdipSetPageScale(graphics, 10);
509     GdipSetPageUnit(graphics, UnitDocument);
510     GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
511     GdipSetSmoothingMode(graphics, SmoothingModeNone);
512     GdipSetTextContrast(graphics, 7);
513     GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
514
515     status = GdipEndContainer(graphics, cont1);
516     expect(Ok, status);
517
518     GdipGetCompositingMode(graphics, &compmode);
519     ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
520
521     GdipGetCompositingQuality(graphics, &compqual);
522     ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
523
524     GdipGetInterpolationMode(graphics, &interp);
525     ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
526
527     GdipGetPageScale(graphics, &scale);
528     ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
529
530     GdipGetPageUnit(graphics, &unit);
531     ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
532
533     GdipGetPixelOffsetMode(graphics, &offsetmode);
534     ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
535
536     GdipGetSmoothingMode(graphics, &smoothmode);
537     ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
538
539     GdipGetTextContrast(graphics, &contrast);
540     ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
541
542     GdipGetTextRenderingHint(graphics, &texthint);
543     ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
544
545     /* test world transform */
546     status = GdipBeginContainer2(graphics, &cont1);
547     expect(Ok, status);
548
549     GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
550             defTrans[4], defTrans[5], &transform);
551     GdipSetWorldTransform(graphics, transform);
552     GdipDeleteMatrix(transform);
553     transform = NULL;
554
555     status = GdipBeginContainer2(graphics, &cont2);
556     expect(Ok, status);
557
558     GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
559     GdipSetWorldTransform(graphics, transform);
560     GdipDeleteMatrix(transform);
561     transform = NULL;
562
563     status = GdipEndContainer(graphics, cont2);
564     expect(Ok, status);
565
566     GdipCreateMatrix(&transform);
567     GdipGetWorldTransform(graphics, transform);
568     GdipGetMatrixElements(transform, elems);
569     ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
570             fabs(defTrans[1] - elems[1]) < 0.0001 &&
571             fabs(defTrans[2] - elems[2]) < 0.0001 &&
572             fabs(defTrans[3] - elems[3]) < 0.0001 &&
573             fabs(defTrans[4] - elems[4]) < 0.0001 &&
574             fabs(defTrans[5] - elems[5]) < 0.0001,
575             "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
576             defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
577             elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
578     GdipDeleteMatrix(transform);
579     transform = NULL;
580
581     status = GdipEndContainer(graphics, cont1);
582     expect(Ok, status);
583
584     /* test clipping */
585     status = GdipBeginContainer2(graphics, &cont1);
586     expect(Ok, status);
587
588     GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
589
590     status = GdipBeginContainer2(graphics, &cont2);
591     expect(Ok, status);
592
593     GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
594
595     status = GdipEndContainer(graphics, cont2);
596     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_GdipDrawImagePointsRect(void)
1134 {
1135     GpStatus status;
1136     GpGraphics *graphics = NULL;
1137     GpPointF ptf[4];
1138     GpBitmap *bm = NULL;
1139     BYTE rbmi[sizeof(BITMAPINFOHEADER)];
1140     BYTE buff[400];
1141     BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
1142     HDC hdc = GetDC( hwnd );
1143     if (!hdc)
1144         return;
1145
1146     memset(rbmi, 0, sizeof(rbmi));
1147     bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1148     bmi->bmiHeader.biWidth = 10;
1149     bmi->bmiHeader.biHeight = 10;
1150     bmi->bmiHeader.biPlanes = 1;
1151     bmi->bmiHeader.biBitCount = 32;
1152     bmi->bmiHeader.biCompression = BI_RGB;
1153     status = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
1154     expect(Ok, status);
1155     ok(NULL != bm, "Expected bitmap to be initialized\n");
1156     status = GdipCreateFromHDC(hdc, &graphics);
1157     expect(Ok, status);
1158     ptf[0].X = 0;
1159     ptf[0].Y = 0;
1160     ptf[1].X = 10;
1161     ptf[1].Y = 0;
1162     ptf[2].X = 0;
1163     ptf[2].Y = 10;
1164     ptf[3].X = 10;
1165     ptf[3].Y = 10;
1166     status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 4, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1167     expect(NotImplemented, status);
1168     status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 2, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1169     expect(InvalidParameter, status);
1170     status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1171     expect(Ok, status);
1172     status = GdipDrawImagePointsRect(graphics, NULL, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1173     expect(InvalidParameter, status);
1174     status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, NULL, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1175     expect(InvalidParameter, status);
1176     status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 0, 0, UnitPixel, NULL, NULL, NULL);
1177     expect(Ok, status);
1178     memset(ptf, 0, sizeof(ptf));
1179     status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1180     expect(Ok, status);
1181
1182     GdipDisposeImage((GpImage*)bm);
1183     GdipDeleteGraphics(graphics);
1184     ReleaseDC(hwnd, hdc);
1185 }
1186
1187 static void test_GdipDrawLinesI(void)
1188 {
1189     GpStatus status;
1190     GpGraphics *graphics = NULL;
1191     GpPen *pen = NULL;
1192     GpPoint *ptf = NULL;
1193     HDC hdc = GetDC( hwnd );
1194
1195     /* make a graphics object and pen object */
1196     ok(hdc != NULL, "Expected HDC to be initialized\n");
1197
1198     status = GdipCreateFromHDC(hdc, &graphics);
1199     expect(Ok, status);
1200     ok(graphics != NULL, "Expected graphics to be initialized\n");
1201
1202     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1203     expect(Ok, status);
1204     ok(pen != NULL, "Expected pen to be initialized\n");
1205
1206     /* make some arbitrary valid points*/
1207     ptf = GdipAlloc(2 * sizeof(GpPointF));
1208
1209     ptf[0].X = 1;
1210     ptf[0].Y = 1;
1211
1212     ptf[1].X = 2;
1213     ptf[1].Y = 2;
1214
1215     /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1216     status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1217     expect(InvalidParameter, status);
1218
1219     status = GdipDrawLinesI(graphics, pen, ptf, 0);
1220     expect(InvalidParameter, status);
1221
1222     status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1223     expect(InvalidParameter, status);
1224
1225     status = GdipDrawLinesI(NULL, pen, ptf, 2);
1226     expect(InvalidParameter, status);
1227
1228     /* successful case */
1229     status = GdipDrawLinesI(graphics, pen, ptf, 2);
1230     expect(Ok, status);
1231
1232     GdipFree(ptf);
1233     GdipDeletePen(pen);
1234     GdipDeleteGraphics(graphics);
1235
1236     ReleaseDC(hwnd, hdc);
1237 }
1238
1239 static void test_GdipFillClosedCurve(void)
1240 {
1241     GpStatus status;
1242     GpGraphics *graphics = NULL;
1243     GpSolidFill *brush = NULL;
1244     HDC hdc = GetDC( hwnd );
1245     GpPointF points[3];
1246
1247     points[0].X = 0;
1248     points[0].Y = 0;
1249
1250     points[1].X = 40;
1251     points[1].Y = 20;
1252
1253     points[2].X = 10;
1254     points[2].Y = 40;
1255
1256     /* make a graphics object and brush object */
1257     ok(hdc != NULL, "Expected HDC to be initialized\n");
1258
1259     status = GdipCreateFromHDC(hdc, &graphics);
1260     expect(Ok, status);
1261     ok(graphics != NULL, "Expected graphics to be initialized\n");
1262
1263     GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1264
1265     /* InvalidParameter cases: null graphics, null brush, null points */
1266     status = GdipFillClosedCurve(NULL, NULL, NULL, 3);
1267     expect(InvalidParameter, status);
1268
1269     status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1270     expect(InvalidParameter, status);
1271
1272     status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1273     expect(InvalidParameter, status);
1274
1275     status = GdipFillClosedCurve(NULL, NULL, points, 3);
1276     expect(InvalidParameter, status);
1277
1278     status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1279     expect(InvalidParameter, status);
1280
1281     status = GdipFillClosedCurve(graphics, NULL, points, 3);
1282     expect(InvalidParameter, status);
1283
1284     status = GdipFillClosedCurve(NULL, (GpBrush*)brush, points, 3);
1285     expect(InvalidParameter, status);
1286
1287     /* InvalidParameter cases: invalid count */
1288     status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1289     expect(InvalidParameter, status);
1290
1291     status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1292     expect(InvalidParameter, status);
1293
1294     /* Valid test cases */
1295     status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1296     expect(Ok, status);
1297
1298     status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1299     expect(Ok, status);
1300
1301     status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1302     expect(Ok, status);
1303
1304     GdipDeleteGraphics(graphics);
1305     GdipDeleteBrush((GpBrush*)brush);
1306
1307     ReleaseDC(hwnd, hdc);
1308 }
1309
1310 static void test_GdipFillClosedCurveI(void)
1311 {
1312     GpStatus status;
1313     GpGraphics *graphics = NULL;
1314     GpSolidFill *brush = NULL;
1315     HDC hdc = GetDC( hwnd );
1316     GpPoint points[3];
1317
1318     points[0].X = 0;
1319     points[0].Y = 0;
1320
1321     points[1].X = 40;
1322     points[1].Y = 20;
1323
1324     points[2].X = 10;
1325     points[2].Y = 40;
1326
1327     /* make a graphics object and brush object */
1328     ok(hdc != NULL, "Expected HDC to be initialized\n");
1329
1330     status = GdipCreateFromHDC(hdc, &graphics);
1331     expect(Ok, status);
1332     ok(graphics != NULL, "Expected graphics to be initialized\n");
1333
1334     GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1335
1336     /* InvalidParameter cases: null graphics, null brush */
1337     /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
1338              when points == NULL, so don't test this condition */
1339     status = GdipFillClosedCurveI(NULL, NULL, points, 3);
1340     expect(InvalidParameter, status);
1341
1342     status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1343     expect(InvalidParameter, status);
1344
1345     status = GdipFillClosedCurveI(NULL, (GpBrush*)brush, points, 3);
1346     expect(InvalidParameter, status);
1347
1348     /* InvalidParameter cases: invalid count */
1349     status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1350     expect(InvalidParameter, status);
1351
1352     /* OutOfMemory cases: large (unsigned) int */
1353     status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1354     expect(OutOfMemory, status);
1355
1356     /* Valid test cases */
1357     status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1358     expect(Ok, status);
1359
1360     status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1361     expect(Ok, status);
1362
1363     status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1364     expect(Ok, status);
1365
1366     GdipDeleteGraphics(graphics);
1367     GdipDeleteBrush((GpBrush*)brush);
1368
1369     ReleaseDC(hwnd, hdc);
1370 }
1371
1372 static void test_Get_Release_DC(void)
1373 {
1374     GpStatus status;
1375     GpGraphics *graphics = NULL;
1376     GpPen *pen;
1377     GpSolidFill *brush;
1378     GpPath *path;
1379     HDC hdc = GetDC( hwnd );
1380     HDC retdc;
1381     REAL r;
1382     CompositingQuality quality;
1383     CompositingMode compmode;
1384     InterpolationMode intmode;
1385     GpMatrix *m;
1386     GpRegion *region;
1387     GpUnit unit;
1388     PixelOffsetMode offsetmode;
1389     SmoothingMode smoothmode;
1390     TextRenderingHint texthint;
1391     GpPointF ptf[5];
1392     GpPoint  pt[5];
1393     GpRectF  rectf[2];
1394     GpRect   rect[2];
1395     GpRegion *clip;
1396     INT i;
1397     BOOL res;
1398     ARGB color = 0x00000000;
1399     HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1400
1401     pt[0].X = 10;
1402     pt[0].Y = 10;
1403     pt[1].X = 20;
1404     pt[1].Y = 15;
1405     pt[2].X = 40;
1406     pt[2].Y = 80;
1407     pt[3].X = -20;
1408     pt[3].Y = 20;
1409     pt[4].X = 50;
1410     pt[4].Y = 110;
1411
1412     for(i = 0; i < 5;i++){
1413         ptf[i].X = (REAL)pt[i].X;
1414         ptf[i].Y = (REAL)pt[i].Y;
1415     }
1416
1417     rect[0].X = 0;
1418     rect[0].Y = 0;
1419     rect[0].Width  = 50;
1420     rect[0].Height = 70;
1421     rect[1].X = 0;
1422     rect[1].Y = 0;
1423     rect[1].Width  = 10;
1424     rect[1].Height = 20;
1425
1426     for(i = 0; i < 2;i++){
1427         rectf[i].X = (REAL)rect[i].X;
1428         rectf[i].Y = (REAL)rect[i].Y;
1429         rectf[i].Height = (REAL)rect[i].Height;
1430         rectf[i].Width  = (REAL)rect[i].Width;
1431     }
1432
1433     GdipCreateMatrix(&m);
1434     GdipCreateRegion(&region);
1435     GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1436     GdipCreatePath(FillModeAlternate, &path);
1437     GdipCreateRegion(&clip);
1438
1439     status = GdipCreateFromHDC(hdc, &graphics);
1440     expect(Ok, status);
1441     ok(graphics != NULL, "Expected graphics to be initialized\n");
1442     status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1443     expect(Ok, status);
1444
1445     /* NULL arguments */
1446     status = GdipGetDC(NULL, NULL);
1447     expect(InvalidParameter, status);
1448     status = GdipGetDC(graphics, NULL);
1449     expect(InvalidParameter, status);
1450     status = GdipGetDC(NULL, &retdc);
1451     expect(InvalidParameter, status);
1452
1453     status = GdipReleaseDC(NULL, NULL);
1454     expect(InvalidParameter, status);
1455     status = GdipReleaseDC(graphics, NULL);
1456     expect(InvalidParameter, status);
1457     status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1458     expect(InvalidParameter, status);
1459
1460     /* Release without Get */
1461     status = GdipReleaseDC(graphics, hdc);
1462     expect(InvalidParameter, status);
1463
1464     retdc = NULL;
1465     status = GdipGetDC(graphics, &retdc);
1466     expect(Ok, status);
1467     ok(retdc == hdc, "Invalid HDC returned\n");
1468     /* call it once more */
1469     status = GdipGetDC(graphics, &retdc);
1470     expect(ObjectBusy, status);
1471
1472     /* try all Graphics calls here */
1473     status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1474     expect(ObjectBusy, status);
1475     status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1476     expect(ObjectBusy, status);
1477     status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1478     expect(ObjectBusy, status);
1479     status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1480     expect(ObjectBusy, status);
1481     status = GdipDrawBeziers(graphics, pen, ptf, 5);
1482     expect(ObjectBusy, status);
1483     status = GdipDrawBeziersI(graphics, pen, pt, 5);
1484     expect(ObjectBusy, status);
1485     status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1486     expect(ObjectBusy, status);
1487     status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1488     expect(ObjectBusy, status);
1489     status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1490     expect(ObjectBusy, status);
1491     status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1492     expect(ObjectBusy, status);
1493     status = GdipDrawCurve(graphics, pen, ptf, 5);
1494     expect(ObjectBusy, status);
1495     status = GdipDrawCurveI(graphics, pen, pt, 5);
1496     expect(ObjectBusy, status);
1497     status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1498     expect(ObjectBusy, status);
1499     status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1500     expect(ObjectBusy, status);
1501     status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1502     expect(ObjectBusy, status);
1503     status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1504     expect(ObjectBusy, status);
1505     /* GdipDrawImage/GdipDrawImageI */
1506     /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1507     /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1508     /* GdipDrawImageRect/GdipDrawImageRectI */
1509     status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1510     expect(ObjectBusy, status);
1511     status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1512     expect(ObjectBusy, status);
1513     status = GdipDrawLines(graphics, pen, ptf, 5);
1514     expect(ObjectBusy, status);
1515     status = GdipDrawLinesI(graphics, pen, pt, 5);
1516     expect(ObjectBusy, status);
1517     status = GdipDrawPath(graphics, pen, path);
1518     expect(ObjectBusy, status);
1519     status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1520     expect(ObjectBusy, status);
1521     status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1522     expect(ObjectBusy, status);
1523     status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1524     expect(ObjectBusy, status);
1525     status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1526     expect(ObjectBusy, status);
1527     status = GdipDrawRectangles(graphics, pen, rectf, 2);
1528     expect(ObjectBusy, status);
1529     status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1530     expect(ObjectBusy, status);
1531     /* GdipDrawString */
1532     status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1533     expect(ObjectBusy, status);
1534     status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1535     expect(ObjectBusy, status);
1536     status = GdipFillClosedCurve(graphics, (GpBrush*)brush, ptf, 5);
1537     expect(ObjectBusy, status);
1538     status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, pt, 5);
1539     expect(ObjectBusy, status);
1540     status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1541     expect(ObjectBusy, status);
1542     status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1543     expect(ObjectBusy, status);
1544     status = GdipFillPath(graphics, (GpBrush*)brush, path);
1545     expect(ObjectBusy, status);
1546     status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1547     expect(ObjectBusy, status);
1548     status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1549     expect(ObjectBusy, status);
1550     status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1551     expect(ObjectBusy, status);
1552     status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1553     expect(ObjectBusy, status);
1554     status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1555     expect(ObjectBusy, status);
1556     status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1557     expect(ObjectBusy, status);
1558     status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1559     expect(ObjectBusy, status);
1560     status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1561     expect(ObjectBusy, status);
1562     status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1563     expect(ObjectBusy, status);
1564     status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1565     expect(ObjectBusy, status);
1566     status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1567     expect(ObjectBusy, status);
1568     status = GdipFlush(graphics, FlushIntentionFlush);
1569     expect(ObjectBusy, status);
1570     status = GdipGetClipBounds(graphics, rectf);
1571     expect(ObjectBusy, status);
1572     status = GdipGetClipBoundsI(graphics, rect);
1573     expect(ObjectBusy, status);
1574     status = GdipGetCompositingMode(graphics, &compmode);
1575     expect(ObjectBusy, status);
1576     status = GdipGetCompositingQuality(graphics, &quality);
1577     expect(ObjectBusy, status);
1578     status = GdipGetInterpolationMode(graphics, &intmode);
1579     expect(ObjectBusy, status);
1580     status = GdipGetNearestColor(graphics, &color);
1581     expect(ObjectBusy, status);
1582     status = GdipGetPageScale(graphics, &r);
1583     expect(ObjectBusy, status);
1584     status = GdipGetPageUnit(graphics, &unit);
1585     expect(ObjectBusy, status);
1586     status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1587     expect(ObjectBusy, status);
1588     status = GdipGetSmoothingMode(graphics, &smoothmode);
1589     expect(ObjectBusy, status);
1590     status = GdipGetTextRenderingHint(graphics, &texthint);
1591     expect(ObjectBusy, status);
1592     status = GdipGetWorldTransform(graphics, m);
1593     expect(ObjectBusy, status);
1594     status = GdipGraphicsClear(graphics, 0xdeadbeef);
1595     expect(ObjectBusy, status);
1596     status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1597     expect(ObjectBusy, status);
1598     status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1599     expect(ObjectBusy, status);
1600     /* GdipMeasureCharacterRanges */
1601     /* GdipMeasureString */
1602     status = GdipResetClip(graphics);
1603     expect(ObjectBusy, status);
1604     status = GdipResetWorldTransform(graphics);
1605     expect(ObjectBusy, status);
1606     /* GdipRestoreGraphics */
1607     status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1608     expect(ObjectBusy, status);
1609     /*  GdipSaveGraphics */
1610     status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1611     expect(ObjectBusy, status);
1612     status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1613     expect(ObjectBusy, status);
1614     status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1615     expect(ObjectBusy, status);
1616     status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1617     expect(ObjectBusy, status);
1618     status = GdipSetPageScale(graphics, 1.0);
1619     expect(ObjectBusy, status);
1620     status = GdipSetPageUnit(graphics, UnitWorld);
1621     expect(ObjectBusy, status);
1622     status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1623     expect(ObjectBusy, status);
1624     status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1625     expect(ObjectBusy, status);
1626     status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1627     expect(ObjectBusy, status);
1628     status = GdipSetWorldTransform(graphics, m);
1629     expect(ObjectBusy, status);
1630     status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1631     expect(ObjectBusy, status);
1632     status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1633     expect(ObjectBusy, status);
1634     status = GdipSetClipPath(graphics, path, CombineModeReplace);
1635     expect(ObjectBusy, status);
1636     status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1637     expect(ObjectBusy, status);
1638     status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1639     expect(ObjectBusy, status);
1640     status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1641     expect(ObjectBusy, status);
1642     status = GdipTranslateClip(graphics, 0.0, 0.0);
1643     expect(ObjectBusy, status);
1644     status = GdipTranslateClipI(graphics, 0, 0);
1645     expect(ObjectBusy, status);
1646     status = GdipDrawPolygon(graphics, pen, ptf, 5);
1647     expect(ObjectBusy, status);
1648     status = GdipDrawPolygonI(graphics, pen, pt, 5);
1649     expect(ObjectBusy, status);
1650     status = GdipGetDpiX(graphics, &r);
1651     expect(ObjectBusy, status);
1652     status = GdipGetDpiY(graphics, &r);
1653     expect(ObjectBusy, status);
1654     status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1655     expect(ObjectBusy, status);
1656     status = GdipGetClip(graphics, region);
1657     expect(ObjectBusy, status);
1658     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1659     expect(ObjectBusy, status);
1660
1661     /* try to delete before release */
1662     status = GdipDeleteGraphics(graphics);
1663     expect(ObjectBusy, status);
1664
1665     status = GdipReleaseDC(graphics, retdc);
1666     expect(Ok, status);
1667
1668     GdipDeletePen(pen);
1669     GdipDeleteGraphics(graphics);
1670
1671     GdipDeleteRegion(clip);
1672     GdipDeletePath(path);
1673     GdipDeleteBrush((GpBrush*)brush);
1674     GdipDeleteRegion(region);
1675     GdipDeleteMatrix(m);
1676     DeleteObject(hrgn);
1677
1678     ReleaseDC(hwnd, hdc);
1679 }
1680
1681 static void test_transformpoints(void)
1682 {
1683     GpStatus status;
1684     GpGraphics *graphics = NULL;
1685     HDC hdc = GetDC( hwnd );
1686     GpPointF ptf[2];
1687     GpPoint pt[2];
1688
1689     status = GdipCreateFromHDC(hdc, &graphics);
1690     expect(Ok, status);
1691
1692     /* NULL arguments */
1693     status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1694     expect(InvalidParameter, status);
1695     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1696     expect(InvalidParameter, status);
1697     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1698     expect(InvalidParameter, status);
1699     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1700     expect(InvalidParameter, status);
1701
1702     ptf[0].X = 1.0;
1703     ptf[0].Y = 0.0;
1704     ptf[1].X = 0.0;
1705     ptf[1].Y = 1.0;
1706     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1707     expect(Ok, status);
1708     expectf(1.0, ptf[0].X);
1709     expectf(0.0, ptf[0].Y);
1710     expectf(0.0, ptf[1].X);
1711     expectf(1.0, ptf[1].Y);
1712
1713     status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1714     expect(Ok, status);
1715     status = GdipSetPageUnit(graphics, UnitPixel);
1716     expect(Ok, status);
1717     status = GdipSetPageScale(graphics, 3.0);
1718     expect(Ok, status);
1719
1720     ptf[0].X = 1.0;
1721     ptf[0].Y = 0.0;
1722     ptf[1].X = 0.0;
1723     ptf[1].Y = 1.0;
1724     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1725     expect(Ok, status);
1726     expectf(18.0, ptf[0].X);
1727     expectf(15.0, ptf[0].Y);
1728     expectf(15.0, ptf[1].X);
1729     expectf(18.0, ptf[1].Y);
1730
1731     ptf[0].X = 1.0;
1732     ptf[0].Y = 0.0;
1733     ptf[1].X = 0.0;
1734     ptf[1].Y = 1.0;
1735     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1736     expect(Ok, status);
1737     expectf(6.0, ptf[0].X);
1738     expectf(5.0, ptf[0].Y);
1739     expectf(5.0, ptf[1].X);
1740     expectf(6.0, ptf[1].Y);
1741
1742     ptf[0].X = 1.0;
1743     ptf[0].Y = 0.0;
1744     ptf[1].X = 0.0;
1745     ptf[1].Y = 1.0;
1746     status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1747     expect(Ok, status);
1748     expectf(3.0, ptf[0].X);
1749     expectf(0.0, ptf[0].Y);
1750     expectf(0.0, ptf[1].X);
1751     expectf(3.0, ptf[1].Y);
1752
1753     ptf[0].X = 18.0;
1754     ptf[0].Y = 15.0;
1755     ptf[1].X = 15.0;
1756     ptf[1].Y = 18.0;
1757     status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1758     expect(Ok, status);
1759     expectf(1.0, ptf[0].X);
1760     expectf(0.0, ptf[0].Y);
1761     expectf(0.0, ptf[1].X);
1762     expectf(1.0, ptf[1].Y);
1763
1764     ptf[0].X = 6.0;
1765     ptf[0].Y = 5.0;
1766     ptf[1].X = 5.0;
1767     ptf[1].Y = 6.0;
1768     status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1769     expect(Ok, status);
1770     expectf(1.0, ptf[0].X);
1771     expectf(0.0, ptf[0].Y);
1772     expectf(0.0, ptf[1].X);
1773     expectf(1.0, ptf[1].Y);
1774
1775     ptf[0].X = 3.0;
1776     ptf[0].Y = 0.0;
1777     ptf[1].X = 0.0;
1778     ptf[1].Y = 3.0;
1779     status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1780     expect(Ok, status);
1781     expectf(1.0, ptf[0].X);
1782     expectf(0.0, ptf[0].Y);
1783     expectf(0.0, ptf[1].X);
1784     expectf(1.0, ptf[1].Y);
1785
1786     pt[0].X = 1;
1787     pt[0].Y = 0;
1788     pt[1].X = 0;
1789     pt[1].Y = 1;
1790     status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1791     expect(Ok, status);
1792     expect(18, pt[0].X);
1793     expect(15, pt[0].Y);
1794     expect(15, pt[1].X);
1795     expect(18, pt[1].Y);
1796
1797     GdipDeleteGraphics(graphics);
1798     ReleaseDC(hwnd, hdc);
1799 }
1800
1801 static void test_get_set_clip(void)
1802 {
1803     GpStatus status;
1804     GpGraphics *graphics = NULL;
1805     HDC hdc = GetDC( hwnd );
1806     GpRegion *clip;
1807     GpRectF rect;
1808     BOOL res;
1809
1810     status = GdipCreateFromHDC(hdc, &graphics);
1811     expect(Ok, status);
1812
1813     rect.X = rect.Y = 0.0;
1814     rect.Height = rect.Width = 100.0;
1815
1816     status = GdipCreateRegionRect(&rect, &clip);
1817     expect(Ok, status);
1818
1819     /* NULL arguments */
1820     status = GdipGetClip(NULL, NULL);
1821     expect(InvalidParameter, status);
1822     status = GdipGetClip(graphics, NULL);
1823     expect(InvalidParameter, status);
1824     status = GdipGetClip(NULL, clip);
1825     expect(InvalidParameter, status);
1826
1827     status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1828     expect(InvalidParameter, status);
1829     status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1830     expect(InvalidParameter, status);
1831
1832     status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
1833     expect(InvalidParameter, status);
1834     status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
1835     expect(InvalidParameter, status);
1836
1837     res = FALSE;
1838     status = GdipGetClip(graphics, clip);
1839     expect(Ok, status);
1840     status = GdipIsInfiniteRegion(clip, graphics, &res);
1841     expect(Ok, status);
1842     expect(TRUE, res);
1843
1844     /* remains infinite after reset */
1845     res = FALSE;
1846     status = GdipResetClip(graphics);
1847     expect(Ok, status);
1848     status = GdipGetClip(graphics, clip);
1849     expect(Ok, status);
1850     status = GdipIsInfiniteRegion(clip, graphics, &res);
1851     expect(Ok, status);
1852     expect(TRUE, res);
1853
1854     /* set to empty and then reset to infinite */
1855     status = GdipSetEmpty(clip);
1856     expect(Ok, status);
1857     status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1858     expect(Ok, status);
1859
1860     status = GdipGetClip(graphics, clip);
1861     expect(Ok, status);
1862     res = FALSE;
1863     status = GdipIsEmptyRegion(clip, graphics, &res);
1864     expect(Ok, status);
1865     expect(TRUE, res);
1866     status = GdipResetClip(graphics);
1867     expect(Ok, status);
1868     status = GdipGetClip(graphics, clip);
1869     expect(Ok, status);
1870     res = FALSE;
1871     status = GdipIsInfiniteRegion(clip, graphics, &res);
1872     expect(Ok, status);
1873     expect(TRUE, res);
1874
1875     GdipDeleteRegion(clip);
1876
1877     GdipDeleteGraphics(graphics);
1878     ReleaseDC(hwnd, hdc);
1879 }
1880
1881 static void test_isempty(void)
1882 {
1883     GpStatus status;
1884     GpGraphics *graphics = NULL;
1885     HDC hdc = GetDC( hwnd );
1886     GpRegion *clip;
1887     BOOL res;
1888
1889     status = GdipCreateFromHDC(hdc, &graphics);
1890     expect(Ok, status);
1891
1892     status = GdipCreateRegion(&clip);
1893     expect(Ok, status);
1894
1895     /* NULL */
1896     status = GdipIsClipEmpty(NULL, NULL);
1897     expect(InvalidParameter, status);
1898     status = GdipIsClipEmpty(graphics, NULL);
1899     expect(InvalidParameter, status);
1900     status = GdipIsClipEmpty(NULL, &res);
1901     expect(InvalidParameter, status);
1902
1903     /* default is infinite */
1904     res = TRUE;
1905     status = GdipIsClipEmpty(graphics, &res);
1906     expect(Ok, status);
1907     expect(FALSE, res);
1908
1909     GdipDeleteRegion(clip);
1910
1911     GdipDeleteGraphics(graphics);
1912     ReleaseDC(hwnd, hdc);
1913 }
1914
1915 static void test_clear(void)
1916 {
1917     GpStatus status;
1918
1919     status = GdipGraphicsClear(NULL, 0xdeadbeef);
1920     expect(InvalidParameter, status);
1921 }
1922
1923 static void test_textcontrast(void)
1924 {
1925     GpStatus status;
1926     HDC hdc = GetDC( hwnd );
1927     GpGraphics *graphics;
1928     UINT contrast;
1929
1930     status = GdipGetTextContrast(NULL, NULL);
1931     expect(InvalidParameter, status);
1932
1933     status = GdipCreateFromHDC(hdc, &graphics);
1934     expect(Ok, status);
1935
1936     status = GdipGetTextContrast(graphics, NULL);
1937     expect(InvalidParameter, status);
1938     status = GdipGetTextContrast(graphics, &contrast);
1939     expect(Ok, status);
1940     expect(4, contrast);
1941
1942     GdipDeleteGraphics(graphics);
1943     ReleaseDC(hwnd, hdc);
1944 }
1945
1946 static void test_GdipDrawString(void)
1947 {
1948     GpStatus status;
1949     GpGraphics *graphics = NULL;
1950     GpFont *fnt = NULL;
1951     RectF  rect;
1952     GpStringFormat *format;
1953     GpBrush *brush;
1954     LOGFONTA logfont;
1955     HDC hdc = GetDC( hwnd );
1956     static const WCHAR string[] = {'T','e','s','t',0};
1957     static const PointF positions[4] = {{0,0}, {1,1}, {2,2}, {3,3}};
1958     GpMatrix *matrix;
1959
1960     memset(&logfont,0,sizeof(logfont));
1961     strcpy(logfont.lfFaceName,"Arial");
1962     logfont.lfHeight = 12;
1963     logfont.lfCharSet = DEFAULT_CHARSET;
1964
1965     status = GdipCreateFromHDC(hdc, &graphics);
1966     expect(Ok, status);
1967
1968     status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
1969     if (status == FileNotFound)
1970     {
1971         skip("Arial not installed.\n");
1972         return;
1973     }
1974     expect(Ok, status);
1975
1976     status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
1977     expect(Ok, status);
1978
1979     status = GdipCreateStringFormat(0,0,&format);
1980     expect(Ok, status);
1981
1982     rect.X = 0;
1983     rect.Y = 0;
1984     rect.Width = 0;
1985     rect.Height = 12;
1986
1987     status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
1988     expect(Ok, status);
1989
1990     status = GdipCreateMatrix(&matrix);
1991     expect(Ok, status);
1992
1993 todo_wine {
1994     status = GdipDrawDriverString(NULL, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
1995     expect(InvalidParameter, status);
1996
1997     status = GdipDrawDriverString(graphics, NULL, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
1998     expect(InvalidParameter, status);
1999
2000     status = GdipDrawDriverString(graphics, string, 4, NULL, brush, positions, DriverStringOptionsCmapLookup, matrix);
2001     expect(InvalidParameter, status);
2002
2003     status = GdipDrawDriverString(graphics, string, 4, fnt, NULL, positions, DriverStringOptionsCmapLookup, matrix);
2004     expect(InvalidParameter, status);
2005
2006     status = GdipDrawDriverString(graphics, string, 4, fnt, brush, NULL, DriverStringOptionsCmapLookup, matrix);
2007     expect(InvalidParameter, status);
2008
2009     status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup|0x10, matrix);
2010     expect(Ok, status);
2011
2012     status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, NULL);
2013     expect(Ok, status);
2014
2015     status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2016     expect(Ok, status);
2017 }
2018
2019     GdipDeleteMatrix(matrix);
2020     GdipDeleteGraphics(graphics);
2021     GdipDeleteBrush(brush);
2022     GdipDeleteFont(fnt);
2023     GdipDeleteStringFormat(format);
2024
2025     ReleaseDC(hwnd, hdc);
2026 }
2027
2028 static void test_GdipGetVisibleClipBounds_screen(void)
2029 {
2030     GpStatus status;
2031     GpGraphics *graphics = NULL;
2032     HDC hdc = GetDC(0);
2033     GpRectF rectf, exp, clipr;
2034     GpRect recti;
2035
2036     ok(hdc != NULL, "Expected HDC to be initialized\n");
2037
2038     status = GdipCreateFromHDC(hdc, &graphics);
2039     expect(Ok, status);
2040     ok(graphics != NULL, "Expected graphics to be initialized\n");
2041
2042     /* no clipping rect */
2043     exp.X = 0;
2044     exp.Y = 0;
2045     exp.Width = GetDeviceCaps(hdc, HORZRES);
2046     exp.Height = GetDeviceCaps(hdc, VERTRES);
2047
2048     status = GdipGetVisibleClipBounds(graphics, &rectf);
2049     expect(Ok, status);
2050     ok(rectf.X == exp.X &&
2051         rectf.Y == exp.Y &&
2052         rectf.Width == exp.Width &&
2053         rectf.Height == exp.Height,
2054         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2055         "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2056         rectf.X, rectf.Y, rectf.Width, rectf.Height,
2057         exp.X, exp.Y, exp.Width, exp.Height);
2058
2059     /* clipping rect entirely within window */
2060     exp.X = clipr.X = 10;
2061     exp.Y = clipr.Y = 12;
2062     exp.Width = clipr.Width = 14;
2063     exp.Height = clipr.Height = 16;
2064
2065     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2066     expect(Ok, status);
2067
2068     status = GdipGetVisibleClipBounds(graphics, &rectf);
2069     expect(Ok, status);
2070     ok(rectf.X == exp.X &&
2071         rectf.Y == exp.Y &&
2072         rectf.Width == exp.Width &&
2073         rectf.Height == exp.Height,
2074         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2075         "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2076         rectf.X, rectf.Y, rectf.Width, rectf.Height,
2077         exp.X, exp.Y, exp.Width, exp.Height);
2078
2079     /* clipping rect partially outside of screen */
2080     clipr.X = -10;
2081     clipr.Y = -12;
2082     clipr.Width = 20;
2083     clipr.Height = 24;
2084
2085     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2086     expect(Ok, status);
2087
2088     exp.X = 0;
2089     exp.Y = 0;
2090     exp.Width = 10;
2091     exp.Height = 12;
2092
2093     status = GdipGetVisibleClipBounds(graphics, &rectf);
2094     expect(Ok, status);
2095     ok(rectf.X == exp.X &&
2096         rectf.Y == exp.Y &&
2097         rectf.Width == exp.Width &&
2098         rectf.Height == exp.Height,
2099         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2100         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2101         rectf.X, rectf.Y, rectf.Width, rectf.Height,
2102         exp.X, exp.Y, exp.Width, exp.Height);
2103
2104     status = GdipGetVisibleClipBoundsI(graphics, &recti);
2105     expect(Ok, status);
2106     ok(recti.X == exp.X &&
2107         recti.Y == exp.Y &&
2108         recti.Width == exp.Width &&
2109         recti.Height == exp.Height,
2110         "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2111         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2112         recti.X, recti.Y, recti.Width, recti.Height,
2113         exp.X, exp.Y, exp.Width, exp.Height);
2114
2115     GdipDeleteGraphics(graphics);
2116     ReleaseDC(0, hdc);
2117 }
2118
2119 static void test_GdipGetVisibleClipBounds_window(void)
2120 {
2121     GpStatus status;
2122     GpGraphics *graphics = NULL;
2123     GpRectF rectf, window, exp, clipr;
2124     GpRect recti;
2125     HDC hdc;
2126     PAINTSTRUCT ps;
2127     RECT wnd_rect;
2128
2129     /* get client area size */
2130     ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2131     window.X = wnd_rect.left;
2132     window.Y = wnd_rect.top;
2133     window.Width = wnd_rect.right - wnd_rect.left;
2134     window.Height = wnd_rect.bottom - wnd_rect.top;
2135
2136     hdc = BeginPaint(hwnd, &ps);
2137
2138     status = GdipCreateFromHDC(hdc, &graphics);
2139     expect(Ok, status);
2140     ok(graphics != NULL, "Expected graphics to be initialized\n");
2141
2142     status = GdipGetVisibleClipBounds(graphics, &rectf);
2143     expect(Ok, status);
2144     ok(rectf.X == window.X &&
2145         rectf.Y == window.Y &&
2146         rectf.Width == window.Width &&
2147         rectf.Height == window.Height,
2148         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2149         "the window (%0.f, %0.f, %0.f, %0.f)\n",
2150         rectf.X, rectf.Y, rectf.Width, rectf.Height,
2151         window.X, window.Y, window.Width, window.Height);
2152
2153     /* clipping rect entirely within window */
2154     exp.X = clipr.X = 20;
2155     exp.Y = clipr.Y = 8;
2156     exp.Width = clipr.Width = 30;
2157     exp.Height = clipr.Height = 20;
2158
2159     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2160     expect(Ok, status);
2161
2162     status = GdipGetVisibleClipBounds(graphics, &rectf);
2163     expect(Ok, status);
2164     ok(rectf.X == exp.X &&
2165         rectf.Y == exp.Y &&
2166         rectf.Width == exp.Width &&
2167         rectf.Height == exp.Height,
2168         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2169         "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2170         rectf.X, rectf.Y, rectf.Width, rectf.Height,
2171         exp.X, exp.Y, exp.Width, exp.Height);
2172
2173     /* clipping rect partially outside of window */
2174     clipr.X = window.Width - 10;
2175     clipr.Y = window.Height - 15;
2176     clipr.Width = 20;
2177     clipr.Height = 30;
2178
2179     status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2180     expect(Ok, status);
2181
2182     exp.X = window.Width - 10;
2183     exp.Y = window.Height - 15;
2184     exp.Width = 10;
2185     exp.Height = 15;
2186
2187     status = GdipGetVisibleClipBounds(graphics, &rectf);
2188     expect(Ok, status);
2189     ok(rectf.X == exp.X &&
2190         rectf.Y == exp.Y &&
2191         rectf.Width == exp.Width &&
2192         rectf.Height == exp.Height,
2193         "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2194         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2195         rectf.X, rectf.Y, rectf.Width, rectf.Height,
2196         exp.X, exp.Y, exp.Width, exp.Height);
2197
2198     status = GdipGetVisibleClipBoundsI(graphics, &recti);
2199     expect(Ok, status);
2200     ok(recti.X == exp.X &&
2201         recti.Y == exp.Y &&
2202         recti.Width == exp.Width &&
2203         recti.Height == exp.Height,
2204         "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2205         "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2206         recti.X, recti.Y, recti.Width, recti.Height,
2207         exp.X, exp.Y, exp.Width, exp.Height);
2208
2209     GdipDeleteGraphics(graphics);
2210     EndPaint(hwnd, &ps);
2211 }
2212
2213 static void test_GdipGetVisibleClipBounds(void)
2214 {
2215     GpGraphics* graphics = NULL;
2216     GpRectF rectf;
2217     GpRect rect;
2218     HDC hdc = GetDC( hwnd );
2219     GpStatus status;
2220
2221     status = GdipCreateFromHDC(hdc, &graphics);
2222     expect(Ok, status);
2223     ok(graphics != NULL, "Expected graphics to be initialized\n");
2224
2225     /* test null parameters */
2226     status = GdipGetVisibleClipBounds(graphics, NULL);
2227     expect(InvalidParameter, status);
2228
2229     status = GdipGetVisibleClipBounds(NULL, &rectf);
2230     expect(InvalidParameter, status);
2231
2232     status = GdipGetVisibleClipBoundsI(graphics, NULL);
2233     expect(InvalidParameter, status);
2234
2235     status = GdipGetVisibleClipBoundsI(NULL, &rect);
2236     expect(InvalidParameter, status);
2237
2238     GdipDeleteGraphics(graphics);
2239     ReleaseDC(hwnd, hdc);
2240
2241     test_GdipGetVisibleClipBounds_screen();
2242     test_GdipGetVisibleClipBounds_window();
2243 }
2244
2245 static void test_fromMemoryBitmap(void)
2246 {
2247     GpStatus status;
2248     GpGraphics *graphics = NULL;
2249     GpBitmap *bitmap = NULL;
2250     BYTE bits[48] = {0};
2251     HDC hdc=NULL;
2252     COLORREF color;
2253
2254     status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2255     expect(Ok, status);
2256
2257     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2258     expect(Ok, status);
2259
2260     status = GdipGraphicsClear(graphics, 0xff686868);
2261     expect(Ok, status);
2262
2263     GdipDeleteGraphics(graphics);
2264
2265     /* drawing writes to the memory provided */
2266     expect(0x68, bits[10]);
2267
2268     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2269     expect(Ok, status);
2270
2271     status = GdipGetDC(graphics, &hdc);
2272     expect(Ok, status);
2273     ok(hdc != NULL, "got NULL hdc\n");
2274
2275     color = GetPixel(hdc, 0, 0);
2276     /* The HDC is write-only, and native fills with a solid color to figure out
2277      * which pixels have changed. */
2278     todo_wine expect(0x0c0b0d, color);
2279
2280     SetPixel(hdc, 0, 0, 0x797979);
2281     SetPixel(hdc, 1, 0, 0x0c0b0d);
2282
2283     status = GdipReleaseDC(graphics, hdc);
2284     expect(Ok, status);
2285
2286     GdipDeleteGraphics(graphics);
2287
2288     expect(0x79, bits[0]);
2289     todo_wine expect(0x68, bits[3]);
2290
2291     GdipDisposeImage((GpImage*)bitmap);
2292
2293     /* We get the same kind of write-only HDC for a "normal" bitmap */
2294     status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2295     expect(Ok, status);
2296
2297     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2298     expect(Ok, status);
2299
2300     status = GdipGetDC(graphics, &hdc);
2301     expect(Ok, status);
2302     ok(hdc != NULL, "got NULL hdc\n");
2303
2304     color = GetPixel(hdc, 0, 0);
2305     todo_wine expect(0x0c0b0d, color);
2306
2307     status = GdipReleaseDC(graphics, hdc);
2308     expect(Ok, status);
2309
2310     GdipDeleteGraphics(graphics);
2311
2312     GdipDisposeImage((GpImage*)bitmap);
2313 }
2314
2315 static void test_GdipIsVisiblePoint(void)
2316 {
2317     GpStatus status;
2318     GpGraphics *graphics = NULL;
2319     HDC hdc = GetDC( hwnd );
2320     REAL x, y;
2321     BOOL val;
2322
2323     ok(hdc != NULL, "Expected HDC to be initialized\n");
2324
2325     status = GdipCreateFromHDC(hdc, &graphics);
2326     expect(Ok, status);
2327     ok(graphics != NULL, "Expected graphics to be initialized\n");
2328
2329     /* null parameters */
2330     status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2331     expect(InvalidParameter, status);
2332
2333     status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2334     expect(InvalidParameter, status);
2335
2336     status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2337     expect(InvalidParameter, status);
2338
2339     status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2340     expect(InvalidParameter, status);
2341
2342     x = 0;
2343     y = 0;
2344     status = GdipIsVisiblePoint(graphics, x, y, &val);
2345     expect(Ok, status);
2346     ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2347
2348     x = -10;
2349     y = 0;
2350     status = GdipIsVisiblePoint(graphics, x, y, &val);
2351     expect(Ok, status);
2352     ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2353
2354     x = 0;
2355     y = -5;
2356     status = GdipIsVisiblePoint(graphics, x, y, &val);
2357     expect(Ok, status);
2358     ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2359
2360     x = 1;
2361     y = 1;
2362     status = GdipIsVisiblePoint(graphics, x, y, &val);
2363     expect(Ok, status);
2364     ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2365
2366     status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2367     expect(Ok, status);
2368
2369     x = 1;
2370     y = 1;
2371     status = GdipIsVisiblePoint(graphics, x, y, &val);
2372     expect(Ok, status);
2373     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2374
2375     x = 15.5;
2376     y = 40.5;
2377     status = GdipIsVisiblePoint(graphics, x, y, &val);
2378     expect(Ok, status);
2379     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2380
2381     /* translate into the center of the rect */
2382     GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2383
2384     x = 0;
2385     y = 0;
2386     status = GdipIsVisiblePoint(graphics, x, y, &val);
2387     expect(Ok, status);
2388     ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2389
2390     x = 25;
2391     y = 40;
2392     status = GdipIsVisiblePoint(graphics, x, y, &val);
2393     expect(Ok, status);
2394     ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2395
2396     GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2397
2398     /* corner cases */
2399     x = 9;
2400     y = 19;
2401     status = GdipIsVisiblePoint(graphics, x, y, &val);
2402     expect(Ok, status);
2403     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2404
2405     x = 9.25;
2406     y = 19.25;
2407     status = GdipIsVisiblePoint(graphics, x, y, &val);
2408     expect(Ok, status);
2409     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2410
2411     x = 9.5;
2412     y = 19.5;
2413     status = GdipIsVisiblePoint(graphics, x, y, &val);
2414     expect(Ok, status);
2415     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2416
2417     x = 9.75;
2418     y = 19.75;
2419     status = GdipIsVisiblePoint(graphics, x, y, &val);
2420     expect(Ok, status);
2421     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2422
2423     x = 10;
2424     y = 20;
2425     status = GdipIsVisiblePoint(graphics, x, y, &val);
2426     expect(Ok, status);
2427     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2428
2429     x = 40;
2430     y = 20;
2431     status = GdipIsVisiblePoint(graphics, x, y, &val);
2432     expect(Ok, status);
2433     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2434
2435     x = 39;
2436     y = 59;
2437     status = GdipIsVisiblePoint(graphics, x, y, &val);
2438     expect(Ok, status);
2439     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2440
2441     x = 39.25;
2442     y = 59.25;
2443     status = GdipIsVisiblePoint(graphics, x, y, &val);
2444     expect(Ok, status);
2445     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2446
2447     x = 39.5;
2448     y = 39.5;
2449     status = GdipIsVisiblePoint(graphics, x, y, &val);
2450     expect(Ok, status);
2451     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2452
2453     x = 39.75;
2454     y = 59.75;
2455     status = GdipIsVisiblePoint(graphics, x, y, &val);
2456     expect(Ok, status);
2457     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2458
2459     x = 40;
2460     y = 60;
2461     status = GdipIsVisiblePoint(graphics, x, y, &val);
2462     expect(Ok, status);
2463     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2464
2465     x = 40.15;
2466     y = 60.15;
2467     status = GdipIsVisiblePoint(graphics, x, y, &val);
2468     expect(Ok, status);
2469     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2470
2471     x = 10;
2472     y = 60;
2473     status = GdipIsVisiblePoint(graphics, x, y, &val);
2474     expect(Ok, status);
2475     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2476
2477     /* integer version */
2478     x = 25;
2479     y = 30;
2480     status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2481     expect(Ok, status);
2482     ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2483
2484     x = 50;
2485     y = 100;
2486     status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2487     expect(Ok, status);
2488     ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2489
2490     GdipDeleteGraphics(graphics);
2491     ReleaseDC(hwnd, hdc);
2492 }
2493
2494 static void test_GdipIsVisibleRect(void)
2495 {
2496     GpStatus status;
2497     GpGraphics *graphics = NULL;
2498     HDC hdc = GetDC( hwnd );
2499     REAL x, y, width, height;
2500     BOOL val;
2501
2502     ok(hdc != NULL, "Expected HDC to be initialized\n");
2503
2504     status = GdipCreateFromHDC(hdc, &graphics);
2505     expect(Ok, status);
2506     ok(graphics != NULL, "Expected graphics to be initialized\n");
2507
2508     status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2509     expect(InvalidParameter, status);
2510
2511     status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2512     expect(InvalidParameter, status);
2513
2514     status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2515     expect(InvalidParameter, status);
2516
2517     status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2518     expect(InvalidParameter, status);
2519
2520     /* entirely within the visible region */
2521     x = 0; width = 10;
2522     y = 0; height = 10;
2523     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2524     expect(Ok, status);
2525     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2526
2527     /* partially outside */
2528     x = -10; width = 20;
2529     y = -10; height = 20;
2530     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2531     expect(Ok, status);
2532     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2533
2534     /* entirely outside */
2535     x = -10; width = 5;
2536     y = -10; height = 5;
2537     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2538     expect(Ok, status);
2539     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2540
2541     status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2542     expect(Ok, status);
2543
2544     /* entirely within the visible region */
2545     x = 12; width = 10;
2546     y = 22; height = 10;
2547     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2548     expect(Ok, status);
2549     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2550
2551     /* partially outside */
2552     x = 35; width = 10;
2553     y = 55; height = 10;
2554     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2555     expect(Ok, status);
2556     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2557
2558     /* entirely outside */
2559     x = 45; width = 5;
2560     y = 65; height = 5;
2561     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2562     expect(Ok, status);
2563     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2564
2565     /* translate into center of clipping rect */
2566     GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2567
2568     x = 0; width = 10;
2569     y = 0; height = 10;
2570     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2571     expect(Ok, status);
2572     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2573
2574     x = 25; width = 5;
2575     y = 40; height = 5;
2576     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2577     expect(Ok, status);
2578     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2579
2580     GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2581
2582     /* corners entirely outside, but some intersections */
2583     x = 0; width = 70;
2584     y = 0; height = 90;
2585     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2586     expect(Ok, status);
2587     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2588
2589     x = 0; width = 70;
2590     y = 0; height = 30;
2591     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2592     expect(Ok, status);
2593     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2594
2595     x = 0; width = 30;
2596     y = 0; height = 90;
2597     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2598     expect(Ok, status);
2599     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2600
2601     /* edge cases */
2602     x = 0; width = 10;
2603     y = 20; height = 40;
2604     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2605     expect(Ok, status);
2606     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2607
2608     x = 10; width = 30;
2609     y = 0; height = 20;
2610     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2611     expect(Ok, status);
2612     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2613
2614     x = 40; width = 10;
2615     y = 20; height = 40;
2616     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2617     expect(Ok, status);
2618     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2619
2620     x = 10; width = 30;
2621     y = 60; height = 10;
2622     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2623     expect(Ok, status);
2624     ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2625
2626     /* rounding tests */
2627     x = 0.4; width = 10.4;
2628     y = 20; height = 40;
2629     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2630     expect(Ok, status);
2631     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2632
2633     x = 10; width = 30;
2634     y = 0.4; height = 20.4;
2635     status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2636     expect(Ok, status);
2637     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2638
2639     /* integer version */
2640     x = 0; width = 30;
2641     y = 0; height = 90;
2642     status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2643     expect(Ok, status);
2644     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2645
2646     x = 12; width = 10;
2647     y = 22; height = 10;
2648     status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2649     expect(Ok, status);
2650     ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2651
2652     GdipDeleteGraphics(graphics);
2653     ReleaseDC(hwnd, hdc);
2654 }
2655
2656 static void test_GdipGetNearestColor(void)
2657 {
2658     GpStatus status;
2659     GpGraphics *graphics;
2660     GpBitmap *bitmap;
2661     ARGB color = 0xdeadbeef;
2662     HDC hdc = GetDC( hwnd );
2663
2664     /* create a graphics object */
2665     ok(hdc != NULL, "Expected HDC to be initialized\n");
2666
2667     status = GdipCreateFromHDC(hdc, &graphics);
2668     expect(Ok, status);
2669     ok(graphics != NULL, "Expected graphics to be initialized\n");
2670
2671     status = GdipGetNearestColor(graphics, NULL);
2672     expect(InvalidParameter, status);
2673
2674     status = GdipGetNearestColor(NULL, &color);
2675     expect(InvalidParameter, status);
2676     GdipDeleteGraphics(graphics);
2677
2678     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2679     expect(Ok, status);
2680     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2681     ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2682     if (status == Ok)
2683     {
2684         status = GdipGetNearestColor(graphics, &color);
2685         expect(Ok, status);
2686         expect(0xdeadbeef, color);
2687         GdipDeleteGraphics(graphics);
2688     }
2689     GdipDisposeImage((GpImage*)bitmap);
2690
2691     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2692     expect(Ok, status);
2693     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2694     ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2695     if (status == Ok)
2696     {
2697         status = GdipGetNearestColor(graphics, &color);
2698         expect(Ok, status);
2699         expect(0xdeadbeef, color);
2700         GdipDeleteGraphics(graphics);
2701     }
2702     GdipDisposeImage((GpImage*)bitmap);
2703
2704     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2705     expect(Ok, status);
2706     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2707     ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2708     if (status == Ok)
2709     {
2710         status = GdipGetNearestColor(graphics, &color);
2711         expect(Ok, status);
2712         expect(0xdeadbeef, color);
2713         GdipDeleteGraphics(graphics);
2714     }
2715     GdipDisposeImage((GpImage*)bitmap);
2716
2717     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2718     expect(Ok, status);
2719     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2720     todo_wine expect(OutOfMemory, status);
2721     if (status == Ok)
2722         GdipDeleteGraphics(graphics);
2723     GdipDisposeImage((GpImage*)bitmap);
2724
2725     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2726     expect(Ok, status);
2727     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2728     expect(Ok, status);
2729     status = GdipGetNearestColor(graphics, &color);
2730     expect(Ok, status);
2731     expect(0xdeadbeef, color);
2732     GdipDeleteGraphics(graphics);
2733     GdipDisposeImage((GpImage*)bitmap);
2734
2735     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2736     expect(Ok, status);
2737     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2738     expect(Ok, status);
2739     status = GdipGetNearestColor(graphics, &color);
2740     expect(Ok, status);
2741     expect(0xdeadbeef, color);
2742     GdipDeleteGraphics(graphics);
2743     GdipDisposeImage((GpImage*)bitmap);
2744
2745     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2746     expect(Ok, status);
2747     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2748     expect(Ok, status);
2749     status = GdipGetNearestColor(graphics, &color);
2750     expect(Ok, status);
2751     expect(0xdeadbeef, color);
2752     GdipDeleteGraphics(graphics);
2753     GdipDisposeImage((GpImage*)bitmap);
2754
2755     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2756     expect(Ok, status);
2757     if (status == Ok)
2758     {
2759         status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2760         expect(Ok, status);
2761         status = GdipGetNearestColor(graphics, &color);
2762         expect(Ok, status);
2763         expect(0xdeadbeef, color);
2764         GdipDeleteGraphics(graphics);
2765         GdipDisposeImage((GpImage*)bitmap);
2766     }
2767
2768     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2769     expect(Ok, status);
2770     if (status == Ok)
2771     {
2772         status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2773         expect(Ok, status);
2774         status = GdipGetNearestColor(graphics, &color);
2775         expect(Ok, status);
2776         expect(0xdeadbeef, color);
2777         GdipDeleteGraphics(graphics);
2778         GdipDisposeImage((GpImage*)bitmap);
2779     }
2780
2781     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2782     expect(Ok, status);
2783     if (status == Ok)
2784     {
2785         status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2786         expect(Ok, status);
2787         status = GdipGetNearestColor(graphics, &color);
2788         expect(Ok, status);
2789         expect(0xdeadbeef, color);
2790         GdipDeleteGraphics(graphics);
2791         GdipDisposeImage((GpImage*)bitmap);
2792     }
2793
2794     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
2795     expect(Ok, status);
2796     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2797     expect(Ok, status);
2798     status = GdipGetNearestColor(graphics, &color);
2799     expect(Ok, status);
2800     todo_wine expect(0xffa8bce8, color);
2801     GdipDeleteGraphics(graphics);
2802     GdipDisposeImage((GpImage*)bitmap);
2803
2804     status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
2805     expect(Ok, status);
2806     status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2807     expect(Ok, status);
2808     status = GdipGetNearestColor(graphics, &color);
2809     expect(Ok, status);
2810     todo_wine
2811     ok(color == 0xffa8b8e8 ||
2812        broken(color == 0xffa0b8e0), /* Win98/WinMe */
2813        "Expected ffa8b8e8, got %.8x\n", color);
2814     GdipDeleteGraphics(graphics);
2815     GdipDisposeImage((GpImage*)bitmap);
2816
2817     ReleaseDC(hwnd, hdc);
2818 }
2819
2820 static void test_string_functions(void)
2821 {
2822     GpStatus status;
2823     GpGraphics *graphics;
2824     GpFontFamily *family;
2825     GpFont *font;
2826     RectF rc, char_bounds, bounds;
2827     GpBrush *brush;
2828     ARGB color = 0xff000000;
2829     HDC hdc = GetDC( hwnd );
2830     const WCHAR fontname[] = {'T','a','h','o','m','a',0};
2831     const WCHAR teststring[] = {'M','M',' ','M','\n','M',0};
2832     REAL char_width, char_height;
2833     INT codepointsfitted, linesfilled;
2834     GpStringFormat *format;
2835     CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
2836     GpRegion *regions[4] = {0};
2837     BOOL region_isempty[4];
2838     int i;
2839
2840     ok(hdc != NULL, "Expected HDC to be initialized\n");
2841     status = GdipCreateFromHDC(hdc, &graphics);
2842     expect(Ok, status);
2843     ok(graphics != NULL, "Expected graphics to be initialized\n");
2844
2845     status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
2846     expect(Ok, status);
2847
2848     status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
2849     expect(Ok, status);
2850
2851     status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
2852     expect(Ok, status);
2853
2854     status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
2855     expect(Ok, status);
2856
2857     rc.X = 0;
2858     rc.Y = 0;
2859     rc.Width = 100.0;
2860     rc.Height = 100.0;
2861
2862     status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
2863     expect(InvalidParameter, status);
2864
2865     status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
2866     expect(InvalidParameter, status);
2867
2868     status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
2869     expect(InvalidParameter, status);
2870
2871     status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
2872     expect(InvalidParameter, status);
2873
2874     status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
2875     expect(InvalidParameter, status);
2876
2877     status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
2878     expect(Ok, status);
2879
2880     status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2881     expect(InvalidParameter, status);
2882
2883     status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2884     expect(InvalidParameter, status);
2885
2886     status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2887     expect(InvalidParameter, status);
2888
2889     status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
2890     expect(InvalidParameter, status);
2891
2892     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
2893     expect(InvalidParameter, status);
2894
2895     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
2896     expect(Ok, status);
2897
2898     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
2899     expect(Ok, status);
2900
2901     status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
2902     expect(Ok, status);
2903     expectf(0.0, char_bounds.X);
2904     expectf(0.0, char_bounds.Y);
2905     ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
2906     ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
2907     expect(1, codepointsfitted);
2908     expect(1, linesfilled);
2909
2910     status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2911     expect(Ok, status);
2912     expectf(0.0, bounds.X);
2913     expectf(0.0, bounds.Y);
2914     ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
2915     expectf(char_bounds.Height, bounds.Height);
2916     expect(2, codepointsfitted);
2917     expect(1, linesfilled);
2918     char_width = bounds.Width - char_bounds.Width;
2919
2920     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2921     expect(Ok, status);
2922     expectf(0.0, bounds.X);
2923     expectf(0.0, bounds.Y);
2924     ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
2925        bounds.Width, char_bounds.Width + char_width * 2);
2926     ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
2927     expect(6, codepointsfitted);
2928     expect(2, linesfilled);
2929     char_height = bounds.Height - char_bounds.Height;
2930
2931     /* Cut off everything after the first space. */
2932     rc.Width = char_bounds.Width + char_width * 2.1;
2933
2934     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2935     expect(Ok, status);
2936     expectf(0.0, bounds.X);
2937     expectf(0.0, bounds.Y);
2938     expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
2939     expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
2940     expect(6, codepointsfitted);
2941     expect(3, linesfilled);
2942
2943     /* Cut off everything including the first space. */
2944     rc.Width = char_bounds.Width + char_width * 1.5;
2945
2946     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2947     expect(Ok, status);
2948     expectf(0.0, bounds.X);
2949     expectf(0.0, bounds.Y);
2950     expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
2951     expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
2952     expect(6, codepointsfitted);
2953     expect(3, linesfilled);
2954
2955     /* Cut off everything after the first character. */
2956     rc.Width = char_bounds.Width + char_width * 0.5;
2957
2958     status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2959     expect(Ok, status);
2960     expectf(0.0, bounds.X);
2961     expectf(0.0, bounds.Y);
2962     expectf_(char_bounds.Width, bounds.Width, 0.01);
2963     todo_wine expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
2964     expect(6, codepointsfitted);
2965     todo_wine expect(4, linesfilled);
2966
2967     status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
2968     expect(Ok, status);
2969
2970     rc.Width = 100.0;
2971
2972     for (i=0; i<4; i++)
2973     {
2974         status = GdipCreateRegion(&regions[i]);
2975         expect(Ok, status);
2976     }
2977
2978     status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
2979     expect(InvalidParameter, status);
2980
2981     status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
2982     expect(InvalidParameter, status);
2983
2984     status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
2985     expect(InvalidParameter, status);
2986
2987     status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
2988     expect(InvalidParameter, status);
2989
2990     if (0)
2991     {
2992         /* Crashes on Windows XP */
2993         status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
2994         expect(InvalidParameter, status);
2995     }
2996
2997     status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
2998     expect(InvalidParameter, status);
2999
3000     status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
3001     expect(InvalidParameter, status);
3002
3003     status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
3004     expect(Ok, status);
3005
3006     for (i=0; i<4; i++)
3007     {
3008         status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3009         expect(Ok, status);
3010     }
3011
3012     ok(!region_isempty[0], "region shouldn't be empty\n");
3013     ok(!region_isempty[1], "region shouldn't be empty\n");
3014     ok(!region_isempty[2], "region shouldn't be empty\n");
3015     ok(!region_isempty[3], "region shouldn't be empty\n");
3016
3017     /* Cut off everything after the first space, and the second line. */
3018     rc.Width = char_bounds.Width + char_width * 2.1;
3019     rc.Height = char_bounds.Height + char_height * 0.5;
3020
3021     status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3022     expect(Ok, status);
3023
3024     for (i=0; i<4; i++)
3025     {
3026         status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3027         expect(Ok, status);
3028     }
3029
3030     ok(!region_isempty[0], "region shouldn't be empty\n");
3031     ok(!region_isempty[1], "region shouldn't be empty\n");
3032     ok(region_isempty[2], "region should be empty\n");
3033     ok(!region_isempty[3], "region shouldn't be empty\n");
3034
3035     for (i=0; i<4; i++)
3036         GdipDeleteRegion(regions[i]);
3037
3038     GdipDeleteStringFormat(format);
3039     GdipDeleteBrush(brush);
3040     GdipDeleteFont(font);
3041     GdipDeleteFontFamily(family);
3042     GdipDeleteGraphics(graphics);
3043
3044     ReleaseDC(hwnd, hdc);
3045 }
3046
3047 static void test_get_set_interpolation(void)
3048 {
3049     GpGraphics *graphics;
3050     HDC hdc = GetDC( hwnd );
3051     GpStatus status;
3052     InterpolationMode mode;
3053
3054     ok(hdc != NULL, "Expected HDC to be initialized\n");
3055     status = GdipCreateFromHDC(hdc, &graphics);
3056     expect(Ok, status);
3057     ok(graphics != NULL, "Expected graphics to be initialized\n");
3058
3059     status = GdipGetInterpolationMode(NULL, &mode);
3060     expect(InvalidParameter, status);
3061
3062     if (0)
3063     {
3064         /* Crashes on Windows XP */
3065         status = GdipGetInterpolationMode(graphics, NULL);
3066         expect(InvalidParameter, status);
3067     }
3068
3069     status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor);
3070     expect(InvalidParameter, status);
3071
3072     /* out of range */
3073     status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1);
3074     expect(InvalidParameter, status);
3075
3076     status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid);
3077     expect(InvalidParameter, status);
3078
3079     status = GdipGetInterpolationMode(graphics, &mode);
3080     expect(Ok, status);
3081     expect(InterpolationModeBilinear, mode);
3082
3083     status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3084     expect(Ok, status);
3085
3086     status = GdipGetInterpolationMode(graphics, &mode);
3087     expect(Ok, status);
3088     expect(InterpolationModeNearestNeighbor, mode);
3089
3090     status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
3091     expect(Ok, status);
3092
3093     status = GdipGetInterpolationMode(graphics, &mode);
3094     expect(Ok, status);
3095     expect(InterpolationModeBilinear, mode);
3096
3097     status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality);
3098     expect(Ok, status);
3099
3100     status = GdipGetInterpolationMode(graphics, &mode);
3101     expect(Ok, status);
3102     expect(InterpolationModeBilinear, mode);
3103
3104     status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality);
3105     expect(Ok, status);
3106
3107     status = GdipGetInterpolationMode(graphics, &mode);
3108     expect(Ok, status);
3109     expect(InterpolationModeHighQualityBicubic, mode);
3110
3111     GdipDeleteGraphics(graphics);
3112
3113     ReleaseDC(hwnd, hdc);
3114 }
3115
3116 static void test_get_set_textrenderinghint(void)
3117 {
3118     GpGraphics *graphics;
3119     HDC hdc = GetDC( hwnd );
3120     GpStatus status;
3121     TextRenderingHint hint;
3122
3123     ok(hdc != NULL, "Expected HDC to be initialized\n");
3124     status = GdipCreateFromHDC(hdc, &graphics);
3125     expect(Ok, status);
3126     ok(graphics != NULL, "Expected graphics to be initialized\n");
3127
3128     status = GdipGetTextRenderingHint(NULL, &hint);
3129     expect(InvalidParameter, status);
3130
3131     status = GdipGetTextRenderingHint(graphics, NULL);
3132     expect(InvalidParameter, status);
3133
3134     status = GdipSetTextRenderingHint(NULL, TextRenderingHintAntiAlias);
3135     expect(InvalidParameter, status);
3136
3137     /* out of range */
3138     status = GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit+1);
3139     expect(InvalidParameter, status);
3140
3141     status = GdipGetTextRenderingHint(graphics, &hint);
3142     expect(Ok, status);
3143     expect(TextRenderingHintSystemDefault, hint);
3144
3145     status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
3146     expect(Ok, status);
3147
3148     status = GdipGetTextRenderingHint(graphics, &hint);
3149     expect(Ok, status);
3150     expect(TextRenderingHintSystemDefault, hint);
3151
3152     status = GdipSetTextRenderingHint(graphics, TextRenderingHintAntiAliasGridFit);
3153     expect(Ok, status);
3154
3155     status = GdipGetTextRenderingHint(graphics, &hint);
3156     expect(Ok, status);
3157     expect(TextRenderingHintAntiAliasGridFit, hint);
3158
3159     GdipDeleteGraphics(graphics);
3160
3161     ReleaseDC(hwnd, hdc);
3162 }
3163
3164 START_TEST(graphics)
3165 {
3166     struct GdiplusStartupInput gdiplusStartupInput;
3167     ULONG_PTR gdiplusToken;
3168     WNDCLASSA class;
3169
3170     memset( &class, 0, sizeof(class) );
3171     class.lpszClassName = "gdiplus_test";
3172     class.style = CS_HREDRAW | CS_VREDRAW;
3173     class.lpfnWndProc = DefWindowProcA;
3174     class.hInstance = GetModuleHandleA(0);
3175     class.hIcon = LoadIcon(0, IDI_APPLICATION);
3176     class.hCursor = LoadCursor(NULL, IDC_ARROW);
3177     class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
3178     RegisterClassA( &class );
3179     hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3180                           CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
3181     ok(hwnd != NULL, "Expected window to be created\n");
3182
3183     gdiplusStartupInput.GdiplusVersion              = 1;
3184     gdiplusStartupInput.DebugEventCallback          = NULL;
3185     gdiplusStartupInput.SuppressBackgroundThread    = 0;
3186     gdiplusStartupInput.SuppressExternalCodecs      = 0;
3187
3188     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
3189
3190     test_constructor_destructor();
3191     test_save_restore();
3192     test_GdipFillClosedCurve2();
3193     test_GdipFillClosedCurve2I();
3194     test_GdipDrawBezierI();
3195     test_GdipDrawArc();
3196     test_GdipDrawArcI();
3197     test_GdipDrawCurve();
3198     test_GdipDrawCurveI();
3199     test_GdipDrawCurve2();
3200     test_GdipDrawCurve2I();
3201     test_GdipDrawCurve3();
3202     test_GdipDrawCurve3I();
3203     test_GdipDrawLineI();
3204     test_GdipDrawLinesI();
3205     test_GdipDrawImagePointsRect();
3206     test_GdipFillClosedCurve();
3207     test_GdipFillClosedCurveI();
3208     test_GdipDrawString();
3209     test_GdipGetNearestColor();
3210     test_GdipGetVisibleClipBounds();
3211     test_GdipIsVisiblePoint();
3212     test_GdipIsVisibleRect();
3213     test_Get_Release_DC();
3214     test_BeginContainer2();
3215     test_transformpoints();
3216     test_get_set_clip();
3217     test_isempty();
3218     test_clear();
3219     test_textcontrast();
3220     test_fromMemoryBitmap();
3221     test_string_functions();
3222     test_get_set_interpolation();
3223     test_get_set_textrenderinghint();
3224
3225     GdiplusShutdown(gdiplusToken);
3226     DestroyWindow( hwnd );
3227 }