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