[GDIPLUS_WINETEST]
[reactos.git] / rostests / winetests / gdiplus / graphics.c
1 /*
2 * Unit test suite for graphics objects
3 *
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include <math.h>
23
24 #define WIN32_NO_STATUS
25 #define _INC_WINDOWS
26 #define COM_NO_WINDOWS_H
27
28 //#include "windows.h"
29 #include <wine/test.h>
30 #include <wingdi.h>
31 #include <objbase.h>
32 #include <gdiplus.h>
33
34 #define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (INT)(expected), (INT)(got))
35 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
36 #define expectf(expected, got) expectf_((expected), (got), 0.001)
37 #define TABLE_LEN (23)
38
39 static const REAL mm_per_inch = 25.4;
40 static const REAL point_per_inch = 72.0;
41 static HWND hwnd;
42
43 static void set_rect_empty(RectF *rc)
44 {
45 rc->X = 0.0;
46 rc->Y = 0.0;
47 rc->Width = 0.0;
48 rc->Height = 0.0;
49 }
50
51 /* converts a given unit to its value in pixels */
52 static REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
53 {
54 switch (unit)
55 {
56 case UnitPixel:
57 case UnitDisplay:
58 return units;
59 case UnitPoint:
60 return units * dpi / point_per_inch;
61 case UnitInch:
62 return units * dpi;
63 case UnitDocument:
64 return units * dpi / 300.0; /* Per MSDN */
65 case UnitMillimeter:
66 return units * dpi / mm_per_inch;
67 default:
68 ok(0, "Unsupported unit: %d\n", unit);
69 return 0;
70 }
71 }
72
73 /* converts value in pixels to a given unit */
74 static REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi)
75 {
76 switch (unit)
77 {
78 case UnitPixel:
79 case UnitDisplay:
80 return pixels;
81 case UnitPoint:
82 return pixels * point_per_inch / dpi;
83 case UnitInch:
84 return pixels / dpi;
85 case UnitDocument:
86 return pixels * 300.0 / dpi;
87 case UnitMillimeter:
88 return pixels * mm_per_inch / dpi;
89 default:
90 ok(0, "Unsupported unit: %d\n", unit);
91 return 0;
92 }
93 }
94
95 static REAL units_scale(GpUnit from, GpUnit to, REAL dpi)
96 {
97 REAL pixels = units_to_pixels(1.0, from, dpi);
98 return pixels_to_units(pixels, to, dpi);
99 }
100
101 static GpGraphics *create_graphics(REAL res_x, REAL res_y, GpUnit unit, REAL scale, GpImage **image)
102 {
103 GpStatus status;
104 union
105 {
106 GpBitmap *bitmap;
107 GpImage *image;
108 } u;
109 GpGraphics *graphics = NULL;
110 REAL res;
111
112 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, NULL, &u.bitmap);
113 expect(Ok, status);
114
115 status = GdipBitmapSetResolution(u.bitmap, res_x, res_y);
116 expect(Ok, status);
117 status = GdipGetImageHorizontalResolution(u.image, &res);
118 expect(Ok, status);
119 expectf(res_x, res);
120 status = GdipGetImageVerticalResolution(u.image, &res);
121 expect(Ok, status);
122 expectf(res_y, res);
123
124 status = GdipGetImageGraphicsContext(u.image, &graphics);
125 expect(Ok, status);
126
127 *image = u.image;
128
129 status = GdipGetDpiX(graphics, &res);
130 expect(Ok, status);
131 expectf(res_x, res);
132 status = GdipGetDpiY(graphics, &res);
133 expect(Ok, status);
134 expectf(res_y, res);
135
136 status = GdipSetPageUnit(graphics, unit);
137 expect(Ok, status);
138 status = GdipSetPageScale(graphics, scale);
139 expect(Ok, status);
140
141 return graphics;
142 }
143
144 static void test_constructor_destructor(void)
145 {
146 GpStatus stat;
147 GpGraphics *graphics = NULL;
148 HDC hdc = GetDC( hwnd );
149
150 stat = GdipCreateFromHDC(NULL, &graphics);
151 expect(OutOfMemory, stat);
152 stat = GdipDeleteGraphics(graphics);
153 expect(InvalidParameter, stat);
154
155 stat = GdipCreateFromHDC(hdc, &graphics);
156 expect(Ok, stat);
157 stat = GdipDeleteGraphics(graphics);
158 expect(Ok, stat);
159
160 stat = GdipCreateFromHWND(NULL, &graphics);
161 expect(Ok, stat);
162 stat = GdipDeleteGraphics(graphics);
163 expect(Ok, stat);
164
165 stat = GdipCreateFromHWNDICM(NULL, &graphics);
166 expect(Ok, stat);
167 stat = GdipDeleteGraphics(graphics);
168 expect(Ok, stat);
169
170 stat = GdipDeleteGraphics(NULL);
171 expect(InvalidParameter, stat);
172 ReleaseDC(hwnd, hdc);
173 }
174
175 typedef struct node{
176 GraphicsState data;
177 struct node * next;
178 } node;
179
180 /* Linked list prepend function. */
181 static void log_state(GraphicsState data, node ** log)
182 {
183 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
184
185 new_entry->data = data;
186 new_entry->next = *log;
187 *log = new_entry;
188 }
189
190 /* Checks if there are duplicates in the list, and frees it. */
191 static void check_no_duplicates(node * log)
192 {
193 INT dups = 0;
194 node * temp = NULL;
195 node * temp2 = NULL;
196 node * orig = log;
197
198 if(!log)
199 goto end;
200
201 do{
202 temp = log;
203 while((temp = temp->next)){
204 if(log->data == temp->data){
205 dups++;
206 break;
207 }
208 if(dups > 0)
209 break;
210 }
211 }while((log = log->next));
212
213 temp = orig;
214 do{
215 temp2 = temp->next;
216 HeapFree(GetProcessHeap(), 0, temp);
217 temp = temp2;
218 }while(temp);
219
220 end:
221 expect(0, dups);
222 }
223
224 static void test_save_restore(void)
225 {
226 GpStatus stat;
227 GraphicsState state_a, state_b, state_c;
228 InterpolationMode mode;
229 GpGraphics *graphics1, *graphics2;
230 node * state_log = NULL;
231 HDC hdc = GetDC( hwnd );
232 state_a = state_b = state_c = 0xdeadbeef;
233
234 /* Invalid saving. */
235 GdipCreateFromHDC(hdc, &graphics1);
236 stat = GdipSaveGraphics(graphics1, NULL);
237 expect(InvalidParameter, stat);
238 stat = GdipSaveGraphics(NULL, &state_a);
239 expect(InvalidParameter, stat);
240 GdipDeleteGraphics(graphics1);
241
242 log_state(state_a, &state_log);
243
244 /* Basic save/restore. */
245 GdipCreateFromHDC(hdc, &graphics1);
246 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
247 stat = GdipSaveGraphics(graphics1, &state_a);
248 expect(Ok, stat);
249 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
250 stat = GdipRestoreGraphics(graphics1, state_a);
251 expect(Ok, stat);
252 GdipGetInterpolationMode(graphics1, &mode);
253 expect(InterpolationModeBilinear, mode);
254 GdipDeleteGraphics(graphics1);
255
256 log_state(state_a, &state_log);
257
258 /* Restoring garbage doesn't affect saves. */
259 GdipCreateFromHDC(hdc, &graphics1);
260 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
261 GdipSaveGraphics(graphics1, &state_a);
262 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
263 GdipSaveGraphics(graphics1, &state_b);
264 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
265 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
266 expect(Ok, stat);
267 GdipRestoreGraphics(graphics1, state_b);
268 GdipGetInterpolationMode(graphics1, &mode);
269 expect(InterpolationModeBicubic, mode);
270 GdipRestoreGraphics(graphics1, state_a);
271 GdipGetInterpolationMode(graphics1, &mode);
272 expect(InterpolationModeBilinear, mode);
273 GdipDeleteGraphics(graphics1);
274
275 log_state(state_a, &state_log);
276 log_state(state_b, &state_log);
277
278 /* Restoring older state invalidates newer saves (but not older saves). */
279 GdipCreateFromHDC(hdc, &graphics1);
280 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
281 GdipSaveGraphics(graphics1, &state_a);
282 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
283 GdipSaveGraphics(graphics1, &state_b);
284 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
285 GdipSaveGraphics(graphics1, &state_c);
286 GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
287 GdipRestoreGraphics(graphics1, state_b);
288 GdipGetInterpolationMode(graphics1, &mode);
289 expect(InterpolationModeBicubic, mode);
290 GdipRestoreGraphics(graphics1, state_c);
291 GdipGetInterpolationMode(graphics1, &mode);
292 expect(InterpolationModeBicubic, mode);
293 GdipRestoreGraphics(graphics1, state_a);
294 GdipGetInterpolationMode(graphics1, &mode);
295 expect(InterpolationModeBilinear, mode);
296 GdipDeleteGraphics(graphics1);
297
298 log_state(state_a, &state_log);
299 log_state(state_b, &state_log);
300 log_state(state_c, &state_log);
301
302 /* Restoring older save from one graphics object does not invalidate
303 * newer save from other graphics object. */
304 GdipCreateFromHDC(hdc, &graphics1);
305 GdipCreateFromHDC(hdc, &graphics2);
306 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
307 GdipSaveGraphics(graphics1, &state_a);
308 GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
309 GdipSaveGraphics(graphics2, &state_b);
310 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
311 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
312 GdipRestoreGraphics(graphics1, state_a);
313 GdipGetInterpolationMode(graphics1, &mode);
314 expect(InterpolationModeBilinear, mode);
315 GdipRestoreGraphics(graphics2, state_b);
316 GdipGetInterpolationMode(graphics2, &mode);
317 expect(InterpolationModeBicubic, mode);
318 GdipDeleteGraphics(graphics1);
319 GdipDeleteGraphics(graphics2);
320
321 /* You can't restore a state to a graphics object that didn't save it. */
322 GdipCreateFromHDC(hdc, &graphics1);
323 GdipCreateFromHDC(hdc, &graphics2);
324 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
325 GdipSaveGraphics(graphics1, &state_a);
326 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
327 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
328 GdipRestoreGraphics(graphics2, state_a);
329 GdipGetInterpolationMode(graphics2, &mode);
330 expect(InterpolationModeNearestNeighbor, mode);
331 GdipDeleteGraphics(graphics1);
332 GdipDeleteGraphics(graphics2);
333
334 log_state(state_a, &state_log);
335
336 /* The same state value should never be returned twice. */
337 todo_wine
338 check_no_duplicates(state_log);
339
340 ReleaseDC(hwnd, hdc);
341 }
342
343 static void test_GdipFillClosedCurve2(void)
344 {
345 GpStatus status;
346 GpGraphics *graphics = NULL;
347 GpSolidFill *brush = NULL;
348 HDC hdc = GetDC( hwnd );
349 GpPointF points[3];
350
351 points[0].X = 0;
352 points[0].Y = 0;
353
354 points[1].X = 40;
355 points[1].Y = 20;
356
357 points[2].X = 10;
358 points[2].Y = 40;
359
360 /* make a graphics object and brush object */
361 ok(hdc != NULL, "Expected HDC to be initialized\n");
362
363 status = GdipCreateFromHDC(hdc, &graphics);
364 expect(Ok, status);
365 ok(graphics != NULL, "Expected graphics to be initialized\n");
366
367 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
368
369 /* InvalidParameter cases: null graphics, null brush, null points */
370 status = GdipFillClosedCurve2(NULL, NULL, NULL, 3, 0.5, FillModeAlternate);
371 expect(InvalidParameter, status);
372
373 status = GdipFillClosedCurve2(graphics, NULL, NULL, 3, 0.5, FillModeAlternate);
374 expect(InvalidParameter, status);
375
376 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
377 expect(InvalidParameter, status);
378
379 status = GdipFillClosedCurve2(NULL, NULL, points, 3, 0.5, FillModeAlternate);
380 expect(InvalidParameter, status);
381
382 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
383 expect(InvalidParameter, status);
384
385 status = GdipFillClosedCurve2(graphics, NULL, points, 3, 0.5, FillModeAlternate);
386 expect(InvalidParameter, status);
387
388 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
389 expect(InvalidParameter, status);
390
391 /* InvalidParameter cases: invalid count */
392 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
393 expect(InvalidParameter, status);
394
395 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
396 expect(InvalidParameter, status);
397
398 /* Valid test cases */
399 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
400 expect(Ok, status);
401
402 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
403 expect(Ok, status);
404
405 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
406 expect(Ok, status);
407
408 GdipDeleteGraphics(graphics);
409 GdipDeleteBrush((GpBrush*)brush);
410
411 ReleaseDC(hwnd, hdc);
412 }
413
414 static void test_GdipFillClosedCurve2I(void)
415 {
416 GpStatus status;
417 GpGraphics *graphics = NULL;
418 GpSolidFill *brush = NULL;
419 HDC hdc = GetDC( hwnd );
420 GpPoint points[3];
421
422 points[0].X = 0;
423 points[0].Y = 0;
424
425 points[1].X = 40;
426 points[1].Y = 20;
427
428 points[2].X = 10;
429 points[2].Y = 40;
430
431 /* make a graphics object and brush object */
432 ok(hdc != NULL, "Expected HDC to be initialized\n");
433
434 status = GdipCreateFromHDC(hdc, &graphics);
435 expect(Ok, status);
436 ok(graphics != NULL, "Expected graphics to be initialized\n");
437
438 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
439
440 /* InvalidParameter cases: null graphics, null brush */
441 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
442 when points == NULL, so don't test this condition */
443 status = GdipFillClosedCurve2I(NULL, NULL, points, 3, 0.5, FillModeAlternate);
444 expect(InvalidParameter, status);
445
446 status = GdipFillClosedCurve2I(graphics, NULL, points, 3, 0.5, FillModeAlternate);
447 expect(InvalidParameter, status);
448
449 status = GdipFillClosedCurve2I(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
450 expect(InvalidParameter, status);
451
452 /* InvalidParameter cases: invalid count */
453 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
454 expect(InvalidParameter, status);
455
456 /* OutOfMemory cases: large (unsigned) int */
457 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
458 expect(OutOfMemory, status);
459
460 /* Valid test cases */
461 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
462 expect(Ok, status);
463
464 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
465 expect(Ok, status);
466
467 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
468 expect(Ok, status);
469
470 GdipDeleteGraphics(graphics);
471 GdipDeleteBrush((GpBrush*)brush);
472
473 ReleaseDC(hwnd, hdc);
474 }
475
476 static void test_GdipDrawArc(void)
477 {
478 GpStatus status;
479 GpGraphics *graphics = NULL;
480 GpPen *pen = NULL;
481 HDC hdc = GetDC( hwnd );
482
483 /* make a graphics object and pen object */
484 ok(hdc != NULL, "Expected HDC to be initialized\n");
485
486 status = GdipCreateFromHDC(hdc, &graphics);
487 expect(Ok, status);
488 ok(graphics != NULL, "Expected graphics to be initialized\n");
489
490 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
491 expect(Ok, status);
492 ok(pen != NULL, "Expected pen to be initialized\n");
493
494 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
495 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
496 expect(InvalidParameter, status);
497
498 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
499 expect(InvalidParameter, status);
500
501 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
502 expect(InvalidParameter, status);
503
504 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
505 expect(InvalidParameter, status);
506
507 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
508 expect(InvalidParameter, status);
509
510 /* successful case */
511 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
512 expect(Ok, status);
513
514 GdipDeletePen(pen);
515 GdipDeleteGraphics(graphics);
516
517 ReleaseDC(hwnd, hdc);
518 }
519
520 static void test_GdipDrawArcI(void)
521 {
522 GpStatus status;
523 GpGraphics *graphics = NULL;
524 GpPen *pen = NULL;
525 HDC hdc = GetDC( hwnd );
526
527 /* make a graphics object and pen object */
528 ok(hdc != NULL, "Expected HDC to be initialized\n");
529
530 status = GdipCreateFromHDC(hdc, &graphics);
531 expect(Ok, status);
532 ok(graphics != NULL, "Expected graphics to be initialized\n");
533
534 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
535 expect(Ok, status);
536 ok(pen != NULL, "Expected pen to be initialized\n");
537
538 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
539 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
540 expect(InvalidParameter, status);
541
542 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
543 expect(InvalidParameter, status);
544
545 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
546 expect(InvalidParameter, status);
547
548 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
549 expect(InvalidParameter, status);
550
551 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
552 expect(InvalidParameter, status);
553
554 /* successful case */
555 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
556 expect(Ok, status);
557
558 GdipDeletePen(pen);
559 GdipDeleteGraphics(graphics);
560
561 ReleaseDC(hwnd, hdc);
562 }
563
564 static void test_BeginContainer2(void)
565 {
566 GpMatrix *transform;
567 GpRectF clip;
568 REAL defClip[] = {5, 10, 15, 20};
569 REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
570 GraphicsContainer cont1, cont2, cont3, cont4;
571 CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
572 CompositingMode compmode, defCompmode = CompositingModeSourceOver;
573 InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
574 REAL scale, defScale = 17;
575 GpUnit unit, defUnit = UnitPixel;
576 PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
577 SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
578 UINT contrast, defContrast = 5;
579 TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
580
581 GpStatus status;
582 GpGraphics *graphics = NULL;
583 HDC hdc = GetDC( hwnd );
584
585 ok(hdc != NULL, "Expected HDC to be initialized\n");
586
587 status = GdipCreateFromHDC(hdc, &graphics);
588 expect(Ok, status);
589 ok(graphics != NULL, "Expected graphics to be initialized\n");
590
591 /* null graphics, null container */
592 status = GdipBeginContainer2(NULL, &cont1);
593 expect(InvalidParameter, status);
594
595 status = GdipBeginContainer2(graphics, NULL);
596 expect(InvalidParameter, status);
597
598 status = GdipEndContainer(NULL, cont1);
599 expect(InvalidParameter, status);
600
601 /* test all quality-related values */
602 GdipSetCompositingMode(graphics, defCompmode);
603 GdipSetCompositingQuality(graphics, defCompqual);
604 GdipSetInterpolationMode(graphics, defInterp);
605 GdipSetPageScale(graphics, defScale);
606 GdipSetPageUnit(graphics, defUnit);
607 GdipSetPixelOffsetMode(graphics, defOffsetmode);
608 GdipSetSmoothingMode(graphics, defSmoothmode);
609 GdipSetTextContrast(graphics, defContrast);
610 GdipSetTextRenderingHint(graphics, defTexthint);
611
612 status = GdipBeginContainer2(graphics, &cont1);
613 expect(Ok, status);
614
615 GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
616 GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
617 GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
618 GdipSetPageScale(graphics, 10);
619 GdipSetPageUnit(graphics, UnitDocument);
620 GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
621 GdipSetSmoothingMode(graphics, SmoothingModeNone);
622 GdipSetTextContrast(graphics, 7);
623 GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
624
625 status = GdipEndContainer(graphics, cont1);
626 expect(Ok, status);
627
628 GdipGetCompositingMode(graphics, &compmode);
629 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
630
631 GdipGetCompositingQuality(graphics, &compqual);
632 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
633
634 GdipGetInterpolationMode(graphics, &interp);
635 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
636
637 GdipGetPageScale(graphics, &scale);
638 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
639
640 GdipGetPageUnit(graphics, &unit);
641 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
642
643 GdipGetPixelOffsetMode(graphics, &offsetmode);
644 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
645
646 GdipGetSmoothingMode(graphics, &smoothmode);
647 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
648
649 GdipGetTextContrast(graphics, &contrast);
650 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
651
652 GdipGetTextRenderingHint(graphics, &texthint);
653 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
654
655 /* test world transform */
656 status = GdipBeginContainer2(graphics, &cont1);
657 expect(Ok, status);
658
659 status = GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
660 defTrans[4], defTrans[5], &transform);
661 expect(Ok, status);
662 GdipSetWorldTransform(graphics, transform);
663 GdipDeleteMatrix(transform);
664 transform = NULL;
665
666 status = GdipBeginContainer2(graphics, &cont2);
667 expect(Ok, status);
668
669 status = GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
670 expect(Ok, status);
671 GdipSetWorldTransform(graphics, transform);
672 GdipDeleteMatrix(transform);
673 transform = NULL;
674
675 status = GdipEndContainer(graphics, cont2);
676 expect(Ok, status);
677
678 status = GdipCreateMatrix(&transform);
679 expect(Ok, status);
680 GdipGetWorldTransform(graphics, transform);
681 GdipGetMatrixElements(transform, elems);
682 ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
683 fabs(defTrans[1] - elems[1]) < 0.0001 &&
684 fabs(defTrans[2] - elems[2]) < 0.0001 &&
685 fabs(defTrans[3] - elems[3]) < 0.0001 &&
686 fabs(defTrans[4] - elems[4]) < 0.0001 &&
687 fabs(defTrans[5] - elems[5]) < 0.0001,
688 "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
689 defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
690 elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
691 GdipDeleteMatrix(transform);
692 transform = NULL;
693
694 status = GdipEndContainer(graphics, cont1);
695 expect(Ok, status);
696
697 /* test clipping */
698 status = GdipBeginContainer2(graphics, &cont1);
699 expect(Ok, status);
700
701 GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
702
703 status = GdipBeginContainer2(graphics, &cont2);
704 expect(Ok, status);
705
706 GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
707
708 status = GdipEndContainer(graphics, cont2);
709 expect(Ok, status);
710
711 status = GdipGetClipBounds(graphics, &clip);
712 expect(Ok, status);
713
714 ok(fabs(defClip[0] - clip.X) < 0.0001 &&
715 fabs(defClip[1] - clip.Y) < 0.0001 &&
716 fabs(defClip[2] - clip.Width) < 0.0001 &&
717 fabs(defClip[3] - clip.Height) < 0.0001,
718 "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
719 defClip[0], defClip[1], defClip[2], defClip[3],
720 clip.X, clip.Y, clip.Width, clip.Height);
721
722 status = GdipEndContainer(graphics, cont1);
723 expect(Ok, status);
724
725 /* nesting */
726 status = GdipBeginContainer2(graphics, &cont1);
727 expect(Ok, status);
728
729 status = GdipBeginContainer2(graphics, &cont2);
730 expect(Ok, status);
731
732 status = GdipBeginContainer2(graphics, &cont3);
733 expect(Ok, status);
734
735 status = GdipEndContainer(graphics, cont3);
736 expect(Ok, status);
737
738 status = GdipBeginContainer2(graphics, &cont4);
739 expect(Ok, status);
740
741 status = GdipEndContainer(graphics, cont4);
742 expect(Ok, status);
743
744 /* skip cont2 */
745 status = GdipEndContainer(graphics, cont1);
746 expect(Ok, status);
747
748 /* end an already-ended container */
749 status = GdipEndContainer(graphics, cont1);
750 expect(Ok, status);
751
752 GdipDeleteGraphics(graphics);
753 ReleaseDC(hwnd, hdc);
754 }
755
756 static void test_GdipDrawBezierI(void)
757 {
758 GpStatus status;
759 GpGraphics *graphics = NULL;
760 GpPen *pen = NULL;
761 HDC hdc = GetDC( hwnd );
762
763 /* make a graphics object and pen object */
764 ok(hdc != NULL, "Expected HDC to be initialized\n");
765
766 status = GdipCreateFromHDC(hdc, &graphics);
767 expect(Ok, status);
768 ok(graphics != NULL, "Expected graphics to be initialized\n");
769
770 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
771 expect(Ok, status);
772 ok(pen != NULL, "Expected pen to be initialized\n");
773
774 /* InvalidParameter cases: null graphics, null pen */
775 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
776 expect(InvalidParameter, status);
777
778 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
779 expect(InvalidParameter, status);
780
781 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
782 expect(InvalidParameter, status);
783
784 /* successful case */
785 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
786 expect(Ok, status);
787
788 GdipDeletePen(pen);
789 GdipDeleteGraphics(graphics);
790
791 ReleaseDC(hwnd, hdc);
792 }
793
794 static void test_GdipDrawCurve3(void)
795 {
796 GpStatus status;
797 GpGraphics *graphics = NULL;
798 GpPen *pen = NULL;
799 HDC hdc = GetDC( hwnd );
800 GpPointF points[3];
801
802 points[0].X = 0;
803 points[0].Y = 0;
804
805 points[1].X = 40;
806 points[1].Y = 20;
807
808 points[2].X = 10;
809 points[2].Y = 40;
810
811 /* make a graphics object and pen object */
812 ok(hdc != NULL, "Expected HDC to be initialized\n");
813
814 status = GdipCreateFromHDC(hdc, &graphics);
815 expect(Ok, status);
816 ok(graphics != NULL, "Expected graphics to be initialized\n");
817
818 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
819 expect(Ok, status);
820 ok(pen != NULL, "Expected pen to be initialized\n");
821
822 /* InvalidParameter cases: null graphics, null pen */
823 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
824 expect(InvalidParameter, status);
825
826 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
827 expect(InvalidParameter, status);
828
829 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
830 expect(InvalidParameter, status);
831
832 /* InvalidParameter cases: invalid count */
833 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
834 expect(InvalidParameter, status);
835
836 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
837 expect(InvalidParameter, status);
838
839 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
840 expect(InvalidParameter, status);
841
842 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
843 expect(InvalidParameter, status);
844
845 /* InvalidParameter cases: invalid number of segments */
846 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
847 expect(InvalidParameter, status);
848
849 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
850 expect(InvalidParameter, status);
851
852 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
853 expect(InvalidParameter, status);
854
855 /* Valid test cases */
856 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
857 expect(Ok, status);
858
859 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
860 expect(Ok, status);
861
862 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
863 expect(Ok, status);
864
865 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
866 expect(Ok, status);
867
868 GdipDeletePen(pen);
869 GdipDeleteGraphics(graphics);
870
871 ReleaseDC(hwnd, hdc);
872 }
873
874 static void test_GdipDrawCurve3I(void)
875 {
876 GpStatus status;
877 GpGraphics *graphics = NULL;
878 GpPen *pen = NULL;
879 HDC hdc = GetDC( hwnd );
880 GpPoint points[3];
881
882 points[0].X = 0;
883 points[0].Y = 0;
884
885 points[1].X = 40;
886 points[1].Y = 20;
887
888 points[2].X = 10;
889 points[2].Y = 40;
890
891 /* make a graphics object and pen object */
892 ok(hdc != NULL, "Expected HDC to be initialized\n");
893
894 status = GdipCreateFromHDC(hdc, &graphics);
895 expect(Ok, status);
896 ok(graphics != NULL, "Expected graphics to be initialized\n");
897
898 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
899 expect(Ok, status);
900 ok(pen != NULL, "Expected pen to be initialized\n");
901
902 /* InvalidParameter cases: null graphics, null pen */
903 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
904 expect(InvalidParameter, status);
905
906 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
907 expect(InvalidParameter, status);
908
909 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
910 expect(InvalidParameter, status);
911
912 /* InvalidParameter cases: invalid count */
913 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
914 expect(OutOfMemory, status);
915
916 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
917 expect(InvalidParameter, status);
918
919 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
920 expect(InvalidParameter, status);
921
922 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
923 expect(InvalidParameter, status);
924
925 /* InvalidParameter cases: invalid number of segments */
926 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
927 expect(InvalidParameter, status);
928
929 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
930 expect(InvalidParameter, status);
931
932 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
933 expect(InvalidParameter, status);
934
935 /* Valid test cases */
936 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
937 expect(Ok, status);
938
939 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
940 expect(Ok, status);
941
942 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
943 expect(Ok, status);
944
945 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
946 expect(Ok, status);
947
948 GdipDeletePen(pen);
949 GdipDeleteGraphics(graphics);
950
951 ReleaseDC(hwnd, hdc);
952 }
953
954 static void test_GdipDrawCurve2(void)
955 {
956 GpStatus status;
957 GpGraphics *graphics = NULL;
958 GpPen *pen = NULL;
959 HDC hdc = GetDC( hwnd );
960 GpPointF points[3];
961
962 points[0].X = 0;
963 points[0].Y = 0;
964
965 points[1].X = 40;
966 points[1].Y = 20;
967
968 points[2].X = 10;
969 points[2].Y = 40;
970
971 /* make a graphics object and pen object */
972 ok(hdc != NULL, "Expected HDC to be initialized\n");
973
974 status = GdipCreateFromHDC(hdc, &graphics);
975 expect(Ok, status);
976 ok(graphics != NULL, "Expected graphics to be initialized\n");
977
978 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
979 expect(Ok, status);
980 ok(pen != NULL, "Expected pen to be initialized\n");
981
982 /* InvalidParameter cases: null graphics, null pen */
983 status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
984 expect(InvalidParameter, status);
985
986 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
987 expect(InvalidParameter, status);
988
989 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
990 expect(InvalidParameter, status);
991
992 /* InvalidParameter cases: invalid count */
993 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
994 expect(InvalidParameter, status);
995
996 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
997 expect(InvalidParameter, status);
998
999 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
1000 expect(InvalidParameter, status);
1001
1002 /* Valid test cases */
1003 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
1004 expect(Ok, status);
1005
1006 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
1007 expect(Ok, status);
1008
1009 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
1010 expect(Ok, status);
1011
1012 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
1013 expect(Ok, status);
1014
1015 GdipDeletePen(pen);
1016 GdipDeleteGraphics(graphics);
1017
1018 ReleaseDC(hwnd, hdc);
1019 }
1020
1021 static void test_GdipDrawCurve2I(void)
1022 {
1023 GpStatus status;
1024 GpGraphics *graphics = NULL;
1025 GpPen *pen = NULL;
1026 HDC hdc = GetDC( hwnd );
1027 GpPoint points[3];
1028
1029 points[0].X = 0;
1030 points[0].Y = 0;
1031
1032 points[1].X = 40;
1033 points[1].Y = 20;
1034
1035 points[2].X = 10;
1036 points[2].Y = 40;
1037
1038 /* make a graphics object and pen object */
1039 ok(hdc != NULL, "Expected HDC to be initialized\n");
1040
1041 status = GdipCreateFromHDC(hdc, &graphics);
1042 expect(Ok, status);
1043 ok(graphics != NULL, "Expected graphics to be initialized\n");
1044
1045 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1046 expect(Ok, status);
1047 ok(pen != NULL, "Expected pen to be initialized\n");
1048
1049 /* InvalidParameter cases: null graphics, null pen */
1050 status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
1051 expect(InvalidParameter, status);
1052
1053 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
1054 expect(InvalidParameter, status);
1055
1056 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
1057 expect(InvalidParameter, status);
1058
1059 /* InvalidParameter cases: invalid count */
1060 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
1061 expect(OutOfMemory, status);
1062
1063 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
1064 expect(InvalidParameter, status);
1065
1066 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
1067 expect(InvalidParameter, status);
1068
1069 /* Valid test cases */
1070 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
1071 expect(Ok, status);
1072
1073 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
1074 expect(Ok, status);
1075
1076 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
1077 expect(Ok, status);
1078
1079 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
1080 expect(Ok, status);
1081
1082 GdipDeletePen(pen);
1083 GdipDeleteGraphics(graphics);
1084
1085 ReleaseDC(hwnd, hdc);
1086 }
1087
1088 static void test_GdipDrawCurve(void)
1089 {
1090 GpStatus status;
1091 GpGraphics *graphics = NULL;
1092 GpPen *pen = NULL;
1093 HDC hdc = GetDC( hwnd );
1094 GpPointF points[3];
1095
1096 points[0].X = 0;
1097 points[0].Y = 0;
1098
1099 points[1].X = 40;
1100 points[1].Y = 20;
1101
1102 points[2].X = 10;
1103 points[2].Y = 40;
1104
1105 /* make a graphics object and pen object */
1106 ok(hdc != NULL, "Expected HDC to be initialized\n");
1107
1108 status = GdipCreateFromHDC(hdc, &graphics);
1109 expect(Ok, status);
1110 ok(graphics != NULL, "Expected graphics to be initialized\n");
1111
1112 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1113 expect(Ok, status);
1114 ok(pen != NULL, "Expected pen to be initialized\n");
1115
1116 /* InvalidParameter cases: null graphics, null pen */
1117 status = GdipDrawCurve(NULL, NULL, points, 3);
1118 expect(InvalidParameter, status);
1119
1120 status = GdipDrawCurve(graphics, NULL, points, 3);
1121 expect(InvalidParameter, status);
1122
1123 status = GdipDrawCurve(NULL, pen, points, 3);
1124 expect(InvalidParameter, status);
1125
1126 /* InvalidParameter cases: invalid count */
1127 status = GdipDrawCurve(graphics, pen, points, -1);
1128 expect(InvalidParameter, status);
1129
1130 status = GdipDrawCurve(graphics, pen, points, 0);
1131 expect(InvalidParameter, status);
1132
1133 status = GdipDrawCurve(graphics, pen, points, 1);
1134 expect(InvalidParameter, status);
1135
1136 /* Valid test cases */
1137 status = GdipDrawCurve(graphics, pen, points, 2);
1138 expect(Ok, status);
1139
1140 status = GdipDrawCurve(graphics, pen, points, 3);
1141 expect(Ok, status);
1142
1143 GdipDeletePen(pen);
1144 GdipDeleteGraphics(graphics);
1145
1146 ReleaseDC(hwnd, hdc);
1147 }
1148
1149 static void test_GdipDrawCurveI(void)
1150 {
1151 GpStatus status;
1152 GpGraphics *graphics = NULL;
1153 GpPen *pen = NULL;
1154 HDC hdc = GetDC( hwnd );
1155 GpPoint points[3];
1156
1157 points[0].X = 0;
1158 points[0].Y = 0;
1159
1160 points[1].X = 40;
1161 points[1].Y = 20;
1162
1163 points[2].X = 10;
1164 points[2].Y = 40;
1165
1166 /* make a graphics object and pen object */
1167 ok(hdc != NULL, "Expected HDC to be initialized\n");
1168
1169 status = GdipCreateFromHDC(hdc, &graphics);
1170 expect(Ok, status);
1171 ok(graphics != NULL, "Expected graphics to be initialized\n");
1172
1173 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1174 expect(Ok, status);
1175 ok(pen != NULL, "Expected pen to be initialized\n");
1176
1177 /* InvalidParameter cases: null graphics, null pen */
1178 status = GdipDrawCurveI(NULL, NULL, points, 3);
1179 expect(InvalidParameter, status);
1180
1181 status = GdipDrawCurveI(graphics, NULL, points, 3);
1182 expect(InvalidParameter, status);
1183
1184 status = GdipDrawCurveI(NULL, pen, points, 3);
1185 expect(InvalidParameter, status);
1186
1187 /* InvalidParameter cases: invalid count */
1188 status = GdipDrawCurveI(graphics, pen, points, -1);
1189 expect(OutOfMemory, status);
1190
1191 status = GdipDrawCurveI(graphics, pen, points, 0);
1192 expect(InvalidParameter, status);
1193
1194 status = GdipDrawCurveI(graphics, pen, points, 1);
1195 expect(InvalidParameter, status);
1196
1197 /* Valid test cases */
1198 status = GdipDrawCurveI(graphics, pen, points, 2);
1199 expect(Ok, status);
1200
1201 status = GdipDrawCurveI(graphics, pen, points, 3);
1202 expect(Ok, status);
1203
1204 GdipDeletePen(pen);
1205 GdipDeleteGraphics(graphics);
1206
1207 ReleaseDC(hwnd, hdc);
1208 }
1209
1210 static void test_GdipDrawLineI(void)
1211 {
1212 GpStatus status;
1213 GpGraphics *graphics = NULL;
1214 GpPen *pen = NULL;
1215 HDC hdc = GetDC( hwnd );
1216
1217 /* make a graphics object and pen object */
1218 ok(hdc != NULL, "Expected HDC to be initialized\n");
1219
1220 status = GdipCreateFromHDC(hdc, &graphics);
1221 expect(Ok, status);
1222 ok(graphics != NULL, "Expected graphics to be initialized\n");
1223
1224 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1225 expect(Ok, status);
1226 ok(pen != NULL, "Expected pen to be initialized\n");
1227
1228 /* InvalidParameter cases: null graphics, null pen */
1229 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
1230 expect(InvalidParameter, status);
1231
1232 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
1233 expect(InvalidParameter, status);
1234
1235 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
1236 expect(InvalidParameter, status);
1237
1238 /* successful case */
1239 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
1240 expect(Ok, status);
1241
1242 GdipDeletePen(pen);
1243 GdipDeleteGraphics(graphics);
1244
1245 ReleaseDC(hwnd, hdc);
1246 }
1247
1248 static void test_GdipDrawImagePointsRect(void)
1249 {
1250 GpStatus status;
1251 GpGraphics *graphics = NULL;
1252 GpPointF ptf[4];
1253 GpBitmap *bm = NULL;
1254 BYTE rbmi[sizeof(BITMAPINFOHEADER)];
1255 BYTE buff[400];
1256 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
1257 HDC hdc = GetDC( hwnd );
1258 if (!hdc)
1259 return;
1260
1261 memset(rbmi, 0, sizeof(rbmi));
1262 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1263 bmi->bmiHeader.biWidth = 10;
1264 bmi->bmiHeader.biHeight = 10;
1265 bmi->bmiHeader.biPlanes = 1;
1266 bmi->bmiHeader.biBitCount = 32;
1267 bmi->bmiHeader.biCompression = BI_RGB;
1268 status = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
1269 expect(Ok, status);
1270 ok(NULL != bm, "Expected bitmap to be initialized\n");
1271 status = GdipCreateFromHDC(hdc, &graphics);
1272 expect(Ok, status);
1273 ptf[0].X = 0;
1274 ptf[0].Y = 0;
1275 ptf[1].X = 10;
1276 ptf[1].Y = 0;
1277 ptf[2].X = 0;
1278 ptf[2].Y = 10;
1279 ptf[3].X = 10;
1280 ptf[3].Y = 10;
1281 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 4, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1282 expect(NotImplemented, status);
1283 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 2, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1284 expect(InvalidParameter, status);
1285 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1286 expect(Ok, status);
1287 status = GdipDrawImagePointsRect(graphics, NULL, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1288 expect(InvalidParameter, status);
1289 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, NULL, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1290 expect(InvalidParameter, status);
1291 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 0, 0, UnitPixel, NULL, NULL, NULL);
1292 expect(Ok, status);
1293 memset(ptf, 0, sizeof(ptf));
1294 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1295 expect(Ok, status);
1296
1297 GdipDisposeImage((GpImage*)bm);
1298 GdipDeleteGraphics(graphics);
1299 ReleaseDC(hwnd, hdc);
1300 }
1301
1302 static void test_GdipDrawLinesI(void)
1303 {
1304 GpStatus status;
1305 GpGraphics *graphics = NULL;
1306 GpPen *pen = NULL;
1307 GpPoint *ptf = NULL;
1308 HDC hdc = GetDC( hwnd );
1309
1310 /* make a graphics object and pen object */
1311 ok(hdc != NULL, "Expected HDC to be initialized\n");
1312
1313 status = GdipCreateFromHDC(hdc, &graphics);
1314 expect(Ok, status);
1315 ok(graphics != NULL, "Expected graphics to be initialized\n");
1316
1317 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1318 expect(Ok, status);
1319 ok(pen != NULL, "Expected pen to be initialized\n");
1320
1321 /* make some arbitrary valid points*/
1322 ptf = GdipAlloc(2 * sizeof(GpPointF));
1323
1324 ptf[0].X = 1;
1325 ptf[0].Y = 1;
1326
1327 ptf[1].X = 2;
1328 ptf[1].Y = 2;
1329
1330 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1331 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1332 expect(InvalidParameter, status);
1333
1334 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1335 expect(InvalidParameter, status);
1336
1337 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1338 expect(InvalidParameter, status);
1339
1340 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1341 expect(InvalidParameter, status);
1342
1343 /* successful case */
1344 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1345 expect(Ok, status);
1346
1347 GdipFree(ptf);
1348 GdipDeletePen(pen);
1349 GdipDeleteGraphics(graphics);
1350
1351 ReleaseDC(hwnd, hdc);
1352 }
1353
1354 static void test_GdipFillClosedCurve(void)
1355 {
1356 GpStatus status;
1357 GpGraphics *graphics = NULL;
1358 GpSolidFill *brush = NULL;
1359 HDC hdc = GetDC( hwnd );
1360 GpPointF points[3];
1361
1362 points[0].X = 0;
1363 points[0].Y = 0;
1364
1365 points[1].X = 40;
1366 points[1].Y = 20;
1367
1368 points[2].X = 10;
1369 points[2].Y = 40;
1370
1371 /* make a graphics object and brush object */
1372 ok(hdc != NULL, "Expected HDC to be initialized\n");
1373
1374 status = GdipCreateFromHDC(hdc, &graphics);
1375 expect(Ok, status);
1376 ok(graphics != NULL, "Expected graphics to be initialized\n");
1377
1378 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1379
1380 /* InvalidParameter cases: null graphics, null brush, null points */
1381 status = GdipFillClosedCurve(NULL, NULL, NULL, 3);
1382 expect(InvalidParameter, status);
1383
1384 status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1385 expect(InvalidParameter, status);
1386
1387 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1388 expect(InvalidParameter, status);
1389
1390 status = GdipFillClosedCurve(NULL, NULL, points, 3);
1391 expect(InvalidParameter, status);
1392
1393 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1394 expect(InvalidParameter, status);
1395
1396 status = GdipFillClosedCurve(graphics, NULL, points, 3);
1397 expect(InvalidParameter, status);
1398
1399 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, points, 3);
1400 expect(InvalidParameter, status);
1401
1402 /* InvalidParameter cases: invalid count */
1403 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1404 expect(InvalidParameter, status);
1405
1406 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1407 expect(InvalidParameter, status);
1408
1409 /* Valid test cases */
1410 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1411 expect(Ok, status);
1412
1413 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1414 expect(Ok, status);
1415
1416 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1417 expect(Ok, status);
1418
1419 GdipDeleteGraphics(graphics);
1420 GdipDeleteBrush((GpBrush*)brush);
1421
1422 ReleaseDC(hwnd, hdc);
1423 }
1424
1425 static void test_GdipFillClosedCurveI(void)
1426 {
1427 GpStatus status;
1428 GpGraphics *graphics = NULL;
1429 GpSolidFill *brush = NULL;
1430 HDC hdc = GetDC( hwnd );
1431 GpPoint points[3];
1432
1433 points[0].X = 0;
1434 points[0].Y = 0;
1435
1436 points[1].X = 40;
1437 points[1].Y = 20;
1438
1439 points[2].X = 10;
1440 points[2].Y = 40;
1441
1442 /* make a graphics object and brush object */
1443 ok(hdc != NULL, "Expected HDC to be initialized\n");
1444
1445 status = GdipCreateFromHDC(hdc, &graphics);
1446 expect(Ok, status);
1447 ok(graphics != NULL, "Expected graphics to be initialized\n");
1448
1449 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1450
1451 /* InvalidParameter cases: null graphics, null brush */
1452 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
1453 when points == NULL, so don't test this condition */
1454 status = GdipFillClosedCurveI(NULL, NULL, points, 3);
1455 expect(InvalidParameter, status);
1456
1457 status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1458 expect(InvalidParameter, status);
1459
1460 status = GdipFillClosedCurveI(NULL, (GpBrush*)brush, points, 3);
1461 expect(InvalidParameter, status);
1462
1463 /* InvalidParameter cases: invalid count */
1464 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1465 expect(InvalidParameter, status);
1466
1467 /* OutOfMemory cases: large (unsigned) int */
1468 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1469 expect(OutOfMemory, status);
1470
1471 /* Valid test cases */
1472 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1473 expect(Ok, status);
1474
1475 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1476 expect(Ok, status);
1477
1478 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1479 expect(Ok, status);
1480
1481 GdipDeleteGraphics(graphics);
1482 GdipDeleteBrush((GpBrush*)brush);
1483
1484 ReleaseDC(hwnd, hdc);
1485 }
1486
1487 static void test_Get_Release_DC(void)
1488 {
1489 GpStatus status;
1490 GpGraphics *graphics = NULL;
1491 GpPen *pen;
1492 GpSolidFill *brush;
1493 GpPath *path;
1494 HDC hdc = GetDC( hwnd );
1495 HDC retdc;
1496 REAL r;
1497 CompositingQuality quality;
1498 CompositingMode compmode;
1499 InterpolationMode intmode;
1500 GpMatrix *m;
1501 GpRegion *region;
1502 GpUnit unit;
1503 PixelOffsetMode offsetmode;
1504 SmoothingMode smoothmode;
1505 TextRenderingHint texthint;
1506 GpPointF ptf[5];
1507 GpPoint pt[5];
1508 GpRectF rectf[2];
1509 GpRect rect[2];
1510 GpRegion *clip;
1511 INT i;
1512 BOOL res;
1513 ARGB color = 0x00000000;
1514 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1515
1516 pt[0].X = 10;
1517 pt[0].Y = 10;
1518 pt[1].X = 20;
1519 pt[1].Y = 15;
1520 pt[2].X = 40;
1521 pt[2].Y = 80;
1522 pt[3].X = -20;
1523 pt[3].Y = 20;
1524 pt[4].X = 50;
1525 pt[4].Y = 110;
1526
1527 for(i = 0; i < 5;i++){
1528 ptf[i].X = (REAL)pt[i].X;
1529 ptf[i].Y = (REAL)pt[i].Y;
1530 }
1531
1532 rect[0].X = 0;
1533 rect[0].Y = 0;
1534 rect[0].Width = 50;
1535 rect[0].Height = 70;
1536 rect[1].X = 0;
1537 rect[1].Y = 0;
1538 rect[1].Width = 10;
1539 rect[1].Height = 20;
1540
1541 for(i = 0; i < 2;i++){
1542 rectf[i].X = (REAL)rect[i].X;
1543 rectf[i].Y = (REAL)rect[i].Y;
1544 rectf[i].Height = (REAL)rect[i].Height;
1545 rectf[i].Width = (REAL)rect[i].Width;
1546 }
1547
1548 status = GdipCreateMatrix(&m);
1549 expect(Ok, status);
1550 GdipCreateRegion(&region);
1551 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1552 GdipCreatePath(FillModeAlternate, &path);
1553 GdipCreateRegion(&clip);
1554
1555 status = GdipCreateFromHDC(hdc, &graphics);
1556 expect(Ok, status);
1557 ok(graphics != NULL, "Expected graphics to be initialized\n");
1558 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1559 expect(Ok, status);
1560
1561 /* NULL arguments */
1562 status = GdipGetDC(NULL, NULL);
1563 expect(InvalidParameter, status);
1564 status = GdipGetDC(graphics, NULL);
1565 expect(InvalidParameter, status);
1566 status = GdipGetDC(NULL, &retdc);
1567 expect(InvalidParameter, status);
1568
1569 status = GdipReleaseDC(NULL, NULL);
1570 expect(InvalidParameter, status);
1571 status = GdipReleaseDC(graphics, NULL);
1572 expect(InvalidParameter, status);
1573 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1574 expect(InvalidParameter, status);
1575
1576 /* Release without Get */
1577 status = GdipReleaseDC(graphics, hdc);
1578 expect(InvalidParameter, status);
1579
1580 retdc = NULL;
1581 status = GdipGetDC(graphics, &retdc);
1582 expect(Ok, status);
1583 ok(retdc == hdc, "Invalid HDC returned\n");
1584 /* call it once more */
1585 status = GdipGetDC(graphics, &retdc);
1586 expect(ObjectBusy, status);
1587
1588 /* try all Graphics calls here */
1589 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1590 expect(ObjectBusy, status);
1591 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1592 expect(ObjectBusy, status);
1593 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1594 expect(ObjectBusy, status);
1595 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1596 expect(ObjectBusy, status);
1597 status = GdipDrawBeziers(graphics, pen, ptf, 5);
1598 expect(ObjectBusy, status);
1599 status = GdipDrawBeziersI(graphics, pen, pt, 5);
1600 expect(ObjectBusy, status);
1601 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1602 expect(ObjectBusy, status);
1603 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1604 expect(ObjectBusy, status);
1605 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1606 expect(ObjectBusy, status);
1607 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1608 expect(ObjectBusy, status);
1609 status = GdipDrawCurve(graphics, pen, ptf, 5);
1610 expect(ObjectBusy, status);
1611 status = GdipDrawCurveI(graphics, pen, pt, 5);
1612 expect(ObjectBusy, status);
1613 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1614 expect(ObjectBusy, status);
1615 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1616 expect(ObjectBusy, status);
1617 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1618 expect(ObjectBusy, status);
1619 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1620 expect(ObjectBusy, status);
1621 /* GdipDrawImage/GdipDrawImageI */
1622 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1623 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1624 /* GdipDrawImageRect/GdipDrawImageRectI */
1625 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1626 expect(ObjectBusy, status);
1627 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1628 expect(ObjectBusy, status);
1629 status = GdipDrawLines(graphics, pen, ptf, 5);
1630 expect(ObjectBusy, status);
1631 status = GdipDrawLinesI(graphics, pen, pt, 5);
1632 expect(ObjectBusy, status);
1633 status = GdipDrawPath(graphics, pen, path);
1634 expect(ObjectBusy, status);
1635 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1636 expect(ObjectBusy, status);
1637 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1638 expect(ObjectBusy, status);
1639 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1640 expect(ObjectBusy, status);
1641 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1642 expect(ObjectBusy, status);
1643 status = GdipDrawRectangles(graphics, pen, rectf, 2);
1644 expect(ObjectBusy, status);
1645 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1646 expect(ObjectBusy, status);
1647 /* GdipDrawString */
1648 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1649 expect(ObjectBusy, status);
1650 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1651 expect(ObjectBusy, status);
1652 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, ptf, 5);
1653 expect(ObjectBusy, status);
1654 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, pt, 5);
1655 expect(ObjectBusy, status);
1656 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1657 expect(ObjectBusy, status);
1658 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1659 expect(ObjectBusy, status);
1660 status = GdipFillPath(graphics, (GpBrush*)brush, path);
1661 expect(ObjectBusy, status);
1662 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1663 expect(ObjectBusy, status);
1664 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1665 expect(ObjectBusy, status);
1666 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1667 expect(ObjectBusy, status);
1668 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1669 expect(ObjectBusy, status);
1670 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1671 expect(ObjectBusy, status);
1672 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1673 expect(ObjectBusy, status);
1674 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1675 expect(ObjectBusy, status);
1676 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1677 expect(ObjectBusy, status);
1678 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1679 expect(ObjectBusy, status);
1680 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1681 expect(ObjectBusy, status);
1682 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1683 expect(ObjectBusy, status);
1684 status = GdipFlush(graphics, FlushIntentionFlush);
1685 expect(ObjectBusy, status);
1686 status = GdipGetClipBounds(graphics, rectf);
1687 expect(ObjectBusy, status);
1688 status = GdipGetClipBoundsI(graphics, rect);
1689 expect(ObjectBusy, status);
1690 status = GdipGetCompositingMode(graphics, &compmode);
1691 expect(ObjectBusy, status);
1692 status = GdipGetCompositingQuality(graphics, &quality);
1693 expect(ObjectBusy, status);
1694 status = GdipGetInterpolationMode(graphics, &intmode);
1695 expect(ObjectBusy, status);
1696 status = GdipGetNearestColor(graphics, &color);
1697 expect(ObjectBusy, status);
1698 status = GdipGetPageScale(graphics, &r);
1699 expect(ObjectBusy, status);
1700 status = GdipGetPageUnit(graphics, &unit);
1701 expect(ObjectBusy, status);
1702 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1703 expect(ObjectBusy, status);
1704 status = GdipGetSmoothingMode(graphics, &smoothmode);
1705 expect(ObjectBusy, status);
1706 status = GdipGetTextRenderingHint(graphics, &texthint);
1707 expect(ObjectBusy, status);
1708 status = GdipGetWorldTransform(graphics, m);
1709 expect(ObjectBusy, status);
1710 status = GdipGraphicsClear(graphics, 0xdeadbeef);
1711 expect(ObjectBusy, status);
1712 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1713 expect(ObjectBusy, status);
1714 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1715 expect(ObjectBusy, status);
1716 /* GdipMeasureCharacterRanges */
1717 /* GdipMeasureString */
1718 status = GdipResetClip(graphics);
1719 expect(ObjectBusy, status);
1720 status = GdipResetWorldTransform(graphics);
1721 expect(ObjectBusy, status);
1722 /* GdipRestoreGraphics */
1723 status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1724 expect(ObjectBusy, status);
1725 /* GdipSaveGraphics */
1726 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1727 expect(ObjectBusy, status);
1728 status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1729 expect(ObjectBusy, status);
1730 status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1731 expect(ObjectBusy, status);
1732 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1733 expect(ObjectBusy, status);
1734 status = GdipSetPageScale(graphics, 1.0);
1735 expect(ObjectBusy, status);
1736 status = GdipSetPageUnit(graphics, UnitWorld);
1737 expect(ObjectBusy, status);
1738 status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1739 expect(ObjectBusy, status);
1740 status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1741 expect(ObjectBusy, status);
1742 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1743 expect(ObjectBusy, status);
1744 status = GdipSetWorldTransform(graphics, m);
1745 expect(ObjectBusy, status);
1746 status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1747 expect(ObjectBusy, status);
1748 status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1749 expect(ObjectBusy, status);
1750 status = GdipSetClipPath(graphics, path, CombineModeReplace);
1751 expect(ObjectBusy, status);
1752 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1753 expect(ObjectBusy, status);
1754 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1755 expect(ObjectBusy, status);
1756 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1757 expect(ObjectBusy, status);
1758 status = GdipTranslateClip(graphics, 0.0, 0.0);
1759 expect(ObjectBusy, status);
1760 status = GdipTranslateClipI(graphics, 0, 0);
1761 expect(ObjectBusy, status);
1762 status = GdipDrawPolygon(graphics, pen, ptf, 5);
1763 expect(ObjectBusy, status);
1764 status = GdipDrawPolygonI(graphics, pen, pt, 5);
1765 expect(ObjectBusy, status);
1766 status = GdipGetDpiX(graphics, &r);
1767 expect(ObjectBusy, status);
1768 status = GdipGetDpiY(graphics, &r);
1769 expect(ObjectBusy, status);
1770 status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1771 expect(ObjectBusy, status);
1772 status = GdipGetClip(graphics, region);
1773 expect(ObjectBusy, status);
1774 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1775 expect(ObjectBusy, status);
1776
1777 /* try to delete before release */
1778 status = GdipDeleteGraphics(graphics);
1779 expect(ObjectBusy, status);
1780
1781 status = GdipReleaseDC(graphics, retdc);
1782 expect(Ok, status);
1783
1784 GdipDeletePen(pen);
1785 GdipDeleteGraphics(graphics);
1786
1787 GdipDeleteRegion(clip);
1788 GdipDeletePath(path);
1789 GdipDeleteBrush((GpBrush*)brush);
1790 GdipDeleteRegion(region);
1791 GdipDeleteMatrix(m);
1792 DeleteObject(hrgn);
1793
1794 ReleaseDC(hwnd, hdc);
1795 }
1796
1797 static void test_transformpoints(void)
1798 {
1799 GpStatus status;
1800 GpGraphics *graphics = NULL;
1801 HDC hdc = GetDC( hwnd );
1802 GpPointF ptf[2];
1803 GpPoint pt[2];
1804
1805 status = GdipCreateFromHDC(hdc, &graphics);
1806 expect(Ok, status);
1807
1808 /* NULL arguments */
1809 status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1810 expect(InvalidParameter, status);
1811 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1812 expect(InvalidParameter, status);
1813 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1814 expect(InvalidParameter, status);
1815 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1816 expect(InvalidParameter, status);
1817
1818 ptf[0].X = 1.0;
1819 ptf[0].Y = 0.0;
1820 ptf[1].X = 0.0;
1821 ptf[1].Y = 1.0;
1822 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1823 expect(Ok, status);
1824 expectf(1.0, ptf[0].X);
1825 expectf(0.0, ptf[0].Y);
1826 expectf(0.0, ptf[1].X);
1827 expectf(1.0, ptf[1].Y);
1828
1829 status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1830 expect(Ok, status);
1831 status = GdipSetPageUnit(graphics, UnitPixel);
1832 expect(Ok, status);
1833 status = GdipSetPageScale(graphics, 3.0);
1834 expect(Ok, status);
1835
1836 ptf[0].X = 1.0;
1837 ptf[0].Y = 0.0;
1838 ptf[1].X = 0.0;
1839 ptf[1].Y = 1.0;
1840 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1841 expect(Ok, status);
1842 expectf(18.0, ptf[0].X);
1843 expectf(15.0, ptf[0].Y);
1844 expectf(15.0, ptf[1].X);
1845 expectf(18.0, ptf[1].Y);
1846
1847 ptf[0].X = 1.0;
1848 ptf[0].Y = 0.0;
1849 ptf[1].X = 0.0;
1850 ptf[1].Y = 1.0;
1851 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1852 expect(Ok, status);
1853 expectf(6.0, ptf[0].X);
1854 expectf(5.0, ptf[0].Y);
1855 expectf(5.0, ptf[1].X);
1856 expectf(6.0, ptf[1].Y);
1857
1858 ptf[0].X = 1.0;
1859 ptf[0].Y = 0.0;
1860 ptf[1].X = 0.0;
1861 ptf[1].Y = 1.0;
1862 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1863 expect(Ok, status);
1864 expectf(3.0, ptf[0].X);
1865 expectf(0.0, ptf[0].Y);
1866 expectf(0.0, ptf[1].X);
1867 expectf(3.0, ptf[1].Y);
1868
1869 ptf[0].X = 18.0;
1870 ptf[0].Y = 15.0;
1871 ptf[1].X = 15.0;
1872 ptf[1].Y = 18.0;
1873 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1874 expect(Ok, status);
1875 expectf(1.0, ptf[0].X);
1876 expectf(0.0, ptf[0].Y);
1877 expectf(0.0, ptf[1].X);
1878 expectf(1.0, ptf[1].Y);
1879
1880 ptf[0].X = 6.0;
1881 ptf[0].Y = 5.0;
1882 ptf[1].X = 5.0;
1883 ptf[1].Y = 6.0;
1884 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1885 expect(Ok, status);
1886 expectf(1.0, ptf[0].X);
1887 expectf(0.0, ptf[0].Y);
1888 expectf(0.0, ptf[1].X);
1889 expectf(1.0, ptf[1].Y);
1890
1891 ptf[0].X = 3.0;
1892 ptf[0].Y = 0.0;
1893 ptf[1].X = 0.0;
1894 ptf[1].Y = 3.0;
1895 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
1896 expect(Ok, status);
1897 expectf(1.0, ptf[0].X);
1898 expectf(0.0, ptf[0].Y);
1899 expectf(0.0, ptf[1].X);
1900 expectf(1.0, ptf[1].Y);
1901
1902 pt[0].X = 1;
1903 pt[0].Y = 0;
1904 pt[1].X = 0;
1905 pt[1].Y = 1;
1906 status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
1907 expect(Ok, status);
1908 expect(18, pt[0].X);
1909 expect(15, pt[0].Y);
1910 expect(15, pt[1].X);
1911 expect(18, pt[1].Y);
1912
1913 GdipDeleteGraphics(graphics);
1914 ReleaseDC(hwnd, hdc);
1915 }
1916
1917 static void test_get_set_clip(void)
1918 {
1919 GpStatus status;
1920 GpGraphics *graphics = NULL;
1921 HDC hdc = GetDC( hwnd );
1922 GpRegion *clip;
1923 GpRectF rect;
1924 BOOL res;
1925
1926 status = GdipCreateFromHDC(hdc, &graphics);
1927 expect(Ok, status);
1928
1929 rect.X = rect.Y = 0.0;
1930 rect.Height = rect.Width = 100.0;
1931
1932 status = GdipCreateRegionRect(&rect, &clip);
1933 expect(Ok, status);
1934
1935 /* NULL arguments */
1936 status = GdipGetClip(NULL, NULL);
1937 expect(InvalidParameter, status);
1938 status = GdipGetClip(graphics, NULL);
1939 expect(InvalidParameter, status);
1940 status = GdipGetClip(NULL, clip);
1941 expect(InvalidParameter, status);
1942
1943 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
1944 expect(InvalidParameter, status);
1945 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
1946 expect(InvalidParameter, status);
1947
1948 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
1949 expect(InvalidParameter, status);
1950 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
1951 expect(InvalidParameter, status);
1952
1953 res = FALSE;
1954 status = GdipGetClip(graphics, clip);
1955 expect(Ok, status);
1956 status = GdipIsInfiniteRegion(clip, graphics, &res);
1957 expect(Ok, status);
1958 expect(TRUE, res);
1959
1960 /* remains infinite after reset */
1961 res = FALSE;
1962 status = GdipResetClip(graphics);
1963 expect(Ok, status);
1964 status = GdipGetClip(graphics, clip);
1965 expect(Ok, status);
1966 status = GdipIsInfiniteRegion(clip, graphics, &res);
1967 expect(Ok, status);
1968 expect(TRUE, res);
1969
1970 /* set to empty and then reset to infinite */
1971 status = GdipSetEmpty(clip);
1972 expect(Ok, status);
1973 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1974 expect(Ok, status);
1975
1976 status = GdipGetClip(graphics, clip);
1977 expect(Ok, status);
1978 res = FALSE;
1979 status = GdipIsEmptyRegion(clip, graphics, &res);
1980 expect(Ok, status);
1981 expect(TRUE, res);
1982 status = GdipResetClip(graphics);
1983 expect(Ok, status);
1984 status = GdipGetClip(graphics, clip);
1985 expect(Ok, status);
1986 res = FALSE;
1987 status = GdipIsInfiniteRegion(clip, graphics, &res);
1988 expect(Ok, status);
1989 expect(TRUE, res);
1990
1991 GdipDeleteRegion(clip);
1992
1993 GdipDeleteGraphics(graphics);
1994 ReleaseDC(hwnd, hdc);
1995 }
1996
1997 static void test_isempty(void)
1998 {
1999 GpStatus status;
2000 GpGraphics *graphics = NULL;
2001 HDC hdc = GetDC( hwnd );
2002 GpRegion *clip;
2003 BOOL res;
2004
2005 status = GdipCreateFromHDC(hdc, &graphics);
2006 expect(Ok, status);
2007
2008 status = GdipCreateRegion(&clip);
2009 expect(Ok, status);
2010
2011 /* NULL */
2012 status = GdipIsClipEmpty(NULL, NULL);
2013 expect(InvalidParameter, status);
2014 status = GdipIsClipEmpty(graphics, NULL);
2015 expect(InvalidParameter, status);
2016 status = GdipIsClipEmpty(NULL, &res);
2017 expect(InvalidParameter, status);
2018
2019 /* default is infinite */
2020 res = TRUE;
2021 status = GdipIsClipEmpty(graphics, &res);
2022 expect(Ok, status);
2023 expect(FALSE, res);
2024
2025 GdipDeleteRegion(clip);
2026
2027 GdipDeleteGraphics(graphics);
2028 ReleaseDC(hwnd, hdc);
2029 }
2030
2031 static void test_clear(void)
2032 {
2033 GpStatus status;
2034
2035 status = GdipGraphicsClear(NULL, 0xdeadbeef);
2036 expect(InvalidParameter, status);
2037 }
2038
2039 static void test_textcontrast(void)
2040 {
2041 GpStatus status;
2042 HDC hdc = GetDC( hwnd );
2043 GpGraphics *graphics;
2044 UINT contrast;
2045
2046 status = GdipGetTextContrast(NULL, NULL);
2047 expect(InvalidParameter, status);
2048
2049 status = GdipCreateFromHDC(hdc, &graphics);
2050 expect(Ok, status);
2051
2052 status = GdipGetTextContrast(graphics, NULL);
2053 expect(InvalidParameter, status);
2054 status = GdipGetTextContrast(graphics, &contrast);
2055 expect(Ok, status);
2056 expect(4, contrast);
2057
2058 GdipDeleteGraphics(graphics);
2059 ReleaseDC(hwnd, hdc);
2060 }
2061
2062 static void test_GdipDrawString(void)
2063 {
2064 GpStatus status;
2065 GpGraphics *graphics = NULL;
2066 GpFont *fnt = NULL;
2067 RectF rect;
2068 GpStringFormat *format;
2069 GpBrush *brush;
2070 LOGFONTA logfont;
2071 HDC hdc = GetDC( hwnd );
2072 static const WCHAR string[] = {'T','e','s','t',0};
2073 static const PointF positions[4] = {{0,0}, {1,1}, {2,2}, {3,3}};
2074 GpMatrix *matrix;
2075
2076 memset(&logfont,0,sizeof(logfont));
2077 strcpy(logfont.lfFaceName,"Arial");
2078 logfont.lfHeight = 12;
2079 logfont.lfCharSet = DEFAULT_CHARSET;
2080
2081 status = GdipCreateFromHDC(hdc, &graphics);
2082 expect(Ok, status);
2083
2084 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
2085 if (status == NotTrueTypeFont || status == FileNotFound)
2086 {
2087 skip("Arial not installed.\n");
2088 return;
2089 }
2090 expect(Ok, status);
2091
2092 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
2093 expect(Ok, status);
2094
2095 status = GdipCreateStringFormat(0,0,&format);
2096 expect(Ok, status);
2097
2098 rect.X = 0;
2099 rect.Y = 0;
2100 rect.Width = 0;
2101 rect.Height = 12;
2102
2103 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
2104 expect(Ok, status);
2105
2106 status = GdipCreateMatrix(&matrix);
2107 expect(Ok, status);
2108
2109 status = GdipDrawDriverString(NULL, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2110 expect(InvalidParameter, status);
2111
2112 status = GdipDrawDriverString(graphics, NULL, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2113 expect(InvalidParameter, status);
2114
2115 status = GdipDrawDriverString(graphics, string, 4, NULL, brush, positions, DriverStringOptionsCmapLookup, matrix);
2116 expect(InvalidParameter, status);
2117
2118 status = GdipDrawDriverString(graphics, string, 4, fnt, NULL, positions, DriverStringOptionsCmapLookup, matrix);
2119 expect(InvalidParameter, status);
2120
2121 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, NULL, DriverStringOptionsCmapLookup, matrix);
2122 expect(InvalidParameter, status);
2123
2124 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup|0x10, matrix);
2125 expect(Ok, status);
2126
2127 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, NULL);
2128 expect(Ok, status);
2129
2130 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2131 expect(Ok, status);
2132
2133 GdipDeleteMatrix(matrix);
2134 GdipDeleteGraphics(graphics);
2135 GdipDeleteBrush(brush);
2136 GdipDeleteFont(fnt);
2137 GdipDeleteStringFormat(format);
2138
2139 ReleaseDC(hwnd, hdc);
2140 }
2141
2142 static void test_GdipGetVisibleClipBounds_screen(void)
2143 {
2144 GpStatus status;
2145 GpGraphics *graphics = NULL;
2146 HDC hdc = GetDC(0);
2147 GpRectF rectf, exp, clipr;
2148 GpRect recti;
2149
2150 ok(hdc != NULL, "Expected HDC to be initialized\n");
2151
2152 status = GdipCreateFromHDC(hdc, &graphics);
2153 expect(Ok, status);
2154 ok(graphics != NULL, "Expected graphics to be initialized\n");
2155
2156 /* no clipping rect */
2157 exp.X = 0;
2158 exp.Y = 0;
2159 exp.Width = GetDeviceCaps(hdc, HORZRES);
2160 exp.Height = GetDeviceCaps(hdc, VERTRES);
2161
2162 status = GdipGetVisibleClipBounds(graphics, &rectf);
2163 expect(Ok, status);
2164 ok(rectf.X == exp.X &&
2165 rectf.Y == exp.Y &&
2166 rectf.Width == exp.Width &&
2167 rectf.Height == exp.Height,
2168 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2169 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2170 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2171 exp.X, exp.Y, exp.Width, exp.Height);
2172
2173 /* clipping rect entirely within window */
2174 exp.X = clipr.X = 10;
2175 exp.Y = clipr.Y = 12;
2176 exp.Width = clipr.Width = 14;
2177 exp.Height = clipr.Height = 16;
2178
2179 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2180 expect(Ok, status);
2181
2182 status = GdipGetVisibleClipBounds(graphics, &rectf);
2183 expect(Ok, status);
2184 ok(rectf.X == exp.X &&
2185 rectf.Y == exp.Y &&
2186 rectf.Width == exp.Width &&
2187 rectf.Height == exp.Height,
2188 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2189 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2190 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2191 exp.X, exp.Y, exp.Width, exp.Height);
2192
2193 /* clipping rect partially outside of screen */
2194 clipr.X = -10;
2195 clipr.Y = -12;
2196 clipr.Width = 20;
2197 clipr.Height = 24;
2198
2199 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2200 expect(Ok, status);
2201
2202 exp.X = 0;
2203 exp.Y = 0;
2204 exp.Width = 10;
2205 exp.Height = 12;
2206
2207 status = GdipGetVisibleClipBounds(graphics, &rectf);
2208 expect(Ok, status);
2209 ok(rectf.X == exp.X &&
2210 rectf.Y == exp.Y &&
2211 rectf.Width == exp.Width &&
2212 rectf.Height == exp.Height,
2213 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2214 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2215 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2216 exp.X, exp.Y, exp.Width, exp.Height);
2217
2218 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2219 expect(Ok, status);
2220 ok(recti.X == exp.X &&
2221 recti.Y == exp.Y &&
2222 recti.Width == exp.Width &&
2223 recti.Height == exp.Height,
2224 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2225 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2226 recti.X, recti.Y, recti.Width, recti.Height,
2227 exp.X, exp.Y, exp.Width, exp.Height);
2228
2229 GdipDeleteGraphics(graphics);
2230 ReleaseDC(0, hdc);
2231 }
2232
2233 static void test_GdipGetVisibleClipBounds_window(void)
2234 {
2235 GpStatus status;
2236 GpGraphics *graphics = NULL;
2237 GpRectF rectf, window, exp, clipr;
2238 GpRect recti;
2239 HDC hdc;
2240 PAINTSTRUCT ps;
2241 RECT wnd_rect;
2242
2243 /* get client area size */
2244 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2245 window.X = wnd_rect.left;
2246 window.Y = wnd_rect.top;
2247 window.Width = wnd_rect.right - wnd_rect.left;
2248 window.Height = wnd_rect.bottom - wnd_rect.top;
2249
2250 hdc = BeginPaint(hwnd, &ps);
2251
2252 status = GdipCreateFromHDC(hdc, &graphics);
2253 expect(Ok, status);
2254 ok(graphics != NULL, "Expected graphics to be initialized\n");
2255
2256 status = GdipGetVisibleClipBounds(graphics, &rectf);
2257 expect(Ok, status);
2258 ok(rectf.X == window.X &&
2259 rectf.Y == window.Y &&
2260 rectf.Width == window.Width &&
2261 rectf.Height == window.Height,
2262 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2263 "the window (%0.f, %0.f, %0.f, %0.f)\n",
2264 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2265 window.X, window.Y, window.Width, window.Height);
2266
2267 /* clipping rect entirely within window */
2268 exp.X = clipr.X = 20;
2269 exp.Y = clipr.Y = 8;
2270 exp.Width = clipr.Width = 30;
2271 exp.Height = clipr.Height = 20;
2272
2273 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2274 expect(Ok, status);
2275
2276 status = GdipGetVisibleClipBounds(graphics, &rectf);
2277 expect(Ok, status);
2278 ok(rectf.X == exp.X &&
2279 rectf.Y == exp.Y &&
2280 rectf.Width == exp.Width &&
2281 rectf.Height == exp.Height,
2282 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2283 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2284 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2285 exp.X, exp.Y, exp.Width, exp.Height);
2286
2287 /* clipping rect partially outside of window */
2288 clipr.X = window.Width - 10;
2289 clipr.Y = window.Height - 15;
2290 clipr.Width = 20;
2291 clipr.Height = 30;
2292
2293 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2294 expect(Ok, status);
2295
2296 exp.X = window.Width - 10;
2297 exp.Y = window.Height - 15;
2298 exp.Width = 10;
2299 exp.Height = 15;
2300
2301 status = GdipGetVisibleClipBounds(graphics, &rectf);
2302 expect(Ok, status);
2303 ok(rectf.X == exp.X &&
2304 rectf.Y == exp.Y &&
2305 rectf.Width == exp.Width &&
2306 rectf.Height == exp.Height,
2307 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2308 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2309 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2310 exp.X, exp.Y, exp.Width, exp.Height);
2311
2312 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2313 expect(Ok, status);
2314 ok(recti.X == exp.X &&
2315 recti.Y == exp.Y &&
2316 recti.Width == exp.Width &&
2317 recti.Height == exp.Height,
2318 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2319 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2320 recti.X, recti.Y, recti.Width, recti.Height,
2321 exp.X, exp.Y, exp.Width, exp.Height);
2322
2323 GdipDeleteGraphics(graphics);
2324 EndPaint(hwnd, &ps);
2325 }
2326
2327 static void test_GdipGetVisibleClipBounds(void)
2328 {
2329 GpGraphics* graphics = NULL;
2330 GpRectF rectf;
2331 GpRect rect;
2332 HDC hdc = GetDC( hwnd );
2333 GpStatus status;
2334
2335 status = GdipCreateFromHDC(hdc, &graphics);
2336 expect(Ok, status);
2337 ok(graphics != NULL, "Expected graphics to be initialized\n");
2338
2339 /* test null parameters */
2340 status = GdipGetVisibleClipBounds(graphics, NULL);
2341 expect(InvalidParameter, status);
2342
2343 status = GdipGetVisibleClipBounds(NULL, &rectf);
2344 expect(InvalidParameter, status);
2345
2346 status = GdipGetVisibleClipBoundsI(graphics, NULL);
2347 expect(InvalidParameter, status);
2348
2349 status = GdipGetVisibleClipBoundsI(NULL, &rect);
2350 expect(InvalidParameter, status);
2351
2352 GdipDeleteGraphics(graphics);
2353 ReleaseDC(hwnd, hdc);
2354
2355 test_GdipGetVisibleClipBounds_screen();
2356 test_GdipGetVisibleClipBounds_window();
2357 }
2358
2359 static void test_fromMemoryBitmap(void)
2360 {
2361 GpStatus status;
2362 GpGraphics *graphics = NULL;
2363 GpBitmap *bitmap = NULL;
2364 BYTE bits[48] = {0};
2365 HDC hdc=NULL;
2366 COLORREF color;
2367
2368 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2369 expect(Ok, status);
2370
2371 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2372 expect(Ok, status);
2373
2374 status = GdipGraphicsClear(graphics, 0xff686868);
2375 expect(Ok, status);
2376
2377 GdipDeleteGraphics(graphics);
2378
2379 /* drawing writes to the memory provided */
2380 expect(0x68, bits[10]);
2381
2382 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2383 expect(Ok, status);
2384
2385 status = GdipGetDC(graphics, &hdc);
2386 expect(Ok, status);
2387 ok(hdc != NULL, "got NULL hdc\n");
2388
2389 color = GetPixel(hdc, 0, 0);
2390 /* The HDC is write-only, and native fills with a solid color to figure out
2391 * which pixels have changed. */
2392 todo_wine expect(0x0c0b0d, color);
2393
2394 SetPixel(hdc, 0, 0, 0x797979);
2395 SetPixel(hdc, 1, 0, 0x0c0b0d);
2396
2397 status = GdipReleaseDC(graphics, hdc);
2398 expect(Ok, status);
2399
2400 GdipDeleteGraphics(graphics);
2401
2402 expect(0x79, bits[0]);
2403 todo_wine expect(0x68, bits[3]);
2404
2405 GdipDisposeImage((GpImage*)bitmap);
2406
2407 /* We get the same kind of write-only HDC for a "normal" bitmap */
2408 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2409 expect(Ok, status);
2410
2411 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2412 expect(Ok, status);
2413
2414 status = GdipGetDC(graphics, &hdc);
2415 expect(Ok, status);
2416 ok(hdc != NULL, "got NULL hdc\n");
2417
2418 color = GetPixel(hdc, 0, 0);
2419 todo_wine expect(0x0c0b0d, color);
2420
2421 status = GdipReleaseDC(graphics, hdc);
2422 expect(Ok, status);
2423
2424 GdipDeleteGraphics(graphics);
2425
2426 GdipDisposeImage((GpImage*)bitmap);
2427 }
2428
2429 static void test_GdipIsVisiblePoint(void)
2430 {
2431 GpStatus status;
2432 GpGraphics *graphics = NULL;
2433 HDC hdc = GetDC( hwnd );
2434 REAL x, y;
2435 BOOL val;
2436
2437 ok(hdc != NULL, "Expected HDC to be initialized\n");
2438
2439 status = GdipCreateFromHDC(hdc, &graphics);
2440 expect(Ok, status);
2441 ok(graphics != NULL, "Expected graphics to be initialized\n");
2442
2443 /* null parameters */
2444 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2445 expect(InvalidParameter, status);
2446
2447 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2448 expect(InvalidParameter, status);
2449
2450 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2451 expect(InvalidParameter, status);
2452
2453 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2454 expect(InvalidParameter, status);
2455
2456 x = 0;
2457 y = 0;
2458 status = GdipIsVisiblePoint(graphics, x, y, &val);
2459 expect(Ok, status);
2460 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2461
2462 x = -10;
2463 y = 0;
2464 status = GdipIsVisiblePoint(graphics, x, y, &val);
2465 expect(Ok, status);
2466 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2467
2468 x = 0;
2469 y = -5;
2470 status = GdipIsVisiblePoint(graphics, x, y, &val);
2471 expect(Ok, status);
2472 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2473
2474 x = 1;
2475 y = 1;
2476 status = GdipIsVisiblePoint(graphics, x, y, &val);
2477 expect(Ok, status);
2478 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2479
2480 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2481 expect(Ok, status);
2482
2483 x = 1;
2484 y = 1;
2485 status = GdipIsVisiblePoint(graphics, x, y, &val);
2486 expect(Ok, status);
2487 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2488
2489 x = 15.5;
2490 y = 40.5;
2491 status = GdipIsVisiblePoint(graphics, x, y, &val);
2492 expect(Ok, status);
2493 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2494
2495 /* translate into the center of the rect */
2496 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2497
2498 x = 0;
2499 y = 0;
2500 status = GdipIsVisiblePoint(graphics, x, y, &val);
2501 expect(Ok, status);
2502 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2503
2504 x = 25;
2505 y = 40;
2506 status = GdipIsVisiblePoint(graphics, x, y, &val);
2507 expect(Ok, status);
2508 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2509
2510 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2511
2512 /* corner cases */
2513 x = 9;
2514 y = 19;
2515 status = GdipIsVisiblePoint(graphics, x, y, &val);
2516 expect(Ok, status);
2517 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2518
2519 x = 9.25;
2520 y = 19.25;
2521 status = GdipIsVisiblePoint(graphics, x, y, &val);
2522 expect(Ok, status);
2523 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2524
2525 x = 9.5;
2526 y = 19.5;
2527 status = GdipIsVisiblePoint(graphics, x, y, &val);
2528 expect(Ok, status);
2529 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2530
2531 x = 9.75;
2532 y = 19.75;
2533 status = GdipIsVisiblePoint(graphics, x, y, &val);
2534 expect(Ok, status);
2535 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2536
2537 x = 10;
2538 y = 20;
2539 status = GdipIsVisiblePoint(graphics, x, y, &val);
2540 expect(Ok, status);
2541 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2542
2543 x = 40;
2544 y = 20;
2545 status = GdipIsVisiblePoint(graphics, x, y, &val);
2546 expect(Ok, status);
2547 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2548
2549 x = 39;
2550 y = 59;
2551 status = GdipIsVisiblePoint(graphics, x, y, &val);
2552 expect(Ok, status);
2553 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2554
2555 x = 39.25;
2556 y = 59.25;
2557 status = GdipIsVisiblePoint(graphics, x, y, &val);
2558 expect(Ok, status);
2559 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2560
2561 x = 39.5;
2562 y = 39.5;
2563 status = GdipIsVisiblePoint(graphics, x, y, &val);
2564 expect(Ok, status);
2565 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2566
2567 x = 39.75;
2568 y = 59.75;
2569 status = GdipIsVisiblePoint(graphics, x, y, &val);
2570 expect(Ok, status);
2571 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2572
2573 x = 40;
2574 y = 60;
2575 status = GdipIsVisiblePoint(graphics, x, y, &val);
2576 expect(Ok, status);
2577 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2578
2579 x = 40.15;
2580 y = 60.15;
2581 status = GdipIsVisiblePoint(graphics, x, y, &val);
2582 expect(Ok, status);
2583 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2584
2585 x = 10;
2586 y = 60;
2587 status = GdipIsVisiblePoint(graphics, x, y, &val);
2588 expect(Ok, status);
2589 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2590
2591 /* integer version */
2592 x = 25;
2593 y = 30;
2594 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2595 expect(Ok, status);
2596 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2597
2598 x = 50;
2599 y = 100;
2600 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2601 expect(Ok, status);
2602 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2603
2604 GdipDeleteGraphics(graphics);
2605 ReleaseDC(hwnd, hdc);
2606 }
2607
2608 static void test_GdipIsVisibleRect(void)
2609 {
2610 GpStatus status;
2611 GpGraphics *graphics = NULL;
2612 HDC hdc = GetDC( hwnd );
2613 REAL x, y, width, height;
2614 BOOL val;
2615
2616 ok(hdc != NULL, "Expected HDC to be initialized\n");
2617
2618 status = GdipCreateFromHDC(hdc, &graphics);
2619 expect(Ok, status);
2620 ok(graphics != NULL, "Expected graphics to be initialized\n");
2621
2622 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2623 expect(InvalidParameter, status);
2624
2625 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2626 expect(InvalidParameter, status);
2627
2628 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2629 expect(InvalidParameter, status);
2630
2631 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2632 expect(InvalidParameter, status);
2633
2634 /* entirely within the visible region */
2635 x = 0; width = 10;
2636 y = 0; height = 10;
2637 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2638 expect(Ok, status);
2639 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2640
2641 /* partially outside */
2642 x = -10; width = 20;
2643 y = -10; height = 20;
2644 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2645 expect(Ok, status);
2646 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2647
2648 /* entirely outside */
2649 x = -10; width = 5;
2650 y = -10; height = 5;
2651 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2652 expect(Ok, status);
2653 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2654
2655 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2656 expect(Ok, status);
2657
2658 /* entirely within the visible region */
2659 x = 12; width = 10;
2660 y = 22; height = 10;
2661 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2662 expect(Ok, status);
2663 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2664
2665 /* partially outside */
2666 x = 35; width = 10;
2667 y = 55; height = 10;
2668 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2669 expect(Ok, status);
2670 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2671
2672 /* entirely outside */
2673 x = 45; width = 5;
2674 y = 65; height = 5;
2675 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2676 expect(Ok, status);
2677 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2678
2679 /* translate into center of clipping rect */
2680 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2681
2682 x = 0; width = 10;
2683 y = 0; height = 10;
2684 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2685 expect(Ok, status);
2686 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2687
2688 x = 25; width = 5;
2689 y = 40; height = 5;
2690 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2691 expect(Ok, status);
2692 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2693
2694 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2695
2696 /* corners entirely outside, but some intersections */
2697 x = 0; width = 70;
2698 y = 0; height = 90;
2699 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2700 expect(Ok, status);
2701 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2702
2703 x = 0; width = 70;
2704 y = 0; height = 30;
2705 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2706 expect(Ok, status);
2707 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2708
2709 x = 0; width = 30;
2710 y = 0; height = 90;
2711 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2712 expect(Ok, status);
2713 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2714
2715 /* edge cases */
2716 x = 0; width = 10;
2717 y = 20; height = 40;
2718 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2719 expect(Ok, status);
2720 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2721
2722 x = 10; width = 30;
2723 y = 0; height = 20;
2724 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2725 expect(Ok, status);
2726 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2727
2728 x = 40; width = 10;
2729 y = 20; height = 40;
2730 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2731 expect(Ok, status);
2732 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2733
2734 x = 10; width = 30;
2735 y = 60; height = 10;
2736 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2737 expect(Ok, status);
2738 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2739
2740 /* rounding tests */
2741 x = 0.4; width = 10.4;
2742 y = 20; height = 40;
2743 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2744 expect(Ok, status);
2745 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2746
2747 x = 10; width = 30;
2748 y = 0.4; height = 20.4;
2749 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2750 expect(Ok, status);
2751 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2752
2753 /* integer version */
2754 x = 0; width = 30;
2755 y = 0; height = 90;
2756 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2757 expect(Ok, status);
2758 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2759
2760 x = 12; width = 10;
2761 y = 22; height = 10;
2762 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
2763 expect(Ok, status);
2764 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2765
2766 GdipDeleteGraphics(graphics);
2767 ReleaseDC(hwnd, hdc);
2768 }
2769
2770 static void test_GdipGetNearestColor(void)
2771 {
2772 GpStatus status;
2773 GpGraphics *graphics;
2774 GpBitmap *bitmap;
2775 ARGB color = 0xdeadbeef;
2776 HDC hdc = GetDC( hwnd );
2777
2778 /* create a graphics object */
2779 ok(hdc != NULL, "Expected HDC to be initialized\n");
2780
2781 status = GdipCreateFromHDC(hdc, &graphics);
2782 expect(Ok, status);
2783 ok(graphics != NULL, "Expected graphics to be initialized\n");
2784
2785 status = GdipGetNearestColor(graphics, NULL);
2786 expect(InvalidParameter, status);
2787
2788 status = GdipGetNearestColor(NULL, &color);
2789 expect(InvalidParameter, status);
2790 GdipDeleteGraphics(graphics);
2791
2792 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
2793 expect(Ok, status);
2794 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2795 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2796 if (status == Ok)
2797 {
2798 status = GdipGetNearestColor(graphics, &color);
2799 expect(Ok, status);
2800 expect(0xdeadbeef, color);
2801 GdipDeleteGraphics(graphics);
2802 }
2803 GdipDisposeImage((GpImage*)bitmap);
2804
2805 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
2806 expect(Ok, status);
2807 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2808 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
2809 if (status == Ok)
2810 {
2811 status = GdipGetNearestColor(graphics, &color);
2812 expect(Ok, status);