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