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