gdiplus: Add tests for interpolation mode and make them pass.
[wine.git] / dlls / gdiplus / tests / graphics.c
blobecdbe935cb4f3c4549610efc3fb2744eca703525
1 /*
2 * Unit test suite for graphics objects
4 * Copyright (C) 2007 Google (Evan Stade)
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.
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.
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
21 #include "windows.h"
22 #include "gdiplus.h"
23 #include "wingdi.h"
24 #include "wine/test.h"
25 #include <math.h>
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)
32 static HWND hwnd;
34 static void test_constructor_destructor(void)
36 GpStatus stat;
37 GpGraphics *graphics = NULL;
38 HDC hdc = GetDC( hwnd );
40 stat = GdipCreateFromHDC(NULL, &graphics);
41 expect(OutOfMemory, stat);
42 stat = GdipDeleteGraphics(graphics);
43 expect(InvalidParameter, stat);
45 stat = GdipCreateFromHDC(hdc, &graphics);
46 expect(Ok, stat);
47 stat = GdipDeleteGraphics(graphics);
48 expect(Ok, stat);
50 stat = GdipCreateFromHWND(NULL, &graphics);
51 expect(Ok, stat);
52 stat = GdipDeleteGraphics(graphics);
53 expect(Ok, stat);
55 stat = GdipCreateFromHWNDICM(NULL, &graphics);
56 expect(Ok, stat);
57 stat = GdipDeleteGraphics(graphics);
58 expect(Ok, stat);
60 stat = GdipDeleteGraphics(NULL);
61 expect(InvalidParameter, stat);
62 ReleaseDC(hwnd, hdc);
65 typedef struct node{
66 GraphicsState data;
67 struct node * next;
68 } node;
70 /* Linked list prepend function. */
71 static void log_state(GraphicsState data, node ** log)
73 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
75 new_entry->data = data;
76 new_entry->next = *log;
77 *log = new_entry;
80 /* Checks if there are duplicates in the list, and frees it. */
81 static void check_no_duplicates(node * log)
83 INT dups = 0;
84 node * temp = NULL;
85 node * temp2 = NULL;
86 node * orig = log;
88 if(!log)
89 goto end;
91 do{
92 temp = log;
93 while((temp = temp->next)){
94 if(log->data == temp->data){
95 dups++;
96 break;
98 if(dups > 0)
99 break;
101 }while((log = log->next));
103 temp = orig;
105 temp2 = temp->next;
106 HeapFree(GetProcessHeap(), 0, temp);
107 temp = temp2;
108 }while(temp);
110 end:
111 expect(0, dups);
114 static void test_save_restore(void)
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;
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);
132 log_state(state_a, &state_log);
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);
146 log_state(state_a, &state_log);
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);
165 log_state(state_a, &state_log);
166 log_state(state_b, &state_log);
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);
188 log_state(state_a, &state_log);
189 log_state(state_b, &state_log);
190 log_state(state_c, &state_log);
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);
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);
224 log_state(state_a, &state_log);
226 /* The same state value should never be returned twice. */
227 todo_wine
228 check_no_duplicates(state_log);
230 ReleaseDC(hwnd, hdc);
233 static void test_GdipFillClosedCurve2(void)
235 GpStatus status;
236 GpGraphics *graphics = NULL;
237 GpSolidFill *brush = NULL;
238 HDC hdc = GetDC( hwnd );
239 GpPointF points[3];
241 points[0].X = 0;
242 points[0].Y = 0;
244 points[1].X = 40;
245 points[1].Y = 20;
247 points[2].X = 10;
248 points[2].Y = 40;
250 /* make a graphics object and brush object */
251 ok(hdc != NULL, "Expected HDC to be initialized\n");
253 status = GdipCreateFromHDC(hdc, &graphics);
254 expect(Ok, status);
255 ok(graphics != NULL, "Expected graphics to be initialized\n");
257 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
259 /* InvalidParameter cases: null graphics, null brush, null points */
260 status = GdipFillClosedCurve2(NULL, NULL, NULL, 3, 0.5, FillModeAlternate);
261 expect(InvalidParameter, status);
263 status = GdipFillClosedCurve2(graphics, NULL, NULL, 3, 0.5, FillModeAlternate);
264 expect(InvalidParameter, status);
266 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
267 expect(InvalidParameter, status);
269 status = GdipFillClosedCurve2(NULL, NULL, points, 3, 0.5, FillModeAlternate);
270 expect(InvalidParameter, status);
272 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
273 expect(InvalidParameter, status);
275 status = GdipFillClosedCurve2(graphics, NULL, points, 3, 0.5, FillModeAlternate);
276 expect(InvalidParameter, status);
278 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
279 expect(InvalidParameter, status);
281 /* InvalidParameter cases: invalid count */
282 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
283 expect(InvalidParameter, status);
285 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
286 expect(InvalidParameter, status);
288 /* Valid test cases */
289 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
290 expect(Ok, status);
292 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
293 expect(Ok, status);
295 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
296 expect(Ok, status);
298 GdipDeleteGraphics(graphics);
299 GdipDeleteBrush((GpBrush*)brush);
301 ReleaseDC(hwnd, hdc);
304 static void test_GdipFillClosedCurve2I(void)
306 GpStatus status;
307 GpGraphics *graphics = NULL;
308 GpSolidFill *brush = NULL;
309 HDC hdc = GetDC( hwnd );
310 GpPoint points[3];
312 points[0].X = 0;
313 points[0].Y = 0;
315 points[1].X = 40;
316 points[1].Y = 20;
318 points[2].X = 10;
319 points[2].Y = 40;
321 /* make a graphics object and brush object */
322 ok(hdc != NULL, "Expected HDC to be initialized\n");
324 status = GdipCreateFromHDC(hdc, &graphics);
325 expect(Ok, status);
326 ok(graphics != NULL, "Expected graphics to be initialized\n");
328 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
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);
336 status = GdipFillClosedCurve2I(graphics, NULL, points, 3, 0.5, FillModeAlternate);
337 expect(InvalidParameter, status);
339 status = GdipFillClosedCurve2I(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
340 expect(InvalidParameter, status);
342 /* InvalidParameter cases: invalid count */
343 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
344 expect(InvalidParameter, status);
346 /* OutOfMemory cases: large (unsigned) int */
347 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
348 expect(OutOfMemory, status);
350 /* Valid test cases */
351 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
352 expect(Ok, status);
354 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
355 expect(Ok, status);
357 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
358 expect(Ok, status);
360 GdipDeleteGraphics(graphics);
361 GdipDeleteBrush((GpBrush*)brush);
363 ReleaseDC(hwnd, hdc);
366 static void test_GdipDrawArc(void)
368 GpStatus status;
369 GpGraphics *graphics = NULL;
370 GpPen *pen = NULL;
371 HDC hdc = GetDC( hwnd );
373 /* make a graphics object and pen object */
374 ok(hdc != NULL, "Expected HDC to be initialized\n");
376 status = GdipCreateFromHDC(hdc, &graphics);
377 expect(Ok, status);
378 ok(graphics != NULL, "Expected graphics to be initialized\n");
380 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
381 expect(Ok, status);
382 ok(pen != NULL, "Expected pen to be initialized\n");
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);
388 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
389 expect(InvalidParameter, status);
391 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
392 expect(InvalidParameter, status);
394 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
395 expect(InvalidParameter, status);
397 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
398 expect(InvalidParameter, status);
400 /* successful case */
401 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
402 expect(Ok, status);
404 GdipDeletePen(pen);
405 GdipDeleteGraphics(graphics);
407 ReleaseDC(hwnd, hdc);
410 static void test_GdipDrawArcI(void)
412 GpStatus status;
413 GpGraphics *graphics = NULL;
414 GpPen *pen = NULL;
415 HDC hdc = GetDC( hwnd );
417 /* make a graphics object and pen object */
418 ok(hdc != NULL, "Expected HDC to be initialized\n");
420 status = GdipCreateFromHDC(hdc, &graphics);
421 expect(Ok, status);
422 ok(graphics != NULL, "Expected graphics to be initialized\n");
424 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
425 expect(Ok, status);
426 ok(pen != NULL, "Expected pen to be initialized\n");
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);
432 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
433 expect(InvalidParameter, status);
435 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
436 expect(InvalidParameter, status);
438 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
439 expect(InvalidParameter, status);
441 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
442 expect(InvalidParameter, status);
444 /* successful case */
445 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
446 expect(Ok, status);
448 GdipDeletePen(pen);
449 GdipDeleteGraphics(graphics);
451 ReleaseDC(hwnd, hdc);
454 static void test_BeginContainer2(void)
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;
471 GpStatus status;
472 GpGraphics *graphics = NULL;
473 HDC hdc = GetDC( hwnd );
475 ok(hdc != NULL, "Expected HDC to be initialized\n");
477 status = GdipCreateFromHDC(hdc, &graphics);
478 expect(Ok, status);
479 ok(graphics != NULL, "Expected graphics to be initialized\n");
481 /* null graphics, null container */
482 status = GdipBeginContainer2(NULL, &cont1);
483 expect(InvalidParameter, status);
485 status = GdipBeginContainer2(graphics, NULL);
486 expect(InvalidParameter, status);
488 status = GdipEndContainer(NULL, cont1);
489 expect(InvalidParameter, status);
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);
502 status = GdipBeginContainer2(graphics, &cont1);
503 expect(Ok, status);
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);
515 status = GdipEndContainer(graphics, cont1);
516 expect(Ok, status);
518 GdipGetCompositingMode(graphics, &compmode);
519 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
521 GdipGetCompositingQuality(graphics, &compqual);
522 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
524 GdipGetInterpolationMode(graphics, &interp);
525 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
527 GdipGetPageScale(graphics, &scale);
528 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
530 GdipGetPageUnit(graphics, &unit);
531 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
533 GdipGetPixelOffsetMode(graphics, &offsetmode);
534 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
536 GdipGetSmoothingMode(graphics, &smoothmode);
537 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
539 GdipGetTextContrast(graphics, &contrast);
540 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
542 GdipGetTextRenderingHint(graphics, &texthint);
543 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
545 /* test world transform */
546 status = GdipBeginContainer2(graphics, &cont1);
547 expect(Ok, status);
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;
555 status = GdipBeginContainer2(graphics, &cont2);
556 expect(Ok, status);
558 GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
559 GdipSetWorldTransform(graphics, transform);
560 GdipDeleteMatrix(transform);
561 transform = NULL;
563 status = GdipEndContainer(graphics, cont2);
564 expect(Ok, status);
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;
581 status = GdipEndContainer(graphics, cont1);
582 expect(Ok, status);
584 /* test clipping */
585 status = GdipBeginContainer2(graphics, &cont1);
586 expect(Ok, status);
588 GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
590 status = GdipBeginContainer2(graphics, &cont2);
591 expect(Ok, status);
593 GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
595 status = GdipEndContainer(graphics, cont2);
596 expect(Ok, status);
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);
607 status = GdipEndContainer(graphics, cont1);
608 expect(Ok, status);
610 /* nesting */
611 status = GdipBeginContainer2(graphics, &cont1);
612 expect(Ok, status);
614 status = GdipBeginContainer2(graphics, &cont2);
615 expect(Ok, status);
617 status = GdipBeginContainer2(graphics, &cont3);
618 expect(Ok, status);
620 status = GdipEndContainer(graphics, cont3);
621 expect(Ok, status);
623 status = GdipBeginContainer2(graphics, &cont4);
624 expect(Ok, status);
626 status = GdipEndContainer(graphics, cont4);
627 expect(Ok, status);
629 /* skip cont2 */
630 status = GdipEndContainer(graphics, cont1);
631 expect(Ok, status);
633 /* end an already-ended container */
634 status = GdipEndContainer(graphics, cont1);
635 expect(Ok, status);
637 GdipDeleteGraphics(graphics);
638 ReleaseDC(hwnd, hdc);
641 static void test_GdipDrawBezierI(void)
643 GpStatus status;
644 GpGraphics *graphics = NULL;
645 GpPen *pen = NULL;
646 HDC hdc = GetDC( hwnd );
648 /* make a graphics object and pen object */
649 ok(hdc != NULL, "Expected HDC to be initialized\n");
651 status = GdipCreateFromHDC(hdc, &graphics);
652 expect(Ok, status);
653 ok(graphics != NULL, "Expected graphics to be initialized\n");
655 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
656 expect(Ok, status);
657 ok(pen != NULL, "Expected pen to be initialized\n");
659 /* InvalidParameter cases: null graphics, null pen */
660 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
661 expect(InvalidParameter, status);
663 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
664 expect(InvalidParameter, status);
666 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
667 expect(InvalidParameter, status);
669 /* successful case */
670 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
671 expect(Ok, status);
673 GdipDeletePen(pen);
674 GdipDeleteGraphics(graphics);
676 ReleaseDC(hwnd, hdc);
679 static void test_GdipDrawCurve3(void)
681 GpStatus status;
682 GpGraphics *graphics = NULL;
683 GpPen *pen = NULL;
684 HDC hdc = GetDC( hwnd );
685 GpPointF points[3];
687 points[0].X = 0;
688 points[0].Y = 0;
690 points[1].X = 40;
691 points[1].Y = 20;
693 points[2].X = 10;
694 points[2].Y = 40;
696 /* make a graphics object and pen object */
697 ok(hdc != NULL, "Expected HDC to be initialized\n");
699 status = GdipCreateFromHDC(hdc, &graphics);
700 expect(Ok, status);
701 ok(graphics != NULL, "Expected graphics to be initialized\n");
703 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
704 expect(Ok, status);
705 ok(pen != NULL, "Expected pen to be initialized\n");
707 /* InvalidParameter cases: null graphics, null pen */
708 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
709 expect(InvalidParameter, status);
711 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
712 expect(InvalidParameter, status);
714 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
715 expect(InvalidParameter, status);
717 /* InvalidParameter cases: invalid count */
718 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
719 expect(InvalidParameter, status);
721 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
722 expect(InvalidParameter, status);
724 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
725 expect(InvalidParameter, status);
727 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
728 expect(InvalidParameter, status);
730 /* InvalidParameter cases: invalid number of segments */
731 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
732 expect(InvalidParameter, status);
734 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
735 expect(InvalidParameter, status);
737 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
738 expect(InvalidParameter, status);
740 /* Valid test cases */
741 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
742 expect(Ok, status);
744 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
745 expect(Ok, status);
747 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
748 expect(Ok, status);
750 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
751 expect(Ok, status);
753 GdipDeletePen(pen);
754 GdipDeleteGraphics(graphics);
756 ReleaseDC(hwnd, hdc);
759 static void test_GdipDrawCurve3I(void)
761 GpStatus status;
762 GpGraphics *graphics = NULL;
763 GpPen *pen = NULL;
764 HDC hdc = GetDC( hwnd );
765 GpPoint points[3];
767 points[0].X = 0;
768 points[0].Y = 0;
770 points[1].X = 40;
771 points[1].Y = 20;
773 points[2].X = 10;
774 points[2].Y = 40;
776 /* make a graphics object and pen object */
777 ok(hdc != NULL, "Expected HDC to be initialized\n");
779 status = GdipCreateFromHDC(hdc, &graphics);
780 expect(Ok, status);
781 ok(graphics != NULL, "Expected graphics to be initialized\n");
783 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
784 expect(Ok, status);
785 ok(pen != NULL, "Expected pen to be initialized\n");
787 /* InvalidParameter cases: null graphics, null pen */
788 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
789 expect(InvalidParameter, status);
791 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
792 expect(InvalidParameter, status);
794 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
795 expect(InvalidParameter, status);
797 /* InvalidParameter cases: invalid count */
798 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
799 expect(OutOfMemory, status);
801 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
802 expect(InvalidParameter, status);
804 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
805 expect(InvalidParameter, status);
807 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
808 expect(InvalidParameter, status);
810 /* InvalidParameter cases: invalid number of segments */
811 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
812 expect(InvalidParameter, status);
814 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
815 expect(InvalidParameter, status);
817 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
818 expect(InvalidParameter, status);
820 /* Valid test cases */
821 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
822 expect(Ok, status);
824 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
825 expect(Ok, status);
827 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
828 expect(Ok, status);
830 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
831 expect(Ok, status);
833 GdipDeletePen(pen);
834 GdipDeleteGraphics(graphics);
836 ReleaseDC(hwnd, hdc);
839 static void test_GdipDrawCurve2(void)
841 GpStatus status;
842 GpGraphics *graphics = NULL;
843 GpPen *pen = NULL;
844 HDC hdc = GetDC( hwnd );
845 GpPointF points[3];
847 points[0].X = 0;
848 points[0].Y = 0;
850 points[1].X = 40;
851 points[1].Y = 20;
853 points[2].X = 10;
854 points[2].Y = 40;
856 /* make a graphics object and pen object */
857 ok(hdc != NULL, "Expected HDC to be initialized\n");
859 status = GdipCreateFromHDC(hdc, &graphics);
860 expect(Ok, status);
861 ok(graphics != NULL, "Expected graphics to be initialized\n");
863 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
864 expect(Ok, status);
865 ok(pen != NULL, "Expected pen to be initialized\n");
867 /* InvalidParameter cases: null graphics, null pen */
868 status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
869 expect(InvalidParameter, status);
871 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
872 expect(InvalidParameter, status);
874 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
875 expect(InvalidParameter, status);
877 /* InvalidParameter cases: invalid count */
878 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
879 expect(InvalidParameter, status);
881 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
882 expect(InvalidParameter, status);
884 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
885 expect(InvalidParameter, status);
887 /* Valid test cases */
888 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
889 expect(Ok, status);
891 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
892 expect(Ok, status);
894 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
895 expect(Ok, status);
897 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
898 expect(Ok, status);
900 GdipDeletePen(pen);
901 GdipDeleteGraphics(graphics);
903 ReleaseDC(hwnd, hdc);
906 static void test_GdipDrawCurve2I(void)
908 GpStatus status;
909 GpGraphics *graphics = NULL;
910 GpPen *pen = NULL;
911 HDC hdc = GetDC( hwnd );
912 GpPoint points[3];
914 points[0].X = 0;
915 points[0].Y = 0;
917 points[1].X = 40;
918 points[1].Y = 20;
920 points[2].X = 10;
921 points[2].Y = 40;
923 /* make a graphics object and pen object */
924 ok(hdc != NULL, "Expected HDC to be initialized\n");
926 status = GdipCreateFromHDC(hdc, &graphics);
927 expect(Ok, status);
928 ok(graphics != NULL, "Expected graphics to be initialized\n");
930 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
931 expect(Ok, status);
932 ok(pen != NULL, "Expected pen to be initialized\n");
934 /* InvalidParameter cases: null graphics, null pen */
935 status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
936 expect(InvalidParameter, status);
938 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
939 expect(InvalidParameter, status);
941 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
942 expect(InvalidParameter, status);
944 /* InvalidParameter cases: invalid count */
945 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
946 expect(OutOfMemory, status);
948 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
949 expect(InvalidParameter, status);
951 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
952 expect(InvalidParameter, status);
954 /* Valid test cases */
955 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
956 expect(Ok, status);
958 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
959 expect(Ok, status);
961 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
962 expect(Ok, status);
964 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
965 expect(Ok, status);
967 GdipDeletePen(pen);
968 GdipDeleteGraphics(graphics);
970 ReleaseDC(hwnd, hdc);
973 static void test_GdipDrawCurve(void)
975 GpStatus status;
976 GpGraphics *graphics = NULL;
977 GpPen *pen = NULL;
978 HDC hdc = GetDC( hwnd );
979 GpPointF points[3];
981 points[0].X = 0;
982 points[0].Y = 0;
984 points[1].X = 40;
985 points[1].Y = 20;
987 points[2].X = 10;
988 points[2].Y = 40;
990 /* make a graphics object and pen object */
991 ok(hdc != NULL, "Expected HDC to be initialized\n");
993 status = GdipCreateFromHDC(hdc, &graphics);
994 expect(Ok, status);
995 ok(graphics != NULL, "Expected graphics to be initialized\n");
997 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
998 expect(Ok, status);
999 ok(pen != NULL, "Expected pen to be initialized\n");
1001 /* InvalidParameter cases: null graphics, null pen */
1002 status = GdipDrawCurve(NULL, NULL, points, 3);
1003 expect(InvalidParameter, status);
1005 status = GdipDrawCurve(graphics, NULL, points, 3);
1006 expect(InvalidParameter, status);
1008 status = GdipDrawCurve(NULL, pen, points, 3);
1009 expect(InvalidParameter, status);
1011 /* InvalidParameter cases: invalid count */
1012 status = GdipDrawCurve(graphics, pen, points, -1);
1013 expect(InvalidParameter, status);
1015 status = GdipDrawCurve(graphics, pen, points, 0);
1016 expect(InvalidParameter, status);
1018 status = GdipDrawCurve(graphics, pen, points, 1);
1019 expect(InvalidParameter, status);
1021 /* Valid test cases */
1022 status = GdipDrawCurve(graphics, pen, points, 2);
1023 expect(Ok, status);
1025 status = GdipDrawCurve(graphics, pen, points, 3);
1026 expect(Ok, status);
1028 GdipDeletePen(pen);
1029 GdipDeleteGraphics(graphics);
1031 ReleaseDC(hwnd, hdc);
1034 static void test_GdipDrawCurveI(void)
1036 GpStatus status;
1037 GpGraphics *graphics = NULL;
1038 GpPen *pen = NULL;
1039 HDC hdc = GetDC( hwnd );
1040 GpPoint points[3];
1042 points[0].X = 0;
1043 points[0].Y = 0;
1045 points[1].X = 40;
1046 points[1].Y = 20;
1048 points[2].X = 10;
1049 points[2].Y = 40;
1051 /* make a graphics object and pen object */
1052 ok(hdc != NULL, "Expected HDC to be initialized\n");
1054 status = GdipCreateFromHDC(hdc, &graphics);
1055 expect(Ok, status);
1056 ok(graphics != NULL, "Expected graphics to be initialized\n");
1058 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1059 expect(Ok, status);
1060 ok(pen != NULL, "Expected pen to be initialized\n");
1062 /* InvalidParameter cases: null graphics, null pen */
1063 status = GdipDrawCurveI(NULL, NULL, points, 3);
1064 expect(InvalidParameter, status);
1066 status = GdipDrawCurveI(graphics, NULL, points, 3);
1067 expect(InvalidParameter, status);
1069 status = GdipDrawCurveI(NULL, pen, points, 3);
1070 expect(InvalidParameter, status);
1072 /* InvalidParameter cases: invalid count */
1073 status = GdipDrawCurveI(graphics, pen, points, -1);
1074 expect(OutOfMemory, status);
1076 status = GdipDrawCurveI(graphics, pen, points, 0);
1077 expect(InvalidParameter, status);
1079 status = GdipDrawCurveI(graphics, pen, points, 1);
1080 expect(InvalidParameter, status);
1082 /* Valid test cases */
1083 status = GdipDrawCurveI(graphics, pen, points, 2);
1084 expect(Ok, status);
1086 status = GdipDrawCurveI(graphics, pen, points, 3);
1087 expect(Ok, status);
1089 GdipDeletePen(pen);
1090 GdipDeleteGraphics(graphics);
1092 ReleaseDC(hwnd, hdc);
1095 static void test_GdipDrawLineI(void)
1097 GpStatus status;
1098 GpGraphics *graphics = NULL;
1099 GpPen *pen = NULL;
1100 HDC hdc = GetDC( hwnd );
1102 /* make a graphics object and pen object */
1103 ok(hdc != NULL, "Expected HDC to be initialized\n");
1105 status = GdipCreateFromHDC(hdc, &graphics);
1106 expect(Ok, status);
1107 ok(graphics != NULL, "Expected graphics to be initialized\n");
1109 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1110 expect(Ok, status);
1111 ok(pen != NULL, "Expected pen to be initialized\n");
1113 /* InvalidParameter cases: null graphics, null pen */
1114 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
1115 expect(InvalidParameter, status);
1117 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
1118 expect(InvalidParameter, status);
1120 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
1121 expect(InvalidParameter, status);
1123 /* successful case */
1124 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
1125 expect(Ok, status);
1127 GdipDeletePen(pen);
1128 GdipDeleteGraphics(graphics);
1130 ReleaseDC(hwnd, hdc);
1133 static void test_GdipDrawImagePointsRect(void)
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;
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);
1182 GdipDisposeImage((GpImage*)bm);
1183 GdipDeleteGraphics(graphics);
1184 ReleaseDC(hwnd, hdc);
1187 static void test_GdipDrawLinesI(void)
1189 GpStatus status;
1190 GpGraphics *graphics = NULL;
1191 GpPen *pen = NULL;
1192 GpPoint *ptf = NULL;
1193 HDC hdc = GetDC( hwnd );
1195 /* make a graphics object and pen object */
1196 ok(hdc != NULL, "Expected HDC to be initialized\n");
1198 status = GdipCreateFromHDC(hdc, &graphics);
1199 expect(Ok, status);
1200 ok(graphics != NULL, "Expected graphics to be initialized\n");
1202 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1203 expect(Ok, status);
1204 ok(pen != NULL, "Expected pen to be initialized\n");
1206 /* make some arbitrary valid points*/
1207 ptf = GdipAlloc(2 * sizeof(GpPointF));
1209 ptf[0].X = 1;
1210 ptf[0].Y = 1;
1212 ptf[1].X = 2;
1213 ptf[1].Y = 2;
1215 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1216 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1217 expect(InvalidParameter, status);
1219 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1220 expect(InvalidParameter, status);
1222 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1223 expect(InvalidParameter, status);
1225 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1226 expect(InvalidParameter, status);
1228 /* successful case */
1229 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1230 expect(Ok, status);
1232 GdipFree(ptf);
1233 GdipDeletePen(pen);
1234 GdipDeleteGraphics(graphics);
1236 ReleaseDC(hwnd, hdc);
1239 static void test_GdipFillClosedCurve(void)
1241 GpStatus status;
1242 GpGraphics *graphics = NULL;
1243 GpSolidFill *brush = NULL;
1244 HDC hdc = GetDC( hwnd );
1245 GpPointF points[3];
1247 points[0].X = 0;
1248 points[0].Y = 0;
1250 points[1].X = 40;
1251 points[1].Y = 20;
1253 points[2].X = 10;
1254 points[2].Y = 40;
1256 /* make a graphics object and brush object */
1257 ok(hdc != NULL, "Expected HDC to be initialized\n");
1259 status = GdipCreateFromHDC(hdc, &graphics);
1260 expect(Ok, status);
1261 ok(graphics != NULL, "Expected graphics to be initialized\n");
1263 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1265 /* InvalidParameter cases: null graphics, null brush, null points */
1266 status = GdipFillClosedCurve(NULL, NULL, NULL, 3);
1267 expect(InvalidParameter, status);
1269 status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1270 expect(InvalidParameter, status);
1272 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1273 expect(InvalidParameter, status);
1275 status = GdipFillClosedCurve(NULL, NULL, points, 3);
1276 expect(InvalidParameter, status);
1278 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1279 expect(InvalidParameter, status);
1281 status = GdipFillClosedCurve(graphics, NULL, points, 3);
1282 expect(InvalidParameter, status);
1284 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, points, 3);
1285 expect(InvalidParameter, status);
1287 /* InvalidParameter cases: invalid count */
1288 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1289 expect(InvalidParameter, status);
1291 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1292 expect(InvalidParameter, status);
1294 /* Valid test cases */
1295 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1296 expect(Ok, status);
1298 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1299 expect(Ok, status);
1301 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1302 expect(Ok, status);
1304 GdipDeleteGraphics(graphics);
1305 GdipDeleteBrush((GpBrush*)brush);
1307 ReleaseDC(hwnd, hdc);
1310 static void test_GdipFillClosedCurveI(void)
1312 GpStatus status;
1313 GpGraphics *graphics = NULL;
1314 GpSolidFill *brush = NULL;
1315 HDC hdc = GetDC( hwnd );
1316 GpPoint points[3];
1318 points[0].X = 0;
1319 points[0].Y = 0;
1321 points[1].X = 40;
1322 points[1].Y = 20;
1324 points[2].X = 10;
1325 points[2].Y = 40;
1327 /* make a graphics object and brush object */
1328 ok(hdc != NULL, "Expected HDC to be initialized\n");
1330 status = GdipCreateFromHDC(hdc, &graphics);
1331 expect(Ok, status);
1332 ok(graphics != NULL, "Expected graphics to be initialized\n");
1334 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
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);
1342 status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1343 expect(InvalidParameter, status);
1345 status = GdipFillClosedCurveI(NULL, (GpBrush*)brush, points, 3);
1346 expect(InvalidParameter, status);
1348 /* InvalidParameter cases: invalid count */
1349 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1350 expect(InvalidParameter, status);
1352 /* OutOfMemory cases: large (unsigned) int */
1353 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1354 expect(OutOfMemory, status);
1356 /* Valid test cases */
1357 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1358 expect(Ok, status);
1360 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1361 expect(Ok, status);
1363 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1364 expect(Ok, status);
1366 GdipDeleteGraphics(graphics);
1367 GdipDeleteBrush((GpBrush*)brush);
1369 ReleaseDC(hwnd, hdc);
1372 static void test_Get_Release_DC(void)
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);
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;
1412 for(i = 0; i < 5;i++){
1413 ptf[i].X = (REAL)pt[i].X;
1414 ptf[i].Y = (REAL)pt[i].Y;
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;
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;
1433 GdipCreateMatrix(&m);
1434 GdipCreateRegion(&region);
1435 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1436 GdipCreatePath(FillModeAlternate, &path);
1437 GdipCreateRegion(&clip);
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);
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);
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);
1460 /* Release without Get */
1461 status = GdipReleaseDC(graphics, hdc);
1462 expect(InvalidParameter, status);
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);
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);
1661 /* try to delete before release */
1662 status = GdipDeleteGraphics(graphics);
1663 expect(ObjectBusy, status);
1665 status = GdipReleaseDC(graphics, retdc);
1666 expect(Ok, status);
1668 GdipDeletePen(pen);
1669 GdipDeleteGraphics(graphics);
1671 GdipDeleteRegion(clip);
1672 GdipDeletePath(path);
1673 GdipDeleteBrush((GpBrush*)brush);
1674 GdipDeleteRegion(region);
1675 GdipDeleteMatrix(m);
1676 DeleteObject(hrgn);
1678 ReleaseDC(hwnd, hdc);
1681 static void test_transformpoints(void)
1683 GpStatus status;
1684 GpGraphics *graphics = NULL;
1685 HDC hdc = GetDC( hwnd );
1686 GpPointF ptf[2];
1687 GpPoint pt[2];
1689 status = GdipCreateFromHDC(hdc, &graphics);
1690 expect(Ok, status);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
1797 GdipDeleteGraphics(graphics);
1798 ReleaseDC(hwnd, hdc);
1801 static void test_get_set_clip(void)
1803 GpStatus status;
1804 GpGraphics *graphics = NULL;
1805 HDC hdc = GetDC( hwnd );
1806 GpRegion *clip;
1807 GpRectF rect;
1808 BOOL res;
1810 status = GdipCreateFromHDC(hdc, &graphics);
1811 expect(Ok, status);
1813 rect.X = rect.Y = 0.0;
1814 rect.Height = rect.Width = 100.0;
1816 status = GdipCreateRegionRect(&rect, &clip);
1817 expect(Ok, status);
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);
1827 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1828 expect(InvalidParameter, status);
1829 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1830 expect(InvalidParameter, status);
1832 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
1833 expect(InvalidParameter, status);
1834 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
1835 expect(InvalidParameter, status);
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);
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);
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);
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);
1875 GdipDeleteRegion(clip);
1877 GdipDeleteGraphics(graphics);
1878 ReleaseDC(hwnd, hdc);
1881 static void test_isempty(void)
1883 GpStatus status;
1884 GpGraphics *graphics = NULL;
1885 HDC hdc = GetDC( hwnd );
1886 GpRegion *clip;
1887 BOOL res;
1889 status = GdipCreateFromHDC(hdc, &graphics);
1890 expect(Ok, status);
1892 status = GdipCreateRegion(&clip);
1893 expect(Ok, status);
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);
1903 /* default is infinite */
1904 res = TRUE;
1905 status = GdipIsClipEmpty(graphics, &res);
1906 expect(Ok, status);
1907 expect(FALSE, res);
1909 GdipDeleteRegion(clip);
1911 GdipDeleteGraphics(graphics);
1912 ReleaseDC(hwnd, hdc);
1915 static void test_clear(void)
1917 GpStatus status;
1919 status = GdipGraphicsClear(NULL, 0xdeadbeef);
1920 expect(InvalidParameter, status);
1923 static void test_textcontrast(void)
1925 GpStatus status;
1926 HDC hdc = GetDC( hwnd );
1927 GpGraphics *graphics;
1928 UINT contrast;
1930 status = GdipGetTextContrast(NULL, NULL);
1931 expect(InvalidParameter, status);
1933 status = GdipCreateFromHDC(hdc, &graphics);
1934 expect(Ok, status);
1936 status = GdipGetTextContrast(graphics, NULL);
1937 expect(InvalidParameter, status);
1938 status = GdipGetTextContrast(graphics, &contrast);
1939 expect(Ok, status);
1940 expect(4, contrast);
1942 GdipDeleteGraphics(graphics);
1943 ReleaseDC(hwnd, hdc);
1946 static void test_GdipDrawString(void)
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};
1958 memset(&logfont,0,sizeof(logfont));
1959 strcpy(logfont.lfFaceName,"Arial");
1960 logfont.lfHeight = 12;
1961 logfont.lfCharSet = DEFAULT_CHARSET;
1963 status = GdipCreateFromHDC(hdc, &graphics);
1964 expect(Ok, status);
1966 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
1967 if (status == FileNotFound)
1969 skip("Arial not installed.\n");
1970 return;
1972 expect(Ok, status);
1974 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
1975 expect(Ok, status);
1977 status = GdipCreateStringFormat(0,0,&format);
1978 expect(Ok, status);
1980 rect.X = 0;
1981 rect.Y = 0;
1982 rect.Width = 0;
1983 rect.Height = 12;
1985 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
1986 expect(Ok, status);
1988 GdipDeleteGraphics(graphics);
1989 GdipDeleteBrush(brush);
1990 GdipDeleteFont(fnt);
1991 GdipDeleteStringFormat(format);
1993 ReleaseDC(hwnd, hdc);
1996 static void test_GdipGetVisibleClipBounds_screen(void)
1998 GpStatus status;
1999 GpGraphics *graphics = NULL;
2000 HDC hdc = GetDC(0);
2001 GpRectF rectf, exp, clipr;
2002 GpRect recti;
2004 ok(hdc != NULL, "Expected HDC to be initialized\n");
2006 status = GdipCreateFromHDC(hdc, &graphics);
2007 expect(Ok, status);
2008 ok(graphics != NULL, "Expected graphics to be initialized\n");
2010 /* no clipping rect */
2011 exp.X = 0;
2012 exp.Y = 0;
2013 exp.Width = GetDeviceCaps(hdc, HORZRES);
2014 exp.Height = GetDeviceCaps(hdc, VERTRES);
2016 status = GdipGetVisibleClipBounds(graphics, &rectf);
2017 expect(Ok, status);
2018 ok(rectf.X == exp.X &&
2019 rectf.Y == exp.Y &&
2020 rectf.Width == exp.Width &&
2021 rectf.Height == exp.Height,
2022 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2023 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2024 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2025 exp.X, exp.Y, exp.Width, exp.Height);
2027 /* clipping rect entirely within window */
2028 exp.X = clipr.X = 10;
2029 exp.Y = clipr.Y = 12;
2030 exp.Width = clipr.Width = 14;
2031 exp.Height = clipr.Height = 16;
2033 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2034 expect(Ok, status);
2036 status = GdipGetVisibleClipBounds(graphics, &rectf);
2037 expect(Ok, status);
2038 ok(rectf.X == exp.X &&
2039 rectf.Y == exp.Y &&
2040 rectf.Width == exp.Width &&
2041 rectf.Height == exp.Height,
2042 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2043 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2044 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2045 exp.X, exp.Y, exp.Width, exp.Height);
2047 /* clipping rect partially outside of screen */
2048 clipr.X = -10;
2049 clipr.Y = -12;
2050 clipr.Width = 20;
2051 clipr.Height = 24;
2053 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2054 expect(Ok, status);
2056 exp.X = 0;
2057 exp.Y = 0;
2058 exp.Width = 10;
2059 exp.Height = 12;
2061 status = GdipGetVisibleClipBounds(graphics, &rectf);
2062 expect(Ok, status);
2063 ok(rectf.X == exp.X &&
2064 rectf.Y == exp.Y &&
2065 rectf.Width == exp.Width &&
2066 rectf.Height == exp.Height,
2067 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2068 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2069 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2070 exp.X, exp.Y, exp.Width, exp.Height);
2072 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2073 expect(Ok, status);
2074 ok(recti.X == exp.X &&
2075 recti.Y == exp.Y &&
2076 recti.Width == exp.Width &&
2077 recti.Height == exp.Height,
2078 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2079 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2080 recti.X, recti.Y, recti.Width, recti.Height,
2081 exp.X, exp.Y, exp.Width, exp.Height);
2083 GdipDeleteGraphics(graphics);
2084 ReleaseDC(0, hdc);
2087 static void test_GdipGetVisibleClipBounds_window(void)
2089 GpStatus status;
2090 GpGraphics *graphics = NULL;
2091 GpRectF rectf, window, exp, clipr;
2092 GpRect recti;
2093 HDC hdc;
2094 PAINTSTRUCT ps;
2095 RECT wnd_rect;
2097 /* get client area size */
2098 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2099 window.X = wnd_rect.left;
2100 window.Y = wnd_rect.top;
2101 window.Width = wnd_rect.right - wnd_rect.left;
2102 window.Height = wnd_rect.bottom - wnd_rect.top;
2104 hdc = BeginPaint(hwnd, &ps);
2106 status = GdipCreateFromHDC(hdc, &graphics);
2107 expect(Ok, status);
2108 ok(graphics != NULL, "Expected graphics to be initialized\n");
2110 status = GdipGetVisibleClipBounds(graphics, &rectf);
2111 expect(Ok, status);
2112 ok(rectf.X == window.X &&
2113 rectf.Y == window.Y &&
2114 rectf.Width == window.Width &&
2115 rectf.Height == window.Height,
2116 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2117 "the window (%0.f, %0.f, %0.f, %0.f)\n",
2118 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2119 window.X, window.Y, window.Width, window.Height);
2121 /* clipping rect entirely within window */
2122 exp.X = clipr.X = 20;
2123 exp.Y = clipr.Y = 8;
2124 exp.Width = clipr.Width = 30;
2125 exp.Height = clipr.Height = 20;
2127 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2128 expect(Ok, status);
2130 status = GdipGetVisibleClipBounds(graphics, &rectf);
2131 expect(Ok, status);
2132 ok(rectf.X == exp.X &&
2133 rectf.Y == exp.Y &&
2134 rectf.Width == exp.Width &&
2135 rectf.Height == exp.Height,
2136 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2137 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2138 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2139 exp.X, exp.Y, exp.Width, exp.Height);
2141 /* clipping rect partially outside of window */
2142 clipr.X = window.Width - 10;
2143 clipr.Y = window.Height - 15;
2144 clipr.Width = 20;
2145 clipr.Height = 30;
2147 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2148 expect(Ok, status);
2150 exp.X = window.Width - 10;
2151 exp.Y = window.Height - 15;
2152 exp.Width = 10;
2153 exp.Height = 15;
2155 status = GdipGetVisibleClipBounds(graphics, &rectf);
2156 expect(Ok, status);
2157 ok(rectf.X == exp.X &&
2158 rectf.Y == exp.Y &&
2159 rectf.Width == exp.Width &&
2160 rectf.Height == exp.Height,
2161 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2162 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2163 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2164 exp.X, exp.Y, exp.Width, exp.Height);
2166 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2167 expect(Ok, status);
2168 ok(recti.X == exp.X &&
2169 recti.Y == exp.Y &&
2170 recti.Width == exp.Width &&
2171 recti.Height == exp.Height,
2172 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2173 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2174 recti.X, recti.Y, recti.Width, recti.Height,
2175 exp.X, exp.Y, exp.Width, exp.Height);
2177 GdipDeleteGraphics(graphics);
2178 EndPaint(hwnd, &ps);
2181 static void test_GdipGetVisibleClipBounds(void)
2183 GpGraphics* graphics = NULL;
2184 GpRectF rectf;
2185 GpRect rect;
2186 HDC hdc = GetDC( hwnd );
2187 GpStatus status;
2189 status = GdipCreateFromHDC(hdc, &graphics);
2190 expect(Ok, status);
2191 ok(graphics != NULL, "Expected graphics to be initialized\n");
2193 /* test null parameters */
2194 status = GdipGetVisibleClipBounds(graphics, NULL);
2195 expect(InvalidParameter, status);
2197 status = GdipGetVisibleClipBounds(NULL, &rectf);
2198 expect(InvalidParameter, status);
2200 status = GdipGetVisibleClipBoundsI(graphics, NULL);
2201 expect(InvalidParameter, status);
2203 status = GdipGetVisibleClipBoundsI(NULL, &rect);
2204 expect(InvalidParameter, status);
2206 GdipDeleteGraphics(graphics);
2207 ReleaseDC(hwnd, hdc);
2209 test_GdipGetVisibleClipBounds_screen();
2210 test_GdipGetVisibleClipBounds_window();
2213 static void test_fromMemoryBitmap(void)
2215 GpStatus status;
2216 GpGraphics *graphics = NULL;
2217 GpBitmap *bitmap = NULL;
2218 BYTE bits[48] = {0};
2219 HDC hdc=NULL;
2220 COLORREF color;
2222 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2223 expect(Ok, status);
2225 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2226 expect(Ok, status);
2228 status = GdipGraphicsClear(graphics, 0xff686868);
2229 expect(Ok, status);
2231 GdipDeleteGraphics(graphics);
2233 /* drawing writes to the memory provided */
2234 todo_wine expect(0x68, bits[10]);
2236 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2237 expect(Ok, status);
2239 status = GdipGetDC(graphics, &hdc);
2240 expect(Ok, status);
2241 ok(hdc != NULL, "got NULL hdc\n");
2243 color = GetPixel(hdc, 0, 0);
2244 /* The HDC is write-only, and native fills with a solid color to figure out
2245 * which pixels have changed. */
2246 todo_wine expect(0x0c0b0d, color);
2248 SetPixel(hdc, 0, 0, 0x797979);
2249 SetPixel(hdc, 1, 0, 0x0c0b0d);
2251 status = GdipReleaseDC(graphics, hdc);
2252 expect(Ok, status);
2254 GdipDeleteGraphics(graphics);
2256 expect(0x79, bits[0]);
2257 todo_wine expect(0x68, bits[3]);
2259 GdipDisposeImage((GpImage*)bitmap);
2261 /* We get the same kind of write-only HDC for a "normal" bitmap */
2262 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2263 expect(Ok, status);
2265 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2266 expect(Ok, status);
2268 status = GdipGetDC(graphics, &hdc);
2269 expect(Ok, status);
2270 ok(hdc != NULL, "got NULL hdc\n");
2272 color = GetPixel(hdc, 0, 0);
2273 todo_wine expect(0x0c0b0d, color);
2275 status = GdipReleaseDC(graphics, hdc);
2276 expect(Ok, status);
2278 GdipDeleteGraphics(graphics);
2280 GdipDisposeImage((GpImage*)bitmap);
2283 static void test_GdipIsVisiblePoint(void)
2285 GpStatus status;
2286 GpGraphics *graphics = NULL;
2287 HDC hdc = GetDC( hwnd );
2288 REAL x, y;
2289 BOOL val;
2291 ok(hdc != NULL, "Expected HDC to be initialized\n");
2293 status = GdipCreateFromHDC(hdc, &graphics);
2294 expect(Ok, status);
2295 ok(graphics != NULL, "Expected graphics to be initialized\n");
2297 /* null parameters */
2298 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2299 expect(InvalidParameter, status);
2301 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2302 expect(InvalidParameter, status);
2304 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2305 expect(InvalidParameter, status);
2307 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2308 expect(InvalidParameter, status);
2310 x = 0;
2311 y = 0;
2312 status = GdipIsVisiblePoint(graphics, x, y, &val);
2313 expect(Ok, status);
2314 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2316 x = -10;
2317 y = 0;
2318 status = GdipIsVisiblePoint(graphics, x, y, &val);
2319 expect(Ok, status);
2320 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2322 x = 0;
2323 y = -5;
2324 status = GdipIsVisiblePoint(graphics, x, y, &val);
2325 expect(Ok, status);
2326 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2328 x = 1;
2329 y = 1;
2330 status = GdipIsVisiblePoint(graphics, x, y, &val);
2331 expect(Ok, status);
2332 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2334 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2335 expect(Ok, status);
2337 x = 1;
2338 y = 1;
2339 status = GdipIsVisiblePoint(graphics, x, y, &val);
2340 expect(Ok, status);
2341 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2343 x = 15.5;
2344 y = 40.5;
2345 status = GdipIsVisiblePoint(graphics, x, y, &val);
2346 expect(Ok, status);
2347 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2349 /* translate into the center of the rect */
2350 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2352 x = 0;
2353 y = 0;
2354 status = GdipIsVisiblePoint(graphics, x, y, &val);
2355 expect(Ok, status);
2356 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2358 x = 25;
2359 y = 40;
2360 status = GdipIsVisiblePoint(graphics, x, y, &val);
2361 expect(Ok, status);
2362 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2364 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2366 /* corner cases */
2367 x = 9;
2368 y = 19;
2369 status = GdipIsVisiblePoint(graphics, x, y, &val);
2370 expect(Ok, status);
2371 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2373 x = 9.25;
2374 y = 19.25;
2375 status = GdipIsVisiblePoint(graphics, x, y, &val);
2376 expect(Ok, status);
2377 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2379 x = 9.5;
2380 y = 19.5;
2381 status = GdipIsVisiblePoint(graphics, x, y, &val);
2382 expect(Ok, status);
2383 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2385 x = 9.75;
2386 y = 19.75;
2387 status = GdipIsVisiblePoint(graphics, x, y, &val);
2388 expect(Ok, status);
2389 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2391 x = 10;
2392 y = 20;
2393 status = GdipIsVisiblePoint(graphics, x, y, &val);
2394 expect(Ok, status);
2395 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2397 x = 40;
2398 y = 20;
2399 status = GdipIsVisiblePoint(graphics, x, y, &val);
2400 expect(Ok, status);
2401 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2403 x = 39;
2404 y = 59;
2405 status = GdipIsVisiblePoint(graphics, x, y, &val);
2406 expect(Ok, status);
2407 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2409 x = 39.25;
2410 y = 59.25;
2411 status = GdipIsVisiblePoint(graphics, x, y, &val);
2412 expect(Ok, status);
2413 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2415 x = 39.5;
2416 y = 39.5;
2417 status = GdipIsVisiblePoint(graphics, x, y, &val);
2418 expect(Ok, status);
2419 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2421 x = 39.75;
2422 y = 59.75;
2423 status = GdipIsVisiblePoint(graphics, x, y, &val);
2424 expect(Ok, status);
2425 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2427 x = 40;
2428 y = 60;
2429 status = GdipIsVisiblePoint(graphics, x, y, &val);
2430 expect(Ok, status);
2431 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2433 x = 40.15;
2434 y = 60.15;
2435 status = GdipIsVisiblePoint(graphics, x, y, &val);
2436 expect(Ok, status);
2437 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2439 x = 10;
2440 y = 60;
2441 status = GdipIsVisiblePoint(graphics, x, y, &val);
2442 expect(Ok, status);
2443 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2445 /* integer version */
2446 x = 25;
2447 y = 30;
2448 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2449 expect(Ok, status);
2450 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2452 x = 50;
2453 y = 100;
2454 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2455 expect(Ok, status);
2456 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2458 GdipDeleteGraphics(graphics);
2459 ReleaseDC(hwnd, hdc);
2462 static void test_GdipIsVisibleRect(void)
2464 GpStatus status;
2465 GpGraphics *graphics = NULL;
2466 HDC hdc = GetDC( hwnd );
2467 REAL x, y, width, height;
2468 BOOL val;
2470 ok(hdc != NULL, "Expected HDC to be initialized\n");
2472 status = GdipCreateFromHDC(hdc, &graphics);
2473 expect(Ok, status);
2474 ok(graphics != NULL, "Expected graphics to be initialized\n");
2476 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2477 expect(InvalidParameter, status);
2479 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2480 expect(InvalidParameter, status);
2482 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2483 expect(InvalidParameter, status);
2485 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2486 expect(InvalidParameter, status);
2488 /* entirely within the visible region */
2489 x = 0; width = 10;
2490 y = 0; height = 10;
2491 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2492 expect(Ok, status);
2493 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2495 /* partially outside */
2496 x = -10; width = 20;
2497 y = -10; height = 20;
2498 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2499 expect(Ok, status);
2500 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2502 /* entirely outside */
2503 x = -10; width = 5;
2504 y = -10; height = 5;
2505 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2506 expect(Ok, status);
2507 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2509 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2510 expect(Ok, status);
2512 /* entirely within the visible region */
2513 x = 12; width = 10;
2514 y = 22; height = 10;
2515 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2516 expect(Ok, status);
2517 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2519 /* partially outside */
2520 x = 35; width = 10;
2521 y = 55; height = 10;
2522 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2523 expect(Ok, status);
2524 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2526 /* entirely outside */
2527 x = 45; width = 5;
2528 y = 65; height = 5;
2529 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2530 expect(Ok, status);
2531 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2533 /* translate into center of clipping rect */
2534 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2536 x = 0; width = 10;
2537 y = 0; height = 10;
2538 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2539 expect(Ok, status);
2540 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2542 x = 25; width = 5;
2543 y = 40; height = 5;
2544 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2545 expect(Ok, status);
2546 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2548 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2550 /* corners entirely outside, but some intersections */
2551 x = 0; width = 70;
2552 y = 0; height = 90;
2553 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2554 expect(Ok, status);
2555 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2557 x = 0; width = 70;
2558 y = 0; height = 30;
2559 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2560 expect(Ok, status);
2561 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2563 x = 0; width = 30;
2564 y = 0; height = 90;
2565 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2566 expect(Ok, status);
2567 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2569 /* edge cases */
2570 x = 0; width = 10;
2571 y = 20; height = 40;
2572 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2573 expect(Ok, status);
2574 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2576 x = 10; width = 30;
2577 y = 0; height = 20;
2578 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2579 expect(Ok, status);
2580 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2582 x = 40; width = 10;
2583 y = 20; height = 40;
2584 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2585 expect(Ok, status);
2586 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2588 x = 10; width = 30;
2589 y = 60; height = 10;
2590 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2591 expect(Ok, status);
2592 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2594 /* rounding tests */
2595 x = 0.4; width = 10.4;
2596 y = 20; height = 40;
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);
2601 x = 10; width = 30;
2602 y = 0.4; height = 20.4;
2603 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2604 expect(Ok, status);
2605 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2607 /* integer version */
2608 x = 0; width = 30;
2609 y = 0; height = 90;
2610 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2611 expect(Ok, status);
2612 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2614 x = 12; width = 10;
2615 y = 22; height = 10;
2616 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2617 expect(Ok, status);
2618 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2620 GdipDeleteGraphics(graphics);
2621 ReleaseDC(hwnd, hdc);
2624 static void test_GdipGetNearestColor(void)
2626 GpStatus status;
2627 GpGraphics *graphics;
2628 GpBitmap *bitmap;
2629 ARGB color = 0xdeadbeef;
2630 HDC hdc = GetDC( hwnd );
2632 /* create a graphics object */
2633 ok(hdc != NULL, "Expected HDC to be initialized\n");
2635 status = GdipCreateFromHDC(hdc, &graphics);
2636 expect(Ok, status);
2637 ok(graphics != NULL, "Expected graphics to be initialized\n");
2639 status = GdipGetNearestColor(graphics, NULL);
2640 expect(InvalidParameter, status);
2642 status = GdipGetNearestColor(NULL, &color);
2643 expect(InvalidParameter, status);
2644 GdipDeleteGraphics(graphics);
2646 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2647 expect(Ok, status);
2648 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2649 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2650 if (status == Ok)
2652 status = GdipGetNearestColor(graphics, &color);
2653 expect(Ok, status);
2654 expect(0xdeadbeef, color);
2655 GdipDeleteGraphics(graphics);
2657 GdipDisposeImage((GpImage*)bitmap);
2659 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2660 expect(Ok, status);
2661 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2662 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2663 if (status == Ok)
2665 status = GdipGetNearestColor(graphics, &color);
2666 expect(Ok, status);
2667 expect(0xdeadbeef, color);
2668 GdipDeleteGraphics(graphics);
2670 GdipDisposeImage((GpImage*)bitmap);
2672 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2673 expect(Ok, status);
2674 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2675 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2676 if (status == Ok)
2678 status = GdipGetNearestColor(graphics, &color);
2679 expect(Ok, status);
2680 expect(0xdeadbeef, color);
2681 GdipDeleteGraphics(graphics);
2683 GdipDisposeImage((GpImage*)bitmap);
2685 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2686 expect(Ok, status);
2687 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2688 todo_wine expect(OutOfMemory, status);
2689 if (status == Ok)
2690 GdipDeleteGraphics(graphics);
2691 GdipDisposeImage((GpImage*)bitmap);
2693 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2694 expect(Ok, status);
2695 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2696 expect(Ok, status);
2697 status = GdipGetNearestColor(graphics, &color);
2698 expect(Ok, status);
2699 expect(0xdeadbeef, color);
2700 GdipDeleteGraphics(graphics);
2701 GdipDisposeImage((GpImage*)bitmap);
2703 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2704 expect(Ok, status);
2705 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2706 expect(Ok, status);
2707 status = GdipGetNearestColor(graphics, &color);
2708 expect(Ok, status);
2709 expect(0xdeadbeef, color);
2710 GdipDeleteGraphics(graphics);
2711 GdipDisposeImage((GpImage*)bitmap);
2713 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2714 expect(Ok, status);
2715 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2716 expect(Ok, status);
2717 status = GdipGetNearestColor(graphics, &color);
2718 expect(Ok, status);
2719 expect(0xdeadbeef, color);
2720 GdipDeleteGraphics(graphics);
2721 GdipDisposeImage((GpImage*)bitmap);
2723 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2724 expect(Ok, status);
2725 if (status == Ok)
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);
2736 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2737 expect(Ok, status);
2738 if (status == Ok)
2740 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2741 expect(Ok, status);
2742 status = GdipGetNearestColor(graphics, &color);
2743 expect(Ok, status);
2744 expect(0xdeadbeef, color);
2745 GdipDeleteGraphics(graphics);
2746 GdipDisposeImage((GpImage*)bitmap);
2749 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2750 expect(Ok, status);
2751 if (status == Ok)
2753 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2754 expect(Ok, status);
2755 status = GdipGetNearestColor(graphics, &color);
2756 expect(Ok, status);
2757 expect(0xdeadbeef, color);
2758 GdipDeleteGraphics(graphics);
2759 GdipDisposeImage((GpImage*)bitmap);
2762 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
2763 expect(Ok, status);
2764 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2765 expect(Ok, status);
2766 status = GdipGetNearestColor(graphics, &color);
2767 expect(Ok, status);
2768 todo_wine expect(0xffa8bce8, color);
2769 GdipDeleteGraphics(graphics);
2770 GdipDisposeImage((GpImage*)bitmap);
2772 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
2773 expect(Ok, status);
2774 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2775 expect(Ok, status);
2776 status = GdipGetNearestColor(graphics, &color);
2777 expect(Ok, status);
2778 todo_wine
2779 ok(color == 0xffa8b8e8 ||
2780 broken(color == 0xffa0b8e0), /* Win98/WinMe */
2781 "Expected ffa8b8e8, got %.8x\n", color);
2782 GdipDeleteGraphics(graphics);
2783 GdipDisposeImage((GpImage*)bitmap);
2785 ReleaseDC(hwnd, hdc);
2788 static void test_string_functions(void)
2790 GpStatus status;
2791 GpGraphics *graphics;
2792 GpFontFamily *family;
2793 GpFont *font;
2794 RectF rc, char_bounds, bounds;
2795 GpBrush *brush;
2796 ARGB color = 0xff000000;
2797 HDC hdc = GetDC( hwnd );
2798 const WCHAR fontname[] = {'T','a','h','o','m','a',0};
2799 const WCHAR teststring[] = {'M','M',' ','M','\n','M',0};
2800 REAL char_width, char_height;
2801 INT codepointsfitted, linesfilled;
2802 GpStringFormat *format;
2803 CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
2804 GpRegion *regions[4] = {0};
2805 BOOL region_isempty[4];
2806 int i;
2808 ok(hdc != NULL, "Expected HDC to be initialized\n");
2809 status = GdipCreateFromHDC(hdc, &graphics);
2810 expect(Ok, status);
2811 ok(graphics != NULL, "Expected graphics to be initialized\n");
2813 status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
2814 expect(Ok, status);
2816 status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
2817 expect(Ok, status);
2819 status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
2820 expect(Ok, status);
2822 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
2823 expect(Ok, status);
2825 rc.X = 0;
2826 rc.Y = 0;
2827 rc.Width = 100.0;
2828 rc.Height = 100.0;
2830 status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
2831 expect(InvalidParameter, status);
2833 status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
2834 expect(InvalidParameter, status);
2836 status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
2837 expect(InvalidParameter, status);
2839 status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
2840 expect(InvalidParameter, status);
2842 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
2843 expect(InvalidParameter, status);
2845 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
2846 expect(Ok, status);
2848 status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2849 expect(InvalidParameter, status);
2851 status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2852 expect(InvalidParameter, status);
2854 status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2855 expect(InvalidParameter, status);
2857 status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
2858 expect(InvalidParameter, status);
2860 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
2861 expect(InvalidParameter, status);
2863 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
2864 expect(Ok, status);
2866 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
2867 expect(Ok, status);
2869 status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
2870 expect(Ok, status);
2871 expectf(0.0, char_bounds.X);
2872 expectf(0.0, char_bounds.Y);
2873 ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
2874 ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
2875 expect(1, codepointsfitted);
2876 expect(1, linesfilled);
2878 status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2879 expect(Ok, status);
2880 expectf(0.0, bounds.X);
2881 expectf(0.0, bounds.Y);
2882 ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
2883 expectf(char_bounds.Height, bounds.Height);
2884 expect(2, codepointsfitted);
2885 expect(1, linesfilled);
2886 char_width = bounds.Width - char_bounds.Width;
2888 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2889 expect(Ok, status);
2890 expectf(0.0, bounds.X);
2891 expectf(0.0, bounds.Y);
2892 ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
2893 bounds.Width, char_bounds.Width + char_width * 2);
2894 ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
2895 expect(6, codepointsfitted);
2896 expect(2, linesfilled);
2897 char_height = bounds.Height - char_bounds.Height;
2899 /* Cut off everything after the first space. */
2900 rc.Width = char_bounds.Width + char_width * 2.1;
2902 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2903 expect(Ok, status);
2904 expectf(0.0, bounds.X);
2905 expectf(0.0, bounds.Y);
2906 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
2907 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
2908 expect(6, codepointsfitted);
2909 expect(3, linesfilled);
2911 /* Cut off everything including the first space. */
2912 rc.Width = char_bounds.Width + char_width * 1.5;
2914 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2915 expect(Ok, status);
2916 expectf(0.0, bounds.X);
2917 expectf(0.0, bounds.Y);
2918 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
2919 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
2920 expect(6, codepointsfitted);
2921 expect(3, linesfilled);
2923 /* Cut off everything after the first character. */
2924 rc.Width = char_bounds.Width + char_width * 0.5;
2926 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2927 expect(Ok, status);
2928 expectf(0.0, bounds.X);
2929 expectf(0.0, bounds.Y);
2930 expectf_(char_bounds.Width, bounds.Width, 0.01);
2931 todo_wine expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
2932 expect(6, codepointsfitted);
2933 todo_wine expect(4, linesfilled);
2935 status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
2936 expect(Ok, status);
2938 rc.Width = 100.0;
2940 for (i=0; i<4; i++)
2942 status = GdipCreateRegion(&regions[i]);
2943 expect(Ok, status);
2946 status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
2947 expect(InvalidParameter, status);
2949 status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
2950 expect(InvalidParameter, status);
2952 status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
2953 expect(InvalidParameter, status);
2955 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
2956 expect(InvalidParameter, status);
2958 if (0)
2960 /* Crashes on Windows XP */
2961 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
2962 expect(InvalidParameter, status);
2965 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
2966 expect(InvalidParameter, status);
2968 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
2969 expect(InvalidParameter, status);
2971 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
2972 expect(Ok, status);
2974 for (i=0; i<4; i++)
2976 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
2977 expect(Ok, status);
2980 ok(!region_isempty[0], "region shouldn't be empty\n");
2981 ok(!region_isempty[1], "region shouldn't be empty\n");
2982 ok(!region_isempty[2], "region shouldn't be empty\n");
2983 ok(!region_isempty[3], "region shouldn't be empty\n");
2985 /* Cut off everything after the first space, and the second line. */
2986 rc.Width = char_bounds.Width + char_width * 2.1;
2987 rc.Height = char_bounds.Height + char_height * 0.5;
2989 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
2990 expect(Ok, status);
2992 for (i=0; i<4; i++)
2994 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
2995 expect(Ok, status);
2998 ok(!region_isempty[0], "region shouldn't be empty\n");
2999 ok(!region_isempty[1], "region shouldn't be empty\n");
3000 ok(region_isempty[2], "region should be empty\n");
3001 ok(!region_isempty[3], "region shouldn't be empty\n");
3003 for (i=0; i<4; i++)
3004 GdipDeleteRegion(regions[i]);
3006 GdipDeleteStringFormat(format);
3007 GdipDeleteBrush(brush);
3008 GdipDeleteFont(font);
3009 GdipDeleteFontFamily(family);
3010 GdipDeleteGraphics(graphics);
3012 ReleaseDC(hwnd, hdc);
3015 static void test_get_set_interpolation(void)
3017 GpGraphics *graphics;
3018 HDC hdc = GetDC( hwnd );
3019 GpStatus status;
3020 InterpolationMode mode;
3022 ok(hdc != NULL, "Expected HDC to be initialized\n");
3023 status = GdipCreateFromHDC(hdc, &graphics);
3024 expect(Ok, status);
3025 ok(graphics != NULL, "Expected graphics to be initialized\n");
3027 status = GdipGetInterpolationMode(NULL, &mode);
3028 expect(InvalidParameter, status);
3030 if (0)
3032 /* Crashes on Windows XP */
3033 status = GdipGetInterpolationMode(graphics, NULL);
3034 expect(InvalidParameter, status);
3037 status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor);
3038 expect(InvalidParameter, status);
3040 /* out of range */
3041 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1);
3042 expect(InvalidParameter, status);
3044 status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid);
3045 expect(InvalidParameter, status);
3047 status = GdipGetInterpolationMode(graphics, &mode);
3048 expect(Ok, status);
3049 expect(InterpolationModeBilinear, mode);
3051 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3052 expect(Ok, status);
3054 status = GdipGetInterpolationMode(graphics, &mode);
3055 expect(Ok, status);
3056 expect(InterpolationModeNearestNeighbor, mode);
3058 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
3059 expect(Ok, status);
3061 status = GdipGetInterpolationMode(graphics, &mode);
3062 expect(Ok, status);
3063 expect(InterpolationModeBilinear, mode);
3065 status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality);
3066 expect(Ok, status);
3068 status = GdipGetInterpolationMode(graphics, &mode);
3069 expect(Ok, status);
3070 expect(InterpolationModeBilinear, mode);
3072 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality);
3073 expect(Ok, status);
3075 status = GdipGetInterpolationMode(graphics, &mode);
3076 expect(Ok, status);
3077 expect(InterpolationModeHighQualityBicubic, mode);
3079 GdipDeleteGraphics(graphics);
3081 ReleaseDC(hwnd, hdc);
3084 START_TEST(graphics)
3086 struct GdiplusStartupInput gdiplusStartupInput;
3087 ULONG_PTR gdiplusToken;
3088 WNDCLASSA class;
3090 memset( &class, 0, sizeof(class) );
3091 class.lpszClassName = "gdiplus_test";
3092 class.style = CS_HREDRAW | CS_VREDRAW;
3093 class.lpfnWndProc = DefWindowProcA;
3094 class.hInstance = GetModuleHandleA(0);
3095 class.hIcon = LoadIcon(0, IDI_APPLICATION);
3096 class.hCursor = LoadCursor(NULL, IDC_ARROW);
3097 class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
3098 RegisterClassA( &class );
3099 hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3100 CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
3101 ok(hwnd != NULL, "Expected window to be created\n");
3103 gdiplusStartupInput.GdiplusVersion = 1;
3104 gdiplusStartupInput.DebugEventCallback = NULL;
3105 gdiplusStartupInput.SuppressBackgroundThread = 0;
3106 gdiplusStartupInput.SuppressExternalCodecs = 0;
3108 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
3110 test_constructor_destructor();
3111 test_save_restore();
3112 test_GdipFillClosedCurve2();
3113 test_GdipFillClosedCurve2I();
3114 test_GdipDrawBezierI();
3115 test_GdipDrawArc();
3116 test_GdipDrawArcI();
3117 test_GdipDrawCurve();
3118 test_GdipDrawCurveI();
3119 test_GdipDrawCurve2();
3120 test_GdipDrawCurve2I();
3121 test_GdipDrawCurve3();
3122 test_GdipDrawCurve3I();
3123 test_GdipDrawLineI();
3124 test_GdipDrawLinesI();
3125 test_GdipDrawImagePointsRect();
3126 test_GdipFillClosedCurve();
3127 test_GdipFillClosedCurveI();
3128 test_GdipDrawString();
3129 test_GdipGetNearestColor();
3130 test_GdipGetVisibleClipBounds();
3131 test_GdipIsVisiblePoint();
3132 test_GdipIsVisibleRect();
3133 test_Get_Release_DC();
3134 test_BeginContainer2();
3135 test_transformpoints();
3136 test_get_set_clip();
3137 test_isempty();
3138 test_clear();
3139 test_textcontrast();
3140 test_fromMemoryBitmap();
3141 test_string_functions();
3142 test_get_set_interpolation();
3144 GdiplusShutdown(gdiplusToken);
3145 DestroyWindow( hwnd );