krnl386.exe16: Update a comment.
[wine/testsucceed.git] / dlls / gdiplus / tests / graphics.c
blob57ce638093c277be5735070e76dcad2d0ce51d66
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_GdipDrawArc(void)
235 GpStatus status;
236 GpGraphics *graphics = NULL;
237 GpPen *pen = NULL;
238 HDC hdc = GetDC( hwnd );
240 /* make a graphics object and pen object */
241 ok(hdc != NULL, "Expected HDC to be initialized\n");
243 status = GdipCreateFromHDC(hdc, &graphics);
244 expect(Ok, status);
245 ok(graphics != NULL, "Expected graphics to be initialized\n");
247 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
248 expect(Ok, status);
249 ok(pen != NULL, "Expected pen to be initialized\n");
251 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
252 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
253 expect(InvalidParameter, status);
255 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
256 expect(InvalidParameter, status);
258 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
259 expect(InvalidParameter, status);
261 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
262 expect(InvalidParameter, status);
264 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
265 expect(InvalidParameter, status);
267 /* successful case */
268 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
269 expect(Ok, status);
271 GdipDeletePen(pen);
272 GdipDeleteGraphics(graphics);
274 ReleaseDC(hwnd, hdc);
277 static void test_GdipDrawArcI(void)
279 GpStatus status;
280 GpGraphics *graphics = NULL;
281 GpPen *pen = NULL;
282 HDC hdc = GetDC( hwnd );
284 /* make a graphics object and pen object */
285 ok(hdc != NULL, "Expected HDC to be initialized\n");
287 status = GdipCreateFromHDC(hdc, &graphics);
288 expect(Ok, status);
289 ok(graphics != NULL, "Expected graphics to be initialized\n");
291 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
292 expect(Ok, status);
293 ok(pen != NULL, "Expected pen to be initialized\n");
295 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
296 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
297 expect(InvalidParameter, status);
299 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
300 expect(InvalidParameter, status);
302 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
303 expect(InvalidParameter, status);
305 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
306 expect(InvalidParameter, status);
308 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
309 expect(InvalidParameter, status);
311 /* successful case */
312 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
313 expect(Ok, status);
315 GdipDeletePen(pen);
316 GdipDeleteGraphics(graphics);
318 ReleaseDC(hwnd, hdc);
321 static void test_BeginContainer2(void)
323 GpMatrix *transform;
324 GpRectF clip;
325 REAL defClip[] = {5, 10, 15, 20};
326 REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
327 GraphicsContainer cont1, cont2, cont3, cont4;
328 CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
329 CompositingMode compmode, defCompmode = CompositingModeSourceOver;
330 InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
331 REAL scale, defScale = 17;
332 GpUnit unit, defUnit = UnitPixel;
333 PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
334 SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
335 UINT contrast, defContrast = 5;
336 TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
338 GpStatus status;
339 GpGraphics *graphics = NULL;
340 HDC hdc = GetDC( hwnd );
342 ok(hdc != NULL, "Expected HDC to be initialized\n");
344 status = GdipCreateFromHDC(hdc, &graphics);
345 expect(Ok, status);
346 ok(graphics != NULL, "Expected graphics to be initialized\n");
348 /* null graphics, null container */
349 status = GdipBeginContainer2(NULL, &cont1);
350 expect(InvalidParameter, status);
352 status = GdipBeginContainer2(graphics, NULL);
353 expect(InvalidParameter, status);
355 status = GdipEndContainer(NULL, cont1);
356 expect(InvalidParameter, status);
358 /* test all quality-related values */
359 GdipSetCompositingMode(graphics, defCompmode);
360 GdipSetCompositingQuality(graphics, defCompqual);
361 GdipSetInterpolationMode(graphics, defInterp);
362 GdipSetPageScale(graphics, defScale);
363 GdipSetPageUnit(graphics, defUnit);
364 GdipSetPixelOffsetMode(graphics, defOffsetmode);
365 GdipSetSmoothingMode(graphics, defSmoothmode);
366 GdipSetTextContrast(graphics, defContrast);
367 GdipSetTextRenderingHint(graphics, defTexthint);
369 status = GdipBeginContainer2(graphics, &cont1);
370 expect(Ok, status);
372 GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
373 GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
374 GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
375 GdipSetPageScale(graphics, 10);
376 GdipSetPageUnit(graphics, UnitDocument);
377 GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
378 GdipSetSmoothingMode(graphics, SmoothingModeNone);
379 GdipSetTextContrast(graphics, 7);
380 GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
382 status = GdipEndContainer(graphics, cont1);
383 expect(Ok, status);
385 GdipGetCompositingMode(graphics, &compmode);
386 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
388 GdipGetCompositingQuality(graphics, &compqual);
389 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
391 GdipGetInterpolationMode(graphics, &interp);
392 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
394 GdipGetPageScale(graphics, &scale);
395 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
397 GdipGetPageUnit(graphics, &unit);
398 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
400 GdipGetPixelOffsetMode(graphics, &offsetmode);
401 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
403 GdipGetSmoothingMode(graphics, &smoothmode);
404 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
406 GdipGetTextContrast(graphics, &contrast);
407 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
409 GdipGetTextRenderingHint(graphics, &texthint);
410 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
412 /* test world transform */
413 status = GdipBeginContainer2(graphics, &cont1);
414 expect(Ok, status);
416 GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
417 defTrans[4], defTrans[5], &transform);
418 GdipSetWorldTransform(graphics, transform);
419 GdipDeleteMatrix(transform);
420 transform = NULL;
422 status = GdipBeginContainer2(graphics, &cont2);
423 expect(Ok, status);
425 GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
426 GdipSetWorldTransform(graphics, transform);
427 GdipDeleteMatrix(transform);
428 transform = NULL;
430 status = GdipEndContainer(graphics, cont2);
431 expect(Ok, status);
433 GdipCreateMatrix(&transform);
434 GdipGetWorldTransform(graphics, transform);
435 GdipGetMatrixElements(transform, elems);
436 ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
437 fabs(defTrans[1] - elems[1]) < 0.0001 &&
438 fabs(defTrans[2] - elems[2]) < 0.0001 &&
439 fabs(defTrans[3] - elems[3]) < 0.0001 &&
440 fabs(defTrans[4] - elems[4]) < 0.0001 &&
441 fabs(defTrans[5] - elems[5]) < 0.0001,
442 "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
443 defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
444 elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
445 GdipDeleteMatrix(transform);
446 transform = NULL;
448 status = GdipEndContainer(graphics, cont1);
449 expect(Ok, status);
451 /* test clipping */
452 status = GdipBeginContainer2(graphics, &cont1);
453 expect(Ok, status);
455 GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
457 status = GdipBeginContainer2(graphics, &cont2);
458 expect(Ok, status);
460 GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
462 status = GdipEndContainer(graphics, cont2);
464 GdipGetClipBounds(graphics, &clip);
465 ok(fabs(defClip[0] - clip.X) < 0.0001 &&
466 fabs(defClip[1] - clip.Y) < 0.0001 &&
467 fabs(defClip[2] - clip.Width) < 0.0001 &&
468 fabs(defClip[3] - clip.Height) < 0.0001,
469 "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
470 defClip[0], defClip[1], defClip[2], defClip[3],
471 clip.X, clip.Y, clip.Width, clip.Height);
473 status = GdipEndContainer(graphics, cont1);
475 /* nesting */
476 status = GdipBeginContainer2(graphics, &cont1);
477 expect(Ok, status);
479 status = GdipBeginContainer2(graphics, &cont2);
480 expect(Ok, status);
482 status = GdipBeginContainer2(graphics, &cont3);
483 expect(Ok, status);
485 status = GdipEndContainer(graphics, cont3);
486 expect(Ok, status);
488 status = GdipBeginContainer2(graphics, &cont4);
489 expect(Ok, status);
491 status = GdipEndContainer(graphics, cont4);
492 expect(Ok, status);
494 /* skip cont2 */
495 status = GdipEndContainer(graphics, cont1);
496 expect(Ok, status);
498 /* end an already-ended container */
499 status = GdipEndContainer(graphics, cont1);
500 expect(Ok, status);
502 GdipDeleteGraphics(graphics);
503 ReleaseDC(hwnd, hdc);
506 static void test_GdipDrawBezierI(void)
508 GpStatus status;
509 GpGraphics *graphics = NULL;
510 GpPen *pen = NULL;
511 HDC hdc = GetDC( hwnd );
513 /* make a graphics object and pen object */
514 ok(hdc != NULL, "Expected HDC to be initialized\n");
516 status = GdipCreateFromHDC(hdc, &graphics);
517 expect(Ok, status);
518 ok(graphics != NULL, "Expected graphics to be initialized\n");
520 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
521 expect(Ok, status);
522 ok(pen != NULL, "Expected pen to be initialized\n");
524 /* InvalidParameter cases: null graphics, null pen */
525 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
526 expect(InvalidParameter, status);
528 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
529 expect(InvalidParameter, status);
531 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
532 expect(InvalidParameter, status);
534 /* successful case */
535 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
536 expect(Ok, status);
538 GdipDeletePen(pen);
539 GdipDeleteGraphics(graphics);
541 ReleaseDC(hwnd, hdc);
544 static void test_GdipDrawCurve3(void)
546 GpStatus status;
547 GpGraphics *graphics = NULL;
548 GpPen *pen = NULL;
549 HDC hdc = GetDC( hwnd );
550 GpPointF points[3];
552 points[0].X = 0;
553 points[0].Y = 0;
555 points[1].X = 40;
556 points[1].Y = 20;
558 points[2].X = 10;
559 points[2].Y = 40;
561 /* make a graphics object and pen object */
562 ok(hdc != NULL, "Expected HDC to be initialized\n");
564 status = GdipCreateFromHDC(hdc, &graphics);
565 expect(Ok, status);
566 ok(graphics != NULL, "Expected graphics to be initialized\n");
568 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
569 expect(Ok, status);
570 ok(pen != NULL, "Expected pen to be initialized\n");
572 /* InvalidParameter cases: null graphics, null pen */
573 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
574 expect(InvalidParameter, status);
576 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
577 expect(InvalidParameter, status);
579 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
580 expect(InvalidParameter, status);
582 /* InvalidParameter cases: invalid count */
583 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
584 expect(InvalidParameter, status);
586 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
587 expect(InvalidParameter, status);
589 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
590 expect(InvalidParameter, status);
592 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
593 expect(InvalidParameter, status);
595 /* InvalidParameter cases: invalid number of segments */
596 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
597 expect(InvalidParameter, status);
599 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
600 expect(InvalidParameter, status);
602 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
603 expect(InvalidParameter, status);
605 /* Valid test cases */
606 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
607 expect(Ok, status);
609 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
610 expect(Ok, status);
612 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
613 expect(Ok, status);
615 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
616 expect(Ok, status);
618 GdipDeletePen(pen);
619 GdipDeleteGraphics(graphics);
621 ReleaseDC(hwnd, hdc);
624 static void test_GdipDrawCurve3I(void)
626 GpStatus status;
627 GpGraphics *graphics = NULL;
628 GpPen *pen = NULL;
629 HDC hdc = GetDC( hwnd );
630 GpPoint points[3];
632 points[0].X = 0;
633 points[0].Y = 0;
635 points[1].X = 40;
636 points[1].Y = 20;
638 points[2].X = 10;
639 points[2].Y = 40;
641 /* make a graphics object and pen object */
642 ok(hdc != NULL, "Expected HDC to be initialized\n");
644 status = GdipCreateFromHDC(hdc, &graphics);
645 expect(Ok, status);
646 ok(graphics != NULL, "Expected graphics to be initialized\n");
648 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
649 expect(Ok, status);
650 ok(pen != NULL, "Expected pen to be initialized\n");
652 /* InvalidParameter cases: null graphics, null pen */
653 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
654 expect(InvalidParameter, status);
656 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
657 expect(InvalidParameter, status);
659 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
660 expect(InvalidParameter, status);
662 /* InvalidParameter cases: invalid count */
663 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
664 expect(OutOfMemory, status);
666 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
667 expect(InvalidParameter, status);
669 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
670 expect(InvalidParameter, status);
672 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
673 expect(InvalidParameter, status);
675 /* InvalidParameter cases: invalid number of segments */
676 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
677 expect(InvalidParameter, status);
679 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
680 expect(InvalidParameter, status);
682 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
683 expect(InvalidParameter, status);
685 /* Valid test cases */
686 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
687 expect(Ok, status);
689 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
690 expect(Ok, status);
692 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
693 expect(Ok, status);
695 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
696 expect(Ok, status);
698 GdipDeletePen(pen);
699 GdipDeleteGraphics(graphics);
701 ReleaseDC(hwnd, hdc);
704 static void test_GdipDrawCurve2(void)
706 GpStatus status;
707 GpGraphics *graphics = NULL;
708 GpPen *pen = NULL;
709 HDC hdc = GetDC( hwnd );
710 GpPointF points[3];
712 points[0].X = 0;
713 points[0].Y = 0;
715 points[1].X = 40;
716 points[1].Y = 20;
718 points[2].X = 10;
719 points[2].Y = 40;
721 /* make a graphics object and pen object */
722 ok(hdc != NULL, "Expected HDC to be initialized\n");
724 status = GdipCreateFromHDC(hdc, &graphics);
725 expect(Ok, status);
726 ok(graphics != NULL, "Expected graphics to be initialized\n");
728 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
729 expect(Ok, status);
730 ok(pen != NULL, "Expected pen to be initialized\n");
732 /* InvalidParameter cases: null graphics, null pen */
733 status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
734 expect(InvalidParameter, status);
736 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
737 expect(InvalidParameter, status);
739 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
740 expect(InvalidParameter, status);
742 /* InvalidParameter cases: invalid count */
743 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
744 expect(InvalidParameter, status);
746 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
747 expect(InvalidParameter, status);
749 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
750 expect(InvalidParameter, status);
752 /* Valid test cases */
753 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
754 expect(Ok, status);
756 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
757 expect(Ok, status);
759 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
760 expect(Ok, status);
762 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
763 expect(Ok, status);
765 GdipDeletePen(pen);
766 GdipDeleteGraphics(graphics);
768 ReleaseDC(hwnd, hdc);
771 static void test_GdipDrawCurve2I(void)
773 GpStatus status;
774 GpGraphics *graphics = NULL;
775 GpPen *pen = NULL;
776 HDC hdc = GetDC( hwnd );
777 GpPoint points[3];
779 points[0].X = 0;
780 points[0].Y = 0;
782 points[1].X = 40;
783 points[1].Y = 20;
785 points[2].X = 10;
786 points[2].Y = 40;
788 /* make a graphics object and pen object */
789 ok(hdc != NULL, "Expected HDC to be initialized\n");
791 status = GdipCreateFromHDC(hdc, &graphics);
792 expect(Ok, status);
793 ok(graphics != NULL, "Expected graphics to be initialized\n");
795 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
796 expect(Ok, status);
797 ok(pen != NULL, "Expected pen to be initialized\n");
799 /* InvalidParameter cases: null graphics, null pen */
800 status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
801 expect(InvalidParameter, status);
803 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
804 expect(InvalidParameter, status);
806 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
807 expect(InvalidParameter, status);
809 /* InvalidParameter cases: invalid count */
810 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
811 expect(OutOfMemory, status);
813 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
814 expect(InvalidParameter, status);
816 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
817 expect(InvalidParameter, status);
819 /* Valid test cases */
820 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
821 expect(Ok, status);
823 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
824 expect(Ok, status);
826 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
827 expect(Ok, status);
829 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
830 expect(Ok, status);
832 GdipDeletePen(pen);
833 GdipDeleteGraphics(graphics);
835 ReleaseDC(hwnd, hdc);
838 static void test_GdipDrawCurve(void)
840 GpStatus status;
841 GpGraphics *graphics = NULL;
842 GpPen *pen = NULL;
843 HDC hdc = GetDC( hwnd );
844 GpPointF points[3];
846 points[0].X = 0;
847 points[0].Y = 0;
849 points[1].X = 40;
850 points[1].Y = 20;
852 points[2].X = 10;
853 points[2].Y = 40;
855 /* make a graphics object and pen object */
856 ok(hdc != NULL, "Expected HDC to be initialized\n");
858 status = GdipCreateFromHDC(hdc, &graphics);
859 expect(Ok, status);
860 ok(graphics != NULL, "Expected graphics to be initialized\n");
862 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
863 expect(Ok, status);
864 ok(pen != NULL, "Expected pen to be initialized\n");
866 /* InvalidParameter cases: null graphics, null pen */
867 status = GdipDrawCurve(NULL, NULL, points, 3);
868 expect(InvalidParameter, status);
870 status = GdipDrawCurve(graphics, NULL, points, 3);
871 expect(InvalidParameter, status);
873 status = GdipDrawCurve(NULL, pen, points, 3);
874 expect(InvalidParameter, status);
876 /* InvalidParameter cases: invalid count */
877 status = GdipDrawCurve(graphics, pen, points, -1);
878 expect(InvalidParameter, status);
880 status = GdipDrawCurve(graphics, pen, points, 0);
881 expect(InvalidParameter, status);
883 status = GdipDrawCurve(graphics, pen, points, 1);
884 expect(InvalidParameter, status);
886 /* Valid test cases */
887 status = GdipDrawCurve(graphics, pen, points, 2);
888 expect(Ok, status);
890 status = GdipDrawCurve(graphics, pen, points, 3);
891 expect(Ok, status);
893 GdipDeletePen(pen);
894 GdipDeleteGraphics(graphics);
896 ReleaseDC(hwnd, hdc);
899 static void test_GdipDrawCurveI(void)
901 GpStatus status;
902 GpGraphics *graphics = NULL;
903 GpPen *pen = NULL;
904 HDC hdc = GetDC( hwnd );
905 GpPoint points[3];
907 points[0].X = 0;
908 points[0].Y = 0;
910 points[1].X = 40;
911 points[1].Y = 20;
913 points[2].X = 10;
914 points[2].Y = 40;
916 /* make a graphics object and pen object */
917 ok(hdc != NULL, "Expected HDC to be initialized\n");
919 status = GdipCreateFromHDC(hdc, &graphics);
920 expect(Ok, status);
921 ok(graphics != NULL, "Expected graphics to be initialized\n");
923 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
924 expect(Ok, status);
925 ok(pen != NULL, "Expected pen to be initialized\n");
927 /* InvalidParameter cases: null graphics, null pen */
928 status = GdipDrawCurveI(NULL, NULL, points, 3);
929 expect(InvalidParameter, status);
931 status = GdipDrawCurveI(graphics, NULL, points, 3);
932 expect(InvalidParameter, status);
934 status = GdipDrawCurveI(NULL, pen, points, 3);
935 expect(InvalidParameter, status);
937 /* InvalidParameter cases: invalid count */
938 status = GdipDrawCurveI(graphics, pen, points, -1);
939 expect(OutOfMemory, status);
941 status = GdipDrawCurveI(graphics, pen, points, 0);
942 expect(InvalidParameter, status);
944 status = GdipDrawCurveI(graphics, pen, points, 1);
945 expect(InvalidParameter, status);
947 /* Valid test cases */
948 status = GdipDrawCurveI(graphics, pen, points, 2);
949 expect(Ok, status);
951 status = GdipDrawCurveI(graphics, pen, points, 3);
952 expect(Ok, status);
954 GdipDeletePen(pen);
955 GdipDeleteGraphics(graphics);
957 ReleaseDC(hwnd, hdc);
960 static void test_GdipDrawLineI(void)
962 GpStatus status;
963 GpGraphics *graphics = NULL;
964 GpPen *pen = NULL;
965 HDC hdc = GetDC( hwnd );
967 /* make a graphics object and pen object */
968 ok(hdc != NULL, "Expected HDC to be initialized\n");
970 status = GdipCreateFromHDC(hdc, &graphics);
971 expect(Ok, status);
972 ok(graphics != NULL, "Expected graphics to be initialized\n");
974 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
975 expect(Ok, status);
976 ok(pen != NULL, "Expected pen to be initialized\n");
978 /* InvalidParameter cases: null graphics, null pen */
979 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
980 expect(InvalidParameter, status);
982 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
983 expect(InvalidParameter, status);
985 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
986 expect(InvalidParameter, status);
988 /* successful case */
989 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
990 expect(Ok, status);
992 GdipDeletePen(pen);
993 GdipDeleteGraphics(graphics);
995 ReleaseDC(hwnd, hdc);
998 static void test_GdipDrawLinesI(void)
1000 GpStatus status;
1001 GpGraphics *graphics = NULL;
1002 GpPen *pen = NULL;
1003 GpPoint *ptf = NULL;
1004 HDC hdc = GetDC( hwnd );
1006 /* make a graphics object and pen object */
1007 ok(hdc != NULL, "Expected HDC to be initialized\n");
1009 status = GdipCreateFromHDC(hdc, &graphics);
1010 expect(Ok, status);
1011 ok(graphics != NULL, "Expected graphics to be initialized\n");
1013 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1014 expect(Ok, status);
1015 ok(pen != NULL, "Expected pen to be initialized\n");
1017 /* make some arbitrary valid points*/
1018 ptf = GdipAlloc(2 * sizeof(GpPointF));
1020 ptf[0].X = 1;
1021 ptf[0].Y = 1;
1023 ptf[1].X = 2;
1024 ptf[1].Y = 2;
1026 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1027 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1028 expect(InvalidParameter, status);
1030 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1031 expect(InvalidParameter, status);
1033 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1034 expect(InvalidParameter, status);
1036 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1037 expect(InvalidParameter, status);
1039 /* successful case */
1040 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1041 expect(Ok, status);
1043 GdipFree(ptf);
1044 GdipDeletePen(pen);
1045 GdipDeleteGraphics(graphics);
1047 ReleaseDC(hwnd, hdc);
1050 static void test_Get_Release_DC(void)
1052 GpStatus status;
1053 GpGraphics *graphics = NULL;
1054 GpPen *pen;
1055 GpSolidFill *brush;
1056 GpPath *path;
1057 HDC hdc = GetDC( hwnd );
1058 HDC retdc;
1059 REAL r;
1060 CompositingQuality quality;
1061 CompositingMode compmode;
1062 InterpolationMode intmode;
1063 GpMatrix *m;
1064 GpRegion *region;
1065 GpUnit unit;
1066 PixelOffsetMode offsetmode;
1067 SmoothingMode smoothmode;
1068 TextRenderingHint texthint;
1069 GpPointF ptf[5];
1070 GpPoint pt[5];
1071 GpRectF rectf[2];
1072 GpRect rect[2];
1073 GpRegion *clip;
1074 INT i;
1075 BOOL res;
1076 ARGB color = 0x00000000;
1077 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1079 pt[0].X = 10;
1080 pt[0].Y = 10;
1081 pt[1].X = 20;
1082 pt[1].Y = 15;
1083 pt[2].X = 40;
1084 pt[2].Y = 80;
1085 pt[3].X = -20;
1086 pt[3].Y = 20;
1087 pt[4].X = 50;
1088 pt[4].Y = 110;
1090 for(i = 0; i < 5;i++){
1091 ptf[i].X = (REAL)pt[i].X;
1092 ptf[i].Y = (REAL)pt[i].Y;
1095 rect[0].X = 0;
1096 rect[0].Y = 0;
1097 rect[0].Width = 50;
1098 rect[0].Height = 70;
1099 rect[1].X = 0;
1100 rect[1].Y = 0;
1101 rect[1].Width = 10;
1102 rect[1].Height = 20;
1104 for(i = 0; i < 2;i++){
1105 rectf[i].X = (REAL)rect[i].X;
1106 rectf[i].Y = (REAL)rect[i].Y;
1107 rectf[i].Height = (REAL)rect[i].Height;
1108 rectf[i].Width = (REAL)rect[i].Width;
1111 GdipCreateMatrix(&m);
1112 GdipCreateRegion(&region);
1113 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1114 GdipCreatePath(FillModeAlternate, &path);
1115 GdipCreateRegion(&clip);
1117 status = GdipCreateFromHDC(hdc, &graphics);
1118 expect(Ok, status);
1119 ok(graphics != NULL, "Expected graphics to be initialized\n");
1120 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1121 expect(Ok, status);
1123 /* NULL arguments */
1124 status = GdipGetDC(NULL, NULL);
1125 expect(InvalidParameter, status);
1126 status = GdipGetDC(graphics, NULL);
1127 expect(InvalidParameter, status);
1128 status = GdipGetDC(NULL, &retdc);
1129 expect(InvalidParameter, status);
1131 status = GdipReleaseDC(NULL, NULL);
1132 expect(InvalidParameter, status);
1133 status = GdipReleaseDC(graphics, NULL);
1134 expect(InvalidParameter, status);
1135 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1136 expect(InvalidParameter, status);
1138 /* Release without Get */
1139 status = GdipReleaseDC(graphics, hdc);
1140 expect(InvalidParameter, status);
1142 retdc = NULL;
1143 status = GdipGetDC(graphics, &retdc);
1144 expect(Ok, status);
1145 ok(retdc == hdc, "Invalid HDC returned\n");
1146 /* call it once more */
1147 status = GdipGetDC(graphics, &retdc);
1148 expect(ObjectBusy, status);
1150 /* try all Graphics calls here */
1151 status = Ok;
1152 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1153 expect(ObjectBusy, status); status = Ok;
1154 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1155 expect(ObjectBusy, status); status = Ok;
1156 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1157 expect(ObjectBusy, status); status = Ok;
1158 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1159 expect(ObjectBusy, status); status = Ok;
1160 status = GdipDrawBeziers(graphics, pen, ptf, 5);
1161 expect(ObjectBusy, status); status = Ok;
1162 status = GdipDrawBeziersI(graphics, pen, pt, 5);
1163 expect(ObjectBusy, status); status = Ok;
1164 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1165 expect(ObjectBusy, status); status = Ok;
1166 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1167 expect(ObjectBusy, status); status = Ok;
1168 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1169 expect(ObjectBusy, status); status = Ok;
1170 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1171 expect(ObjectBusy, status); status = Ok;
1172 status = GdipDrawCurve(graphics, pen, ptf, 5);
1173 expect(ObjectBusy, status); status = Ok;
1174 status = GdipDrawCurveI(graphics, pen, pt, 5);
1175 expect(ObjectBusy, status); status = Ok;
1176 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1177 expect(ObjectBusy, status); status = Ok;
1178 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1179 expect(ObjectBusy, status); status = Ok;
1180 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1181 expect(ObjectBusy, status); status = Ok;
1182 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1183 expect(ObjectBusy, status); status = Ok;
1184 /* GdipDrawImage/GdipDrawImageI */
1185 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1186 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1187 /* GdipDrawImageRect/GdipDrawImageRectI */
1188 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1189 expect(ObjectBusy, status); status = Ok;
1190 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1191 expect(ObjectBusy, status); status = Ok;
1192 status = GdipDrawLines(graphics, pen, ptf, 5);
1193 expect(ObjectBusy, status); status = Ok;
1194 status = GdipDrawLinesI(graphics, pen, pt, 5);
1195 expect(ObjectBusy, status); status = Ok;
1196 status = GdipDrawPath(graphics, pen, path);
1197 expect(ObjectBusy, status); status = Ok;
1198 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1199 expect(ObjectBusy, status); status = Ok;
1200 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1201 expect(ObjectBusy, status); status = Ok;
1202 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1203 expect(ObjectBusy, status); status = Ok;
1204 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1205 expect(ObjectBusy, status); status = Ok;
1206 status = GdipDrawRectangles(graphics, pen, rectf, 2);
1207 expect(ObjectBusy, status); status = Ok;
1208 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1209 expect(ObjectBusy, status); status = Ok;
1210 /* GdipDrawString */
1211 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1212 expect(ObjectBusy, status); status = Ok;
1213 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1214 expect(ObjectBusy, status); status = Ok;
1215 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1216 expect(ObjectBusy, status); status = Ok;
1217 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1218 expect(ObjectBusy, status); status = Ok;
1219 status = GdipFillPath(graphics, (GpBrush*)brush, path);
1220 expect(ObjectBusy, status); status = Ok;
1221 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1222 expect(ObjectBusy, status); status = Ok;
1223 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1224 expect(ObjectBusy, status); status = Ok;
1225 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1226 expect(ObjectBusy, status); status = Ok;
1227 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1228 expect(ObjectBusy, status); status = Ok;
1229 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1230 expect(ObjectBusy, status); status = Ok;
1231 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1232 expect(ObjectBusy, status); status = Ok;
1233 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1234 expect(ObjectBusy, status); status = Ok;
1235 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1236 expect(ObjectBusy, status); status = Ok;
1237 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1238 expect(ObjectBusy, status); status = Ok;
1239 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1240 expect(ObjectBusy, status); status = Ok;
1241 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1242 expect(ObjectBusy, status); status = Ok;
1243 status = GdipFlush(graphics, FlushIntentionFlush);
1244 expect(ObjectBusy, status); status = Ok;
1245 status = GdipGetClipBounds(graphics, rectf);
1246 expect(ObjectBusy, status); status = Ok;
1247 status = GdipGetClipBoundsI(graphics, rect);
1248 expect(ObjectBusy, status); status = Ok;
1249 status = GdipGetCompositingMode(graphics, &compmode);
1250 expect(ObjectBusy, status); status = Ok;
1251 status = GdipGetCompositingQuality(graphics, &quality);
1252 expect(ObjectBusy, status); status = Ok;
1253 status = GdipGetInterpolationMode(graphics, &intmode);
1254 expect(ObjectBusy, status); status = Ok;
1255 status = GdipGetNearestColor(graphics, &color);
1256 expect(ObjectBusy, status); status = Ok;
1257 status = GdipGetPageScale(graphics, &r);
1258 expect(ObjectBusy, status); status = Ok;
1259 status = GdipGetPageUnit(graphics, &unit);
1260 expect(ObjectBusy, status); status = Ok;
1261 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1262 expect(ObjectBusy, status); status = Ok;
1263 status = GdipGetSmoothingMode(graphics, &smoothmode);
1264 expect(ObjectBusy, status); status = Ok;
1265 status = GdipGetTextRenderingHint(graphics, &texthint);
1266 expect(ObjectBusy, status); status = Ok;
1267 status = GdipGetWorldTransform(graphics, m);
1268 expect(ObjectBusy, status); status = Ok;
1269 status = GdipGraphicsClear(graphics, 0xdeadbeef);
1270 expect(ObjectBusy, status); status = Ok;
1271 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1272 expect(ObjectBusy, status); status = Ok;
1273 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1274 expect(ObjectBusy, status); status = Ok;
1275 /* GdipMeasureCharacterRanges */
1276 /* GdipMeasureString */
1277 status = GdipResetClip(graphics);
1278 expect(ObjectBusy, status); status = Ok;
1279 status = GdipResetWorldTransform(graphics);
1280 expect(ObjectBusy, status); status = Ok;
1281 /* GdipRestoreGraphics */
1282 status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1283 expect(ObjectBusy, status); status = Ok;
1284 /* GdipSaveGraphics */
1285 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1286 expect(ObjectBusy, status); status = Ok;
1287 status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1288 expect(ObjectBusy, status); status = Ok;
1289 status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1290 expect(ObjectBusy, status); status = Ok;
1291 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1292 expect(ObjectBusy, status); status = Ok;
1293 status = GdipSetPageScale(graphics, 1.0);
1294 expect(ObjectBusy, status); status = Ok;
1295 status = GdipSetPageUnit(graphics, UnitWorld);
1296 expect(ObjectBusy, status); status = Ok;
1297 status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1298 expect(ObjectBusy, status); status = Ok;
1299 status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1300 expect(ObjectBusy, status); status = Ok;
1301 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1302 expect(ObjectBusy, status); status = Ok;
1303 status = GdipSetWorldTransform(graphics, m);
1304 expect(ObjectBusy, status); status = Ok;
1305 status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1306 expect(ObjectBusy, status); status = Ok;
1307 status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1308 expect(ObjectBusy, status); status = Ok;
1309 status = GdipSetClipPath(graphics, path, CombineModeReplace);
1310 expect(ObjectBusy, status); status = Ok;
1311 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1312 expect(ObjectBusy, status); status = Ok;
1313 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1314 expect(ObjectBusy, status); status = Ok;
1315 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1316 expect(ObjectBusy, status); status = Ok;
1317 status = GdipTranslateClip(graphics, 0.0, 0.0);
1318 expect(ObjectBusy, status); status = Ok;
1319 status = GdipTranslateClipI(graphics, 0, 0);
1320 expect(ObjectBusy, status); status = Ok;
1321 status = GdipDrawPolygon(graphics, pen, ptf, 5);
1322 expect(ObjectBusy, status); status = Ok;
1323 status = GdipDrawPolygonI(graphics, pen, pt, 5);
1324 expect(ObjectBusy, status); status = Ok;
1325 status = GdipGetDpiX(graphics, &r);
1326 expect(ObjectBusy, status); status = Ok;
1327 status = GdipGetDpiY(graphics, &r);
1328 expect(ObjectBusy, status); status = Ok;
1329 status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1330 status = GdipGetClip(graphics, region);
1331 expect(ObjectBusy, status); status = Ok;
1332 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1333 expect(ObjectBusy, status); status = Ok;
1334 /* try to delete before release */
1335 status = GdipDeleteGraphics(graphics);
1336 expect(ObjectBusy, status);
1338 status = GdipReleaseDC(graphics, retdc);
1339 expect(Ok, status);
1341 GdipDeletePen(pen);
1342 GdipDeleteGraphics(graphics);
1344 GdipDeleteRegion(clip);
1345 GdipDeletePath(path);
1346 GdipDeleteBrush((GpBrush*)brush);
1347 GdipDeleteRegion(region);
1348 GdipDeleteMatrix(m);
1349 DeleteObject(hrgn);
1351 ReleaseDC(hwnd, hdc);
1354 static void test_transformpoints(void)
1356 GpStatus status;
1357 GpGraphics *graphics = NULL;
1358 HDC hdc = GetDC( hwnd );
1359 GpPointF ptf[2];
1360 GpPoint pt[2];
1362 status = GdipCreateFromHDC(hdc, &graphics);
1363 expect(Ok, status);
1365 /* NULL arguments */
1366 status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1367 expect(InvalidParameter, status);
1368 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1369 expect(InvalidParameter, status);
1370 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1371 expect(InvalidParameter, status);
1372 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1373 expect(InvalidParameter, status);
1375 ptf[0].X = 1.0;
1376 ptf[0].Y = 0.0;
1377 ptf[1].X = 0.0;
1378 ptf[1].Y = 1.0;
1379 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1380 expect(Ok, status);
1381 expectf(1.0, ptf[0].X);
1382 expectf(0.0, ptf[0].Y);
1383 expectf(0.0, ptf[1].X);
1384 expectf(1.0, ptf[1].Y);
1386 status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1387 expect(Ok, status);
1388 status = GdipSetPageUnit(graphics, UnitPixel);
1389 expect(Ok, status);
1390 status = GdipSetPageScale(graphics, 3.0);
1391 expect(Ok, status);
1393 ptf[0].X = 1.0;
1394 ptf[0].Y = 0.0;
1395 ptf[1].X = 0.0;
1396 ptf[1].Y = 1.0;
1397 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1398 expect(Ok, status);
1399 expectf(18.0, ptf[0].X);
1400 expectf(15.0, ptf[0].Y);
1401 expectf(15.0, ptf[1].X);
1402 expectf(18.0, ptf[1].Y);
1404 ptf[0].X = 1.0;
1405 ptf[0].Y = 0.0;
1406 ptf[1].X = 0.0;
1407 ptf[1].Y = 1.0;
1408 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1409 expect(Ok, status);
1410 expectf(6.0, ptf[0].X);
1411 expectf(5.0, ptf[0].Y);
1412 expectf(5.0, ptf[1].X);
1413 expectf(6.0, ptf[1].Y);
1415 ptf[0].X = 1.0;
1416 ptf[0].Y = 0.0;
1417 ptf[1].X = 0.0;
1418 ptf[1].Y = 1.0;
1419 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1420 expect(Ok, status);
1421 expectf(3.0, ptf[0].X);
1422 expectf(0.0, ptf[0].Y);
1423 expectf(0.0, ptf[1].X);
1424 expectf(3.0, ptf[1].Y);
1426 ptf[0].X = 18.0;
1427 ptf[0].Y = 15.0;
1428 ptf[1].X = 15.0;
1429 ptf[1].Y = 18.0;
1430 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1431 expect(Ok, status);
1432 expectf(1.0, ptf[0].X);
1433 expectf(0.0, ptf[0].Y);
1434 expectf(0.0, ptf[1].X);
1435 expectf(1.0, ptf[1].Y);
1437 ptf[0].X = 6.0;
1438 ptf[0].Y = 5.0;
1439 ptf[1].X = 5.0;
1440 ptf[1].Y = 6.0;
1441 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1442 expect(Ok, status);
1443 expectf(1.0, ptf[0].X);
1444 expectf(0.0, ptf[0].Y);
1445 expectf(0.0, ptf[1].X);
1446 expectf(1.0, ptf[1].Y);
1448 ptf[0].X = 3.0;
1449 ptf[0].Y = 0.0;
1450 ptf[1].X = 0.0;
1451 ptf[1].Y = 3.0;
1452 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1453 expect(Ok, status);
1454 expectf(1.0, ptf[0].X);
1455 expectf(0.0, ptf[0].Y);
1456 expectf(0.0, ptf[1].X);
1457 expectf(1.0, ptf[1].Y);
1459 pt[0].X = 1;
1460 pt[0].Y = 0;
1461 pt[1].X = 0;
1462 pt[1].Y = 1;
1463 status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1464 expect(Ok, status);
1465 expect(18, pt[0].X);
1466 expect(15, pt[0].Y);
1467 expect(15, pt[1].X);
1468 expect(18, pt[1].Y);
1470 GdipDeleteGraphics(graphics);
1471 ReleaseDC(hwnd, hdc);
1474 static void test_get_set_clip(void)
1476 GpStatus status;
1477 GpGraphics *graphics = NULL;
1478 HDC hdc = GetDC( hwnd );
1479 GpRegion *clip;
1480 GpRectF rect;
1481 BOOL res;
1483 status = GdipCreateFromHDC(hdc, &graphics);
1484 expect(Ok, status);
1486 rect.X = rect.Y = 0.0;
1487 rect.Height = rect.Width = 100.0;
1489 status = GdipCreateRegionRect(&rect, &clip);
1491 /* NULL arguments */
1492 status = GdipGetClip(NULL, NULL);
1493 expect(InvalidParameter, status);
1494 status = GdipGetClip(graphics, NULL);
1495 expect(InvalidParameter, status);
1496 status = GdipGetClip(NULL, clip);
1497 expect(InvalidParameter, status);
1499 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1500 expect(InvalidParameter, status);
1501 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1502 expect(InvalidParameter, status);
1504 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
1505 expect(InvalidParameter, status);
1506 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
1507 expect(InvalidParameter, status);
1509 res = FALSE;
1510 status = GdipGetClip(graphics, clip);
1511 expect(Ok, status);
1512 status = GdipIsInfiniteRegion(clip, graphics, &res);
1513 expect(Ok, status);
1514 expect(TRUE, res);
1516 /* remains infinite after reset */
1517 res = FALSE;
1518 status = GdipResetClip(graphics);
1519 expect(Ok, status);
1520 status = GdipGetClip(graphics, clip);
1521 expect(Ok, status);
1522 status = GdipIsInfiniteRegion(clip, graphics, &res);
1523 expect(Ok, status);
1524 expect(TRUE, res);
1526 /* set to empty and then reset to infinite */
1527 status = GdipSetEmpty(clip);
1528 expect(Ok, status);
1529 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1530 expect(Ok, status);
1532 status = GdipGetClip(graphics, clip);
1533 expect(Ok, status);
1534 res = FALSE;
1535 status = GdipIsEmptyRegion(clip, graphics, &res);
1536 expect(Ok, status);
1537 expect(TRUE, res);
1538 status = GdipResetClip(graphics);
1539 expect(Ok, status);
1540 status = GdipGetClip(graphics, clip);
1541 expect(Ok, status);
1542 res = FALSE;
1543 status = GdipIsInfiniteRegion(clip, graphics, &res);
1544 expect(Ok, status);
1545 expect(TRUE, res);
1547 GdipDeleteRegion(clip);
1549 GdipDeleteGraphics(graphics);
1550 ReleaseDC(hwnd, hdc);
1553 static void test_isempty(void)
1555 GpStatus status;
1556 GpGraphics *graphics = NULL;
1557 HDC hdc = GetDC( hwnd );
1558 GpRegion *clip;
1559 BOOL res;
1561 status = GdipCreateFromHDC(hdc, &graphics);
1562 expect(Ok, status);
1564 status = GdipCreateRegion(&clip);
1565 expect(Ok, status);
1567 /* NULL */
1568 status = GdipIsClipEmpty(NULL, NULL);
1569 expect(InvalidParameter, status);
1570 status = GdipIsClipEmpty(graphics, NULL);
1571 expect(InvalidParameter, status);
1572 status = GdipIsClipEmpty(NULL, &res);
1573 expect(InvalidParameter, status);
1575 /* default is infinite */
1576 res = TRUE;
1577 status = GdipIsClipEmpty(graphics, &res);
1578 expect(Ok, status);
1579 expect(FALSE, res);
1581 GdipDeleteRegion(clip);
1583 GdipDeleteGraphics(graphics);
1584 ReleaseDC(hwnd, hdc);
1587 static void test_clear(void)
1589 GpStatus status;
1591 status = GdipGraphicsClear(NULL, 0xdeadbeef);
1592 expect(InvalidParameter, status);
1595 static void test_textcontrast(void)
1597 GpStatus status;
1598 HDC hdc = GetDC( hwnd );
1599 GpGraphics *graphics;
1600 UINT contrast;
1602 status = GdipGetTextContrast(NULL, NULL);
1603 expect(InvalidParameter, status);
1605 status = GdipCreateFromHDC(hdc, &graphics);
1606 expect(Ok, status);
1608 status = GdipGetTextContrast(graphics, NULL);
1609 expect(InvalidParameter, status);
1610 status = GdipGetTextContrast(graphics, &contrast);
1611 expect(4, contrast);
1613 GdipDeleteGraphics(graphics);
1614 ReleaseDC(hwnd, hdc);
1617 static void test_GdipDrawString(void)
1619 GpStatus status;
1620 GpGraphics *graphics = NULL;
1621 GpFont *fnt = NULL;
1622 RectF rect;
1623 GpStringFormat *format;
1624 GpBrush *brush;
1625 LOGFONTA logfont;
1626 HDC hdc = GetDC( hwnd );
1627 static const WCHAR string[] = {'T','e','s','t',0};
1629 memset(&logfont,0,sizeof(logfont));
1630 strcpy(logfont.lfFaceName,"Arial");
1631 logfont.lfHeight = 12;
1632 logfont.lfCharSet = DEFAULT_CHARSET;
1634 status = GdipCreateFromHDC(hdc, &graphics);
1635 expect(Ok, status);
1637 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
1638 if (status == FileNotFound)
1640 skip("Arial not installed.\n");
1641 return;
1643 expect(Ok, status);
1645 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
1646 expect(Ok, status);
1648 status = GdipCreateStringFormat(0,0,&format);
1649 expect(Ok, status);
1651 rect.X = 0;
1652 rect.Y = 0;
1653 rect.Width = 0;
1654 rect.Height = 12;
1656 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
1657 expect(Ok, status);
1659 GdipDeleteGraphics(graphics);
1660 GdipDeleteBrush(brush);
1661 GdipDeleteFont(fnt);
1662 GdipDeleteStringFormat(format);
1664 ReleaseDC(hwnd, hdc);
1667 static void test_GdipGetVisibleClipBounds_screen(void)
1669 GpStatus status;
1670 GpGraphics *graphics = NULL;
1671 HDC hdc = GetDC(0);
1672 GpRectF rectf, exp, clipr;
1673 GpRect recti;
1675 ok(hdc != NULL, "Expected HDC to be initialized\n");
1677 status = GdipCreateFromHDC(hdc, &graphics);
1678 expect(Ok, status);
1679 ok(graphics != NULL, "Expected graphics to be initialized\n");
1681 /* no clipping rect */
1682 exp.X = 0;
1683 exp.Y = 0;
1684 exp.Width = GetDeviceCaps(hdc, HORZRES);
1685 exp.Height = GetDeviceCaps(hdc, VERTRES);
1687 status = GdipGetVisibleClipBounds(graphics, &rectf);
1688 expect(Ok, status);
1689 ok(rectf.X == exp.X &&
1690 rectf.Y == exp.Y &&
1691 rectf.Width == exp.Width &&
1692 rectf.Height == exp.Height,
1693 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1694 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
1695 rectf.X, rectf.Y, rectf.Width, rectf.Height,
1696 exp.X, exp.Y, exp.Width, exp.Height);
1698 /* clipping rect entirely within window */
1699 exp.X = clipr.X = 10;
1700 exp.Y = clipr.Y = 12;
1701 exp.Width = clipr.Width = 14;
1702 exp.Height = clipr.Height = 16;
1704 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1705 expect(Ok, status);
1707 status = GdipGetVisibleClipBounds(graphics, &rectf);
1708 expect(Ok, status);
1709 ok(rectf.X == exp.X &&
1710 rectf.Y == exp.Y &&
1711 rectf.Width == exp.Width &&
1712 rectf.Height == exp.Height,
1713 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1714 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1715 rectf.X, rectf.Y, rectf.Width, rectf.Height,
1716 exp.X, exp.Y, exp.Width, exp.Height);
1718 /* clipping rect partially outside of screen */
1719 clipr.X = -10;
1720 clipr.Y = -12;
1721 clipr.Width = 20;
1722 clipr.Height = 24;
1724 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1725 expect(Ok, status);
1727 exp.X = 0;
1728 exp.Y = 0;
1729 exp.Width = 10;
1730 exp.Height = 12;
1732 status = GdipGetVisibleClipBounds(graphics, &rectf);
1733 expect(Ok, status);
1734 ok(rectf.X == exp.X &&
1735 rectf.Y == exp.Y &&
1736 rectf.Width == exp.Width &&
1737 rectf.Height == exp.Height,
1738 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1739 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1740 rectf.X, rectf.Y, rectf.Width, rectf.Height,
1741 exp.X, exp.Y, exp.Width, exp.Height);
1743 status = GdipGetVisibleClipBoundsI(graphics, &recti);
1744 expect(Ok, status);
1745 ok(recti.X == exp.X &&
1746 recti.Y == exp.Y &&
1747 recti.Width == exp.Width &&
1748 recti.Height == exp.Height,
1749 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
1750 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1751 recti.X, recti.Y, recti.Width, recti.Height,
1752 exp.X, exp.Y, exp.Width, exp.Height);
1754 GdipDeleteGraphics(graphics);
1755 ReleaseDC(0, hdc);
1758 static void test_GdipGetVisibleClipBounds_window(void)
1760 GpStatus status;
1761 GpGraphics *graphics = NULL;
1762 GpRectF rectf, window, exp, clipr;
1763 GpRect recti;
1764 HDC hdc;
1765 PAINTSTRUCT ps;
1766 RECT wnd_rect;
1768 /* get client area size */
1769 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
1770 window.X = wnd_rect.left;
1771 window.Y = wnd_rect.top;
1772 window.Width = wnd_rect.right - wnd_rect.left;
1773 window.Height = wnd_rect.bottom - wnd_rect.top;
1775 hdc = BeginPaint(hwnd, &ps);
1777 status = GdipCreateFromHDC(hdc, &graphics);
1778 expect(Ok, status);
1779 ok(graphics != NULL, "Expected graphics to be initialized\n");
1781 status = GdipGetVisibleClipBounds(graphics, &rectf);
1782 expect(Ok, status);
1783 ok(rectf.X == window.X &&
1784 rectf.Y == window.Y &&
1785 rectf.Width == window.Width &&
1786 rectf.Height == window.Height,
1787 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1788 "the window (%0.f, %0.f, %0.f, %0.f)\n",
1789 rectf.X, rectf.Y, rectf.Width, rectf.Height,
1790 window.X, window.Y, window.Width, window.Height);
1792 /* clipping rect entirely within window */
1793 exp.X = clipr.X = 20;
1794 exp.Y = clipr.Y = 8;
1795 exp.Width = clipr.Width = 30;
1796 exp.Height = clipr.Height = 20;
1798 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1799 expect(Ok, status);
1801 status = GdipGetVisibleClipBounds(graphics, &rectf);
1802 expect(Ok, status);
1803 ok(rectf.X == exp.X &&
1804 rectf.Y == exp.Y &&
1805 rectf.Width == exp.Width &&
1806 rectf.Height == exp.Height,
1807 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1808 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1809 rectf.X, rectf.Y, rectf.Width, rectf.Height,
1810 exp.X, exp.Y, exp.Width, exp.Height);
1812 /* clipping rect partially outside of window */
1813 clipr.X = window.Width - 10;
1814 clipr.Y = window.Height - 15;
1815 clipr.Width = 20;
1816 clipr.Height = 30;
1818 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
1819 expect(Ok, status);
1821 exp.X = window.Width - 10;
1822 exp.Y = window.Height - 15;
1823 exp.Width = 10;
1824 exp.Height = 15;
1826 status = GdipGetVisibleClipBounds(graphics, &rectf);
1827 expect(Ok, status);
1828 ok(rectf.X == exp.X &&
1829 rectf.Y == exp.Y &&
1830 rectf.Width == exp.Width &&
1831 rectf.Height == exp.Height,
1832 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
1833 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1834 rectf.X, rectf.Y, rectf.Width, rectf.Height,
1835 exp.X, exp.Y, exp.Width, exp.Height);
1837 status = GdipGetVisibleClipBoundsI(graphics, &recti);
1838 expect(Ok, status);
1839 ok(recti.X == exp.X &&
1840 recti.Y == exp.Y &&
1841 recti.Width == exp.Width &&
1842 recti.Height == exp.Height,
1843 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
1844 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
1845 recti.X, recti.Y, recti.Width, recti.Height,
1846 exp.X, exp.Y, exp.Width, exp.Height);
1848 GdipDeleteGraphics(graphics);
1849 EndPaint(hwnd, &ps);
1852 static void test_GdipGetVisibleClipBounds(void)
1854 GpGraphics* graphics = NULL;
1855 GpRectF rectf;
1856 GpRect rect;
1857 HDC hdc = GetDC( hwnd );
1858 GpStatus status;
1860 status = GdipCreateFromHDC(hdc, &graphics);
1861 expect(Ok, status);
1862 ok(graphics != NULL, "Expected graphics to be initialized\n");
1864 /* test null parameters */
1865 status = GdipGetVisibleClipBounds(graphics, NULL);
1866 expect(InvalidParameter, status);
1868 status = GdipGetVisibleClipBounds(NULL, &rectf);
1869 expect(InvalidParameter, status);
1871 status = GdipGetVisibleClipBoundsI(graphics, NULL);
1872 expect(InvalidParameter, status);
1874 status = GdipGetVisibleClipBoundsI(NULL, &rect);
1875 expect(InvalidParameter, status);
1877 GdipDeleteGraphics(graphics);
1878 ReleaseDC(hwnd, hdc);
1880 test_GdipGetVisibleClipBounds_screen();
1881 test_GdipGetVisibleClipBounds_window();
1884 static void test_fromMemoryBitmap(void)
1886 GpStatus status;
1887 GpGraphics *graphics = NULL;
1888 GpBitmap *bitmap = NULL;
1889 BYTE bits[48] = {0};
1891 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
1892 expect(Ok, status);
1894 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
1895 expect(Ok, status);
1897 status = GdipGraphicsClear(graphics, 0xff686868);
1898 expect(Ok, status);
1900 GdipDeleteGraphics(graphics);
1902 /* drawing writes to the memory provided */
1903 todo_wine expect(0x68, bits[10]);
1905 GdipDisposeImage((GpImage*)bitmap);
1908 static void test_GdipIsVisiblePoint(void)
1910 GpStatus status;
1911 GpGraphics *graphics = NULL;
1912 HDC hdc = GetDC( hwnd );
1913 REAL x, y;
1914 BOOL val;
1916 ok(hdc != NULL, "Expected HDC to be initialized\n");
1918 status = GdipCreateFromHDC(hdc, &graphics);
1919 expect(Ok, status);
1920 ok(graphics != NULL, "Expected graphics to be initialized\n");
1922 /* null parameters */
1923 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
1924 expect(InvalidParameter, status);
1926 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
1927 expect(InvalidParameter, status);
1929 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
1930 expect(InvalidParameter, status);
1932 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
1933 expect(InvalidParameter, status);
1935 x = 0;
1936 y = 0;
1937 status = GdipIsVisiblePoint(graphics, x, y, &val);
1938 expect(Ok, status);
1939 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1941 x = -10;
1942 y = 0;
1943 status = GdipIsVisiblePoint(graphics, x, y, &val);
1944 expect(Ok, status);
1945 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1947 x = 0;
1948 y = -5;
1949 status = GdipIsVisiblePoint(graphics, x, y, &val);
1950 expect(Ok, status);
1951 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1953 x = 1;
1954 y = 1;
1955 status = GdipIsVisiblePoint(graphics, x, y, &val);
1956 expect(Ok, status);
1957 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1959 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
1960 expect(Ok, status);
1962 x = 1;
1963 y = 1;
1964 status = GdipIsVisiblePoint(graphics, x, y, &val);
1965 expect(Ok, status);
1966 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
1968 x = 15.5;
1969 y = 40.5;
1970 status = GdipIsVisiblePoint(graphics, x, y, &val);
1971 expect(Ok, status);
1972 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
1974 /* translate into the center of the rect */
1975 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
1977 x = 0;
1978 y = 0;
1979 status = GdipIsVisiblePoint(graphics, x, y, &val);
1980 expect(Ok, status);
1981 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
1983 x = 25;
1984 y = 40;
1985 status = GdipIsVisiblePoint(graphics, x, y, &val);
1986 expect(Ok, status);
1987 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
1989 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
1991 /* corner cases */
1992 x = 9;
1993 y = 19;
1994 status = GdipIsVisiblePoint(graphics, x, y, &val);
1995 expect(Ok, status);
1996 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
1998 x = 9.25;
1999 y = 19.25;
2000 status = GdipIsVisiblePoint(graphics, x, y, &val);
2001 expect(Ok, status);
2002 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2004 x = 9.5;
2005 y = 19.5;
2006 status = GdipIsVisiblePoint(graphics, x, y, &val);
2007 expect(Ok, status);
2008 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2010 x = 9.75;
2011 y = 19.75;
2012 status = GdipIsVisiblePoint(graphics, x, y, &val);
2013 expect(Ok, status);
2014 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2016 x = 10;
2017 y = 20;
2018 status = GdipIsVisiblePoint(graphics, x, y, &val);
2019 expect(Ok, status);
2020 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2022 x = 40;
2023 y = 20;
2024 status = GdipIsVisiblePoint(graphics, x, y, &val);
2025 expect(Ok, status);
2026 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2028 x = 39;
2029 y = 59;
2030 status = GdipIsVisiblePoint(graphics, x, y, &val);
2031 expect(Ok, status);
2032 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2034 x = 39.25;
2035 y = 59.25;
2036 status = GdipIsVisiblePoint(graphics, x, y, &val);
2037 expect(Ok, status);
2038 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2040 x = 39.5;
2041 y = 39.5;
2042 status = GdipIsVisiblePoint(graphics, x, y, &val);
2043 expect(Ok, status);
2044 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2046 x = 39.75;
2047 y = 59.75;
2048 status = GdipIsVisiblePoint(graphics, x, y, &val);
2049 expect(Ok, status);
2050 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2052 x = 40;
2053 y = 60;
2054 status = GdipIsVisiblePoint(graphics, x, y, &val);
2055 expect(Ok, status);
2056 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2058 x = 40.15;
2059 y = 60.15;
2060 status = GdipIsVisiblePoint(graphics, x, y, &val);
2061 expect(Ok, status);
2062 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2064 x = 10;
2065 y = 60;
2066 status = GdipIsVisiblePoint(graphics, x, y, &val);
2067 expect(Ok, status);
2068 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2070 /* integer version */
2071 x = 25;
2072 y = 30;
2073 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2074 expect(Ok, status);
2075 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2077 x = 50;
2078 y = 100;
2079 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2080 expect(Ok, status);
2081 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2083 GdipDeleteGraphics(graphics);
2084 ReleaseDC(hwnd, hdc);
2087 static void test_GdipIsVisibleRect(void)
2089 GpStatus status;
2090 GpGraphics *graphics = NULL;
2091 HDC hdc = GetDC( hwnd );
2092 REAL x, y, width, height;
2093 BOOL val;
2095 ok(hdc != NULL, "Expected HDC to be initialized\n");
2097 status = GdipCreateFromHDC(hdc, &graphics);
2098 expect(Ok, status);
2099 ok(graphics != NULL, "Expected graphics to be initialized\n");
2101 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2102 expect(InvalidParameter, status);
2104 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2105 expect(InvalidParameter, status);
2107 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2108 expect(InvalidParameter, status);
2110 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2111 expect(InvalidParameter, status);
2113 /* entirely within the visible region */
2114 x = 0; width = 10;
2115 y = 0; height = 10;
2116 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2117 expect(Ok, status);
2118 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2120 /* partially outside */
2121 x = -10; width = 20;
2122 y = -10; height = 20;
2123 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2124 expect(Ok, status);
2125 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2127 /* entirely outside */
2128 x = -10; width = 5;
2129 y = -10; height = 5;
2130 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2131 expect(Ok, status);
2132 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2134 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2135 expect(Ok, status);
2137 /* entirely within the visible region */
2138 x = 12; width = 10;
2139 y = 22; height = 10;
2140 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2141 expect(Ok, status);
2142 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2144 /* partially outside */
2145 x = 35; width = 10;
2146 y = 55; height = 10;
2147 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2148 expect(Ok, status);
2149 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2151 /* entirely outside */
2152 x = 45; width = 5;
2153 y = 65; height = 5;
2154 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2155 expect(Ok, status);
2156 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2158 /* translate into center of clipping rect */
2159 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2161 x = 0; width = 10;
2162 y = 0; height = 10;
2163 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2164 expect(Ok, status);
2165 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2167 x = 25; width = 5;
2168 y = 40; height = 5;
2169 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2170 expect(Ok, status);
2171 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2173 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2175 /* corners entirely outside, but some intersections */
2176 x = 0; width = 70;
2177 y = 0; height = 90;
2178 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2179 expect(Ok, status);
2180 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2182 x = 0; width = 70;
2183 y = 0; height = 30;
2184 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2185 expect(Ok, status);
2186 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2188 x = 0; width = 30;
2189 y = 0; height = 90;
2190 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2191 expect(Ok, status);
2192 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2194 /* edge cases */
2195 x = 0; width = 10;
2196 y = 20; height = 40;
2197 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2198 expect(Ok, status);
2199 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2201 x = 10; width = 30;
2202 y = 0; height = 20;
2203 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2204 expect(Ok, status);
2205 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2207 x = 40; width = 10;
2208 y = 20; height = 40;
2209 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2210 expect(Ok, status);
2211 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2213 x = 10; width = 30;
2214 y = 60; height = 10;
2215 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2216 expect(Ok, status);
2217 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2219 /* rounding tests */
2220 x = 0.4; width = 10.4;
2221 y = 20; height = 40;
2222 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2223 expect(Ok, status);
2224 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2226 x = 10; width = 30;
2227 y = 0.4; height = 20.4;
2228 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2229 expect(Ok, status);
2230 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2232 /* integer version */
2233 x = 0; width = 30;
2234 y = 0; height = 90;
2235 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2236 expect(Ok, status);
2237 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2239 x = 12; width = 10;
2240 y = 22; height = 10;
2241 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2242 expect(Ok, status);
2243 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2245 GdipDeleteGraphics(graphics);
2246 ReleaseDC(hwnd, hdc);
2249 static void test_GdipGetNearestColor(void)
2251 GpStatus status;
2252 GpGraphics *graphics;
2253 GpBitmap *bitmap;
2254 ARGB color = 0xdeadbeef;
2255 HDC hdc = GetDC( hwnd );
2257 /* create a graphics object */
2258 ok(hdc != NULL, "Expected HDC to be initialized\n");
2260 status = GdipCreateFromHDC(hdc, &graphics);
2261 expect(Ok, status);
2262 ok(graphics != NULL, "Expected graphics to be initialized\n");
2264 status = GdipGetNearestColor(graphics, NULL);
2265 expect(InvalidParameter, status);
2267 status = GdipGetNearestColor(NULL, &color);
2268 expect(InvalidParameter, status);
2269 GdipDeleteGraphics(graphics);
2271 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2272 expect(Ok, status);
2273 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2274 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2275 if (status == Ok)
2277 status = GdipGetNearestColor(graphics, &color);
2278 expect(Ok, status);
2279 expect(0xdeadbeef, color);
2280 GdipDeleteGraphics(graphics);
2282 GdipDisposeImage((GpImage*)bitmap);
2284 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2285 expect(Ok, status);
2286 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2287 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2288 if (status == Ok)
2290 status = GdipGetNearestColor(graphics, &color);
2291 expect(Ok, status);
2292 expect(0xdeadbeef, color);
2293 GdipDeleteGraphics(graphics);
2295 GdipDisposeImage((GpImage*)bitmap);
2297 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
2298 expect(Ok, status);
2299 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2300 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2301 if (status == Ok)
2303 status = GdipGetNearestColor(graphics, &color);
2304 expect(Ok, status);
2305 expect(0xdeadbeef, color);
2306 GdipDeleteGraphics(graphics);
2308 GdipDisposeImage((GpImage*)bitmap);
2310 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
2311 expect(Ok, status);
2312 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2313 todo_wine expect(OutOfMemory, status);
2314 if (status == Ok)
2315 GdipDeleteGraphics(graphics);
2316 GdipDisposeImage((GpImage*)bitmap);
2318 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
2319 expect(Ok, status);
2320 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2321 expect(Ok, status);
2322 status = GdipGetNearestColor(graphics, &color);
2323 expect(Ok, status);
2324 expect(0xdeadbeef, color);
2325 GdipDeleteGraphics(graphics);
2326 GdipDisposeImage((GpImage*)bitmap);
2328 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
2329 expect(Ok, status);
2330 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2331 expect(Ok, status);
2332 status = GdipGetNearestColor(graphics, &color);
2333 expect(Ok, status);
2334 expect(0xdeadbeef, color);
2335 GdipDeleteGraphics(graphics);
2336 GdipDisposeImage((GpImage*)bitmap);
2338 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
2339 expect(Ok, status);
2340 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2341 expect(Ok, status);
2342 status = GdipGetNearestColor(graphics, &color);
2343 expect(Ok, status);
2344 expect(0xdeadbeef, color);
2345 GdipDeleteGraphics(graphics);
2346 GdipDisposeImage((GpImage*)bitmap);
2348 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
2349 expect(Ok, status);
2350 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2351 expect(Ok, status);
2352 status = GdipGetNearestColor(graphics, &color);
2353 expect(Ok, status);
2354 expect(0xdeadbeef, color);
2355 GdipDeleteGraphics(graphics);
2356 GdipDisposeImage((GpImage*)bitmap);
2358 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
2359 expect(Ok, status);
2360 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2361 expect(Ok, status);
2362 status = GdipGetNearestColor(graphics, &color);
2363 expect(Ok, status);
2364 expect(0xdeadbeef, color);
2365 GdipDeleteGraphics(graphics);
2366 GdipDisposeImage((GpImage*)bitmap);
2368 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
2369 expect(Ok, status);
2370 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2371 expect(Ok, status);
2372 status = GdipGetNearestColor(graphics, &color);
2373 expect(Ok, status);
2374 expect(0xdeadbeef, color);
2375 GdipDeleteGraphics(graphics);
2376 GdipDisposeImage((GpImage*)bitmap);
2378 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
2379 expect(Ok, status);
2380 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2381 expect(Ok, status);
2382 status = GdipGetNearestColor(graphics, &color);
2383 expect(Ok, status);
2384 todo_wine expect(0xffa8bce8, color);
2385 GdipDeleteGraphics(graphics);
2386 GdipDisposeImage((GpImage*)bitmap);
2388 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
2389 expect(Ok, status);
2390 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2391 expect(Ok, status);
2392 status = GdipGetNearestColor(graphics, &color);
2393 expect(Ok, status);
2394 todo_wine
2395 ok(color == 0xffa8b8e8 ||
2396 broken(color == 0xffa0b8e0), /* Win98/WinMe */
2397 "Expected ffa8b8e8, got %.8x\n", color);
2398 GdipDeleteGraphics(graphics);
2399 GdipDisposeImage((GpImage*)bitmap);
2401 ReleaseDC(hwnd, hdc);
2404 static void test_string_functions(void)
2406 GpStatus status;
2407 GpGraphics *graphics;
2408 GpFontFamily *family;
2409 GpFont *font;
2410 RectF rc, char_bounds, bounds;
2411 GpBrush *brush;
2412 ARGB color = 0xff000000;
2413 HDC hdc = GetDC( hwnd );
2414 const WCHAR fontname[] = {'C','o','u','r','i','e','r',' ','N','e','w',0};
2415 const WCHAR fontname2[] = {'C','o','u','r','i','e','r',0};
2416 const WCHAR teststring[] = {'o','o',' ','o','\n','o',0};
2417 REAL char_width, char_height;
2418 INT codepointsfitted, linesfilled;
2419 GpStringFormat *format;
2420 CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
2421 GpRegion *regions[4] = {0};
2422 BOOL region_isempty[4];
2423 int i;
2425 ok(hdc != NULL, "Expected HDC to be initialized\n");
2426 status = GdipCreateFromHDC(hdc, &graphics);
2427 expect(Ok, status);
2428 ok(graphics != NULL, "Expected graphics to be initialized\n");
2430 status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
2432 if (status != Ok)
2434 /* Wine doesn't have Courier New? */
2435 todo_wine expect(Ok, status);
2436 status = GdipCreateFontFamilyFromName(fontname2, NULL, &family);
2439 expect(Ok, status);
2441 status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
2442 expect(Ok, status);
2444 status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
2445 expect(Ok, status);
2447 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
2448 expect(Ok, status);
2450 rc.X = 0;
2451 rc.Y = 0;
2452 rc.Width = 100.0;
2453 rc.Height = 100.0;
2455 status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
2456 expect(InvalidParameter, status);
2458 status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
2459 expect(InvalidParameter, status);
2461 status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
2462 expect(InvalidParameter, status);
2464 status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
2465 expect(InvalidParameter, status);
2467 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
2468 expect(InvalidParameter, status);
2470 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
2471 expect(Ok, status);
2473 status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2474 expect(InvalidParameter, status);
2476 status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2477 expect(InvalidParameter, status);
2479 status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2480 expect(InvalidParameter, status);
2482 status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
2483 expect(InvalidParameter, status);
2485 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
2486 expect(InvalidParameter, status);
2488 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
2489 expect(Ok, status);
2491 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
2492 expect(Ok, status);
2494 status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
2495 expect(Ok, status);
2496 expectf(0.0, char_bounds.X);
2497 expectf(0.0, char_bounds.Y);
2498 ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
2499 ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
2500 expect(1, codepointsfitted);
2501 expect(1, linesfilled);
2503 status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2504 expect(Ok, status);
2505 expectf(0.0, bounds.X);
2506 expectf(0.0, bounds.Y);
2507 ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
2508 expectf(char_bounds.Height, bounds.Height);
2509 expect(2, codepointsfitted);
2510 expect(1, linesfilled);
2511 char_width = bounds.Width - char_bounds.Width;
2513 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2514 expect(Ok, status);
2515 expectf(0.0, bounds.X);
2516 expectf(0.0, bounds.Y);
2517 expectf_(char_bounds.Width + char_width * 3, bounds.Width, 0.01);
2518 ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
2519 expect(6, codepointsfitted);
2520 expect(2, linesfilled);
2521 char_height = bounds.Height - char_bounds.Height;
2523 /* Cut off everything after the first space. */
2524 rc.Width = char_bounds.Width + char_width * 2.5;
2526 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2527 expect(Ok, status);
2528 expectf(0.0, bounds.X);
2529 expectf(0.0, bounds.Y);
2530 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
2531 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
2532 expect(6, codepointsfitted);
2533 expect(3, linesfilled);
2535 /* Cut off everything including the first space. */
2536 rc.Width = char_bounds.Width + char_width * 1.5;
2538 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2539 expect(Ok, status);
2540 expectf(0.0, bounds.X);
2541 expectf(0.0, bounds.Y);
2542 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
2543 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
2544 expect(6, codepointsfitted);
2545 expect(3, linesfilled);
2547 /* Cut off everything after the first character. */
2548 rc.Width = char_bounds.Width + char_width * 0.5;
2550 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
2551 expect(Ok, status);
2552 expectf(0.0, bounds.X);
2553 expectf(0.0, bounds.Y);
2554 expectf_(char_bounds.Width, bounds.Width, 0.01);
2555 todo_wine expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
2556 expect(6, codepointsfitted);
2557 todo_wine expect(4, linesfilled);
2559 status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
2560 expect(Ok, status);
2562 rc.Width = 100.0;
2564 for (i=0; i<4; i++)
2566 status = GdipCreateRegion(&regions[i]);
2567 expect(Ok, status);
2570 status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
2571 expect(InvalidParameter, status);
2573 status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
2574 expect(InvalidParameter, status);
2576 status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
2577 expect(InvalidParameter, status);
2579 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
2580 expect(InvalidParameter, status);
2582 if (0)
2584 /* Crashes on Windows XP */
2585 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
2586 expect(InvalidParameter, status);
2589 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
2590 expect(InvalidParameter, status);
2592 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
2593 expect(InvalidParameter, status);
2595 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
2596 expect(Ok, status);
2598 for (i=0; i<4; i++)
2600 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
2601 expect(Ok, status);
2604 ok(!region_isempty[0], "region shouldn't be empty\n");
2605 ok(!region_isempty[1], "region shouldn't be empty\n");
2606 ok(!region_isempty[2], "region shouldn't be empty\n");
2607 ok(!region_isempty[3], "region shouldn't be empty\n");
2609 /* Cut off everything after the first space, and the second line. */
2610 rc.Width = char_bounds.Width + char_width * 2.5;
2611 rc.Height = char_bounds.Height + char_height * 0.5;
2613 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
2614 expect(Ok, status);
2616 for (i=0; i<4; i++)
2618 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
2619 expect(Ok, status);
2622 ok(!region_isempty[0], "region shouldn't be empty\n");
2623 ok(!region_isempty[1], "region shouldn't be empty\n");
2624 ok(region_isempty[2], "region should be empty\n");
2625 ok(!region_isempty[3], "region shouldn't be empty\n");
2627 for (i=0; i<4; i++)
2628 GdipDeleteRegion(regions[i]);
2630 GdipDeleteStringFormat(format);
2631 GdipDeleteBrush(brush);
2632 GdipDeleteFont(font);
2633 GdipDeleteFontFamily(family);
2634 GdipDeleteGraphics(graphics);
2636 ReleaseDC(hwnd, hdc);
2639 START_TEST(graphics)
2641 struct GdiplusStartupInput gdiplusStartupInput;
2642 ULONG_PTR gdiplusToken;
2643 WNDCLASSA class;
2645 memset( &class, 0, sizeof(class) );
2646 class.lpszClassName = "gdiplus_test";
2647 class.style = CS_HREDRAW | CS_VREDRAW;
2648 class.lpfnWndProc = DefWindowProcA;
2649 class.hInstance = GetModuleHandleA(0);
2650 class.hIcon = LoadIcon(0, IDI_APPLICATION);
2651 class.hCursor = LoadCursor(NULL, IDC_ARROW);
2652 class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2653 RegisterClassA( &class );
2654 hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
2655 CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
2656 ok(hwnd != NULL, "Expected window to be created\n");
2658 gdiplusStartupInput.GdiplusVersion = 1;
2659 gdiplusStartupInput.DebugEventCallback = NULL;
2660 gdiplusStartupInput.SuppressBackgroundThread = 0;
2661 gdiplusStartupInput.SuppressExternalCodecs = 0;
2663 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
2665 test_constructor_destructor();
2666 test_save_restore();
2667 test_GdipDrawBezierI();
2668 test_GdipDrawArc();
2669 test_GdipDrawArcI();
2670 test_GdipDrawCurve();
2671 test_GdipDrawCurveI();
2672 test_GdipDrawCurve2();
2673 test_GdipDrawCurve2I();
2674 test_GdipDrawCurve3();
2675 test_GdipDrawCurve3I();
2676 test_GdipDrawLineI();
2677 test_GdipDrawLinesI();
2678 test_GdipDrawString();
2679 test_GdipGetNearestColor();
2680 test_GdipGetVisibleClipBounds();
2681 test_GdipIsVisiblePoint();
2682 test_GdipIsVisibleRect();
2683 test_Get_Release_DC();
2684 test_BeginContainer2();
2685 test_transformpoints();
2686 test_get_set_clip();
2687 test_isempty();
2688 test_clear();
2689 test_textcontrast();
2690 test_fromMemoryBitmap();
2691 test_string_functions();
2693 GdiplusShutdown(gdiplusToken);
2694 DestroyWindow( hwnd );