1
/*
2
 * Copyright © 2010 Red Hat Inc.
3
 *
4
 * Permission to use, copy, modify, distribute, and sell this software
5
 * and its documentation for any purpose is hereby granted without
6
 * fee, provided that the above copyright notice appear in all copies
7
 * and that both that copyright notice and this permission notice
8
 * appear in supporting documentation, and that the name of
9
 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. Red Hat, Inc. makes no representations about the
12
 * suitability of this software for any purpose.  It is provided "as
13
 * is" without express or implied warranty.
14
 *
15
 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 *
23
 * Author: Benjamin Otte <otte@redhat.com>
24
 */
25

            
26
/*
27
 * WHAT THIS TEST DOES
28
 *
29
 * This test tests that for all public APIs Cairo behaves correct, consistent
30
 * and most of all doesn't crash. It does this by calling all APIs that take
31
 * surfaces or contexts and calling them on specially prepared arguments that
32
 * should fail when called on this function.
33
 *
34
 * ADDING NEW FUNCTIONS
35
 *
36
 * You need (for adding the function cairo_surface_foo):
37
 * 1) A surface_test_func_t named test_cairo_surface_foo that gets passed the
38
 *    prepared surface and has the job of calling the function and checking
39
 *    the return value (if one exists) for correctness. The top of this file
40
 *    contains all these shim functions.
41
 * 2) Knowledge if the function behaves like a setter or like a getter. A 
42
 *    setter should set an error status on the surface, a getter does not
43
 *    modify the function.
44
 * 3) Knowledge if the function only works for a specific surface type and for
45
 *    which one.
46
 * 4) An entry in the tests array using the TEST() macro. It takes as arguments:
47
 *    - The function name
48
 *    - TRUE if the function modifies the surface, FALSE otherwise
49
 *    - the surface type for which the function is valid or -1 if it is valid
50
 *      for all surface types.
51
 *
52
 * FIXING FAILURES
53
 *
54
 * The test will dump failures notices into the api-special-cases.log file (when 
55
 * it doesn't crash). These should be pretty self-explanatory. Usually it is 
56
 * enough to just add a new check to the function it complained about.
57
 */
58

            
59
#include "config.h"
60

            
61
#include <assert.h>
62
#include <limits.h>
63

            
64
#include "cairo-test.h"
65

            
66
#if CAIRO_HAS_PDF_SURFACE
67
#include <cairo-pdf.h>
68
#endif
69
#if CAIRO_HAS_PS_SURFACE
70
#include <cairo-ps.h>
71
#endif
72
#if CAIRO_HAS_QUARTZ_SURFACE
73
#define Cursor QuartzCursor
74
#include <cairo-quartz.h>
75
#undef Cursor
76
#endif
77
#if CAIRO_HAS_SVG_SURFACE
78
#include <cairo-svg.h>
79
#endif
80
#if CAIRO_HAS_TEE_SURFACE
81
#include <cairo-tee.h>
82
#endif
83
#if CAIRO_HAS_XCB_SURFACE
84
#include <cairo-xcb.h>
85
#endif
86
#if CAIRO_HAS_XLIB_SURFACE
87
#define Cursor XCursor
88
#include <cairo-xlib.h>
89
#undef Cursor
90
#endif
91

            
92
#define surface_has_type(surface,type) (cairo_surface_get_type (surface) == (type))
93

            
94
typedef cairo_test_status_t (* surface_test_func_t) (cairo_surface_t *surface);
95
typedef cairo_test_status_t (* context_test_func_t) (cairo_t *cr);
96

            
97
static cairo_test_status_t
98
11
test_cairo_reference (cairo_t *cr)
99
{
100
11
    cairo_destroy (cairo_reference (cr));
101

            
102
11
    return CAIRO_TEST_SUCCESS;
103
}
104

            
105
static cairo_test_status_t
106
11
test_cairo_get_reference_count (cairo_t *cr)
107
{
108
11
    unsigned int refcount = cairo_get_reference_count (cr);
109
11
    if (refcount > 0)
110
6
        return CAIRO_TEST_SUCCESS;
111
    /* inert error context have a refcount of 0 */
112
5
    return cairo_status (cr) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
113
}
114

            
115
static cairo_test_status_t
116
11
test_cairo_set_user_data (cairo_t *cr)
117
{
118
    static cairo_user_data_key_t key;
119
    cairo_status_t status;
120

            
121
11
    status = cairo_set_user_data (cr, &key, &key, NULL);
122
11
    if (status == CAIRO_STATUS_NO_MEMORY)
123
        return CAIRO_TEST_NO_MEMORY;
124
11
    else if (status)
125
5
        return CAIRO_TEST_SUCCESS;
126

            
127
6
    if (cairo_get_user_data (cr, &key) != &key)
128
        return CAIRO_TEST_ERROR;
129

            
130
6
    return CAIRO_TEST_SUCCESS;
131
}
132

            
133
static cairo_test_status_t
134
11
test_cairo_save (cairo_t *cr)
135
{
136
11
    cairo_save (cr);
137
11
    cairo_restore (cr);
138

            
139
11
    return CAIRO_TEST_SUCCESS;
140
}
141

            
142
static cairo_test_status_t
143
11
test_cairo_push_group (cairo_t *cr)
144
{
145
    cairo_pattern_t *pattern;
146
    cairo_status_t status;
147

            
148
11
    cairo_push_group (cr);
149
11
    pattern = cairo_pop_group (cr);
150
11
    status = cairo_pattern_status (pattern);
151
11
    cairo_pattern_destroy (pattern);
152

            
153
11
    return status == CAIRO_STATUS_SUCCESS || status == cairo_status (cr) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
154
}
155

            
156
static cairo_test_status_t
157
11
test_cairo_push_group_with_content (cairo_t *cr)
158
{
159
11
    cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
160
11
    cairo_pop_group_to_source (cr);
161

            
162
11
    return CAIRO_TEST_SUCCESS;
163
}
164

            
165
static cairo_test_status_t
166
11
test_cairo_set_operator (cairo_t *cr)
167
{
168
11
    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
169

            
170
11
    return CAIRO_TEST_SUCCESS;
171
}
172

            
173
static cairo_test_status_t
174
11
test_cairo_set_source (cairo_t *cr)
175
{
176
11
    cairo_pattern_t *source = cairo_pattern_create_rgb (0, 0, 0);
177
11
    cairo_set_source (cr, source);
178
11
    cairo_pattern_destroy (source);
179

            
180
11
    return CAIRO_TEST_SUCCESS;
181
}
182

            
183
static cairo_test_status_t
184
11
test_cairo_set_source_rgb (cairo_t *cr)
185
{
186
11
    cairo_set_source_rgb (cr, 0, 0, 0);
187

            
188
11
    return CAIRO_TEST_SUCCESS;
189
}
190

            
191
static cairo_test_status_t
192
11
test_cairo_set_source_rgba (cairo_t *cr)
193
{
194
11
    cairo_set_source_rgba (cr, 0, 0, 0, 1);
195

            
196
11
    return CAIRO_TEST_SUCCESS;
197
}
198

            
199
static cairo_test_status_t
200
11
test_cairo_set_source_surface (cairo_t *cr)
201
{
202
11
    cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
203
11
    cairo_set_source_surface (cr, surface, 0, 0);
204
11
    cairo_surface_destroy (surface);
205

            
206
11
    return CAIRO_TEST_SUCCESS;
207
}
208

            
209
static cairo_test_status_t
210
11
test_cairo_set_tolerance (cairo_t *cr)
211
{
212
11
    cairo_set_tolerance (cr, 42);
213

            
214
11
    return CAIRO_TEST_SUCCESS;
215
}
216

            
217
static cairo_test_status_t
218
11
test_cairo_set_antialias (cairo_t *cr)
219
{
220
11
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_BEST);
221

            
222
11
    return CAIRO_TEST_SUCCESS;
223
}
224

            
225
static cairo_test_status_t
226
11
test_cairo_set_fill_rule (cairo_t *cr)
227
{
228
11
    cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
229

            
230
11
    return CAIRO_TEST_SUCCESS;
231
}
232

            
233
static cairo_test_status_t
234
11
test_cairo_set_line_width (cairo_t *cr)
235
{
236
11
    cairo_set_line_width (cr, 42);
237

            
238
11
    return CAIRO_TEST_SUCCESS;
239
}
240

            
241
static cairo_test_status_t
242
11
test_cairo_set_line_cap (cairo_t *cr)
243
{
244
11
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
245

            
246
11
    return CAIRO_TEST_SUCCESS;
247
}
248

            
249
static cairo_test_status_t
250
11
test_cairo_set_line_join (cairo_t *cr)
251
{
252
11
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
253

            
254
11
    return CAIRO_TEST_SUCCESS;
255
}
256

            
257
static cairo_test_status_t
258
11
test_cairo_set_dash (cairo_t *cr)
259
{
260
11
    cairo_set_dash (cr, NULL, 0, 0);
261

            
262
11
    return CAIRO_TEST_SUCCESS;
263
}
264

            
265
static cairo_test_status_t
266
11
test_cairo_set_miter_limit (cairo_t *cr)
267
{
268
11
    cairo_set_miter_limit (cr, 2);
269

            
270
11
    return CAIRO_TEST_SUCCESS;
271
}
272

            
273
static cairo_test_status_t
274
11
test_cairo_translate (cairo_t *cr)
275
{
276
11
    cairo_translate (cr, 2, 2);
277

            
278
11
    return CAIRO_TEST_SUCCESS;
279
}
280

            
281
static cairo_test_status_t
282
11
test_cairo_scale (cairo_t *cr)
283
{
284
11
    cairo_scale (cr, 2, 2);
285

            
286
11
    return CAIRO_TEST_SUCCESS;
287
}
288

            
289
static cairo_test_status_t
290
11
test_cairo_rotate (cairo_t *cr)
291
{
292
11
    cairo_rotate (cr, 2);
293

            
294
11
    return CAIRO_TEST_SUCCESS;
295
}
296

            
297
static cairo_test_status_t
298
11
test_cairo_transform (cairo_t *cr)
299
{
300
    cairo_matrix_t matrix;
301

            
302
11
    cairo_matrix_init_translate (&matrix, 1, 1);
303
11
    cairo_transform (cr, &matrix);
304

            
305
11
    return CAIRO_TEST_SUCCESS;
306
}
307

            
308
static cairo_test_status_t
309
11
test_cairo_set_matrix (cairo_t *cr)
310
{
311
    cairo_matrix_t matrix;
312

            
313
11
    cairo_matrix_init_translate (&matrix, 1, 1);
314
11
    cairo_set_matrix (cr, &matrix);
315

            
316
11
    return CAIRO_TEST_SUCCESS;
317
}
318

            
319
static cairo_test_status_t
320
11
test_cairo_identity_matrix (cairo_t *cr)
321
{
322
11
    cairo_identity_matrix (cr);
323

            
324
11
    return CAIRO_TEST_SUCCESS;
325
}
326

            
327
static cairo_test_status_t
328
11
test_cairo_user_to_device (cairo_t *cr)
329
{
330
11
    double x = 42, y = 42;
331

            
332
11
    cairo_user_to_device (cr, &x, &y);
333

            
334
11
    return CAIRO_TEST_SUCCESS;
335
}
336

            
337
static cairo_test_status_t
338
11
test_cairo_user_to_device_distance (cairo_t *cr)
339
{
340
11
    double x = 42, y = 42;
341

            
342
11
    cairo_user_to_device_distance (cr, &x, &y);
343

            
344
11
    return CAIRO_TEST_SUCCESS;
345
}
346

            
347
static cairo_test_status_t
348
11
test_cairo_device_to_user (cairo_t *cr)
349
{
350
11
    double x = 42, y = 42;
351

            
352
11
    cairo_device_to_user (cr, &x, &y);
353

            
354
11
    return CAIRO_TEST_SUCCESS;
355
}
356

            
357
static cairo_test_status_t
358
11
test_cairo_device_to_user_distance (cairo_t *cr)
359
{
360
11
    double x = 42, y = 42;
361

            
362
11
    cairo_device_to_user_distance (cr, &x, &y);
363

            
364
11
    return CAIRO_TEST_SUCCESS;
365
}
366

            
367
static cairo_test_status_t
368
11
test_cairo_new_path (cairo_t *cr)
369
{
370
11
    cairo_new_path (cr);
371

            
372
11
    return CAIRO_TEST_SUCCESS;
373
}
374

            
375
static cairo_test_status_t
376
11
test_cairo_move_to (cairo_t *cr)
377
{
378
11
    cairo_move_to (cr, 2, 2);
379

            
380
11
    return CAIRO_TEST_SUCCESS;
381
}
382

            
383
static cairo_test_status_t
384
11
test_cairo_new_sub_path (cairo_t *cr)
385
{
386
11
    cairo_new_sub_path (cr);
387

            
388
11
    return CAIRO_TEST_SUCCESS;
389
}
390

            
391
static cairo_test_status_t
392
11
test_cairo_line_to (cairo_t *cr)
393
{
394
11
    cairo_line_to (cr, 2, 2);
395

            
396
11
    return CAIRO_TEST_SUCCESS;
397
}
398

            
399
static cairo_test_status_t
400
11
test_cairo_curve_to (cairo_t *cr)
401
{
402
11
    cairo_curve_to (cr, 2, 2, 3, 3, 4, 4);
403

            
404
11
    return CAIRO_TEST_SUCCESS;
405
}
406

            
407
static cairo_test_status_t
408
11
test_cairo_arc (cairo_t *cr)
409
{
410
11
    cairo_arc (cr, 2, 2, 3, 0, 2 * M_PI);
411

            
412
11
    return CAIRO_TEST_SUCCESS;
413
}
414

            
415
static cairo_test_status_t
416
11
test_cairo_arc_negative (cairo_t *cr)
417
{
418
11
    cairo_arc_negative (cr, 2, 2, 3, 0, 2 * M_PI);
419

            
420
11
    return CAIRO_TEST_SUCCESS;
421
}
422

            
423
static cairo_test_status_t
424
11
test_cairo_rel_move_to (cairo_t *cr)
425
{
426
11
    cairo_rel_move_to (cr, 2, 2);
427

            
428
11
    return CAIRO_TEST_SUCCESS;
429
}
430

            
431
static cairo_test_status_t
432
11
test_cairo_rel_line_to (cairo_t *cr)
433
{
434
11
    cairo_rel_line_to (cr, 2, 2);
435

            
436
11
    return CAIRO_TEST_SUCCESS;
437
}
438

            
439
static cairo_test_status_t
440
11
test_cairo_rel_curve_to (cairo_t *cr)
441
{
442
11
    cairo_rel_curve_to (cr, 2, 2, 3, 3, 4, 4);
443

            
444
11
    return CAIRO_TEST_SUCCESS;
445
}
446

            
447
static cairo_test_status_t
448
11
test_cairo_rectangle (cairo_t *cr)
449
{
450
11
    cairo_rectangle (cr, 2, 2, 3, 3);
451

            
452
11
    return CAIRO_TEST_SUCCESS;
453
}
454

            
455
static cairo_test_status_t
456
11
test_cairo_close_path (cairo_t *cr)
457
{
458
11
    cairo_close_path (cr);
459

            
460
11
    return CAIRO_TEST_SUCCESS;
461
}
462

            
463
static cairo_test_status_t
464
11
test_cairo_path_extents (cairo_t *cr)
465
{
466
    double x1, y1, x2, y2;
467
11
    cairo_path_extents (cr, &x1, &y1, &x2, &y2);
468

            
469
11
    return CAIRO_TEST_SUCCESS;
470
}
471

            
472
static cairo_test_status_t
473
11
test_cairo_paint (cairo_t *cr)
474
{
475
11
    cairo_paint (cr);
476

            
477
11
    return CAIRO_TEST_SUCCESS;
478
}
479

            
480
static cairo_test_status_t
481
11
test_cairo_paint_with_alpha (cairo_t *cr)
482
{
483
11
    cairo_paint_with_alpha (cr, 0.5);
484

            
485
11
    return CAIRO_TEST_SUCCESS;
486
}
487

            
488
static cairo_test_status_t
489
11
test_cairo_mask (cairo_t *cr)
490
{
491
    cairo_pattern_t *pattern;
492

            
493
11
    pattern = cairo_pattern_create_rgb (0.5, 0.5, 0.5);
494
11
    cairo_mask (cr, pattern);
495

            
496
11
    cairo_pattern_destroy (pattern);
497
11
    return CAIRO_TEST_SUCCESS;
498
}
499

            
500
static cairo_test_status_t
501
11
test_cairo_mask_surface (cairo_t *cr)
502
{
503
    cairo_surface_t *surface;
504

            
505
11
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
506
11
    cairo_mask_surface (cr, surface, 0, 0);
507

            
508
11
    cairo_surface_destroy (surface);
509
11
    return CAIRO_TEST_SUCCESS;
510
}
511

            
512
static cairo_test_status_t
513
11
test_cairo_stroke (cairo_t *cr)
514
{
515
11
    cairo_stroke (cr);
516

            
517
11
    return CAIRO_TEST_SUCCESS;
518
}
519

            
520
static cairo_test_status_t
521
11
test_cairo_stroke_preserve (cairo_t *cr)
522
{
523
11
    cairo_stroke_preserve (cr);
524

            
525
11
    return CAIRO_TEST_SUCCESS;
526
}
527

            
528
static cairo_test_status_t
529
11
test_cairo_fill (cairo_t *cr)
530
{
531
11
    cairo_fill (cr);
532

            
533
11
    return CAIRO_TEST_SUCCESS;
534
}
535

            
536
static cairo_test_status_t
537
11
test_cairo_fill_preserve (cairo_t *cr)
538
{
539
11
    cairo_fill_preserve (cr);
540

            
541
11
    return CAIRO_TEST_SUCCESS;
542
}
543

            
544
static cairo_test_status_t
545
11
test_cairo_copy_page (cairo_t *cr)
546
{
547
11
    cairo_copy_page (cr);
548

            
549
11
    return CAIRO_TEST_SUCCESS;
550
}
551

            
552
static cairo_test_status_t
553
11
test_cairo_show_page (cairo_t *cr)
554
{
555
11
    cairo_show_page (cr);
556

            
557
11
    return CAIRO_TEST_SUCCESS;
558
}
559

            
560
static cairo_test_status_t
561
11
test_cairo_in_stroke (cairo_t *cr)
562
{
563
11
    cairo_in_stroke (cr, 1, 1);
564

            
565
11
    return CAIRO_TEST_SUCCESS;
566
}
567

            
568
static cairo_test_status_t
569
11
test_cairo_in_fill (cairo_t *cr)
570
{
571
11
    cairo_in_fill (cr, 1, 1);
572

            
573
11
    return CAIRO_TEST_SUCCESS;
574
}
575

            
576
static cairo_test_status_t
577
11
test_cairo_in_clip (cairo_t *cr)
578
{
579
11
    cairo_in_clip (cr, 1, 1);
580

            
581
11
    return CAIRO_TEST_SUCCESS;
582
}
583

            
584
static cairo_test_status_t
585
11
test_cairo_stroke_extents (cairo_t *cr)
586
{
587
    double x1, y1, x2, y2;
588
11
    cairo_stroke_extents (cr, &x1, &y1, &x2, &y2);
589

            
590
11
    return CAIRO_TEST_SUCCESS;
591
}
592

            
593
static cairo_test_status_t
594
11
test_cairo_fill_extents (cairo_t *cr)
595
{
596
    double x1, y1, x2, y2;
597
11
    cairo_fill_extents (cr, &x1, &y1, &x2, &y2);
598

            
599
11
    return CAIRO_TEST_SUCCESS;
600
}
601

            
602
static cairo_test_status_t
603
11
test_cairo_reset_clip (cairo_t *cr)
604
{
605
11
    cairo_reset_clip (cr);
606

            
607
11
    return CAIRO_TEST_SUCCESS;
608
}
609

            
610
static cairo_test_status_t
611
11
test_cairo_clip (cairo_t *cr)
612
{
613
11
    cairo_clip (cr);
614

            
615
11
    return CAIRO_TEST_SUCCESS;
616
}
617

            
618
static cairo_test_status_t
619
11
test_cairo_clip_preserve (cairo_t *cr)
620
{
621
11
    cairo_clip_preserve (cr);
622

            
623
11
    return CAIRO_TEST_SUCCESS;
624
}
625

            
626
static cairo_test_status_t
627
11
test_cairo_clip_extents (cairo_t *cr)
628
{
629
    double x1, y1, x2, y2;
630
11
    cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
631

            
632
11
    return CAIRO_TEST_SUCCESS;
633
}
634

            
635
static cairo_test_status_t
636
11
test_cairo_copy_clip_rectangle_list (cairo_t *cr)
637
{
638
11
    cairo_rectangle_list_destroy (cairo_copy_clip_rectangle_list (cr));
639

            
640
11
    return CAIRO_TEST_SUCCESS;
641
}
642

            
643
static cairo_test_status_t
644
11
test_cairo_select_font_face (cairo_t *cr)
645
{
646
11
    cairo_select_font_face (cr, "Arial", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
647

            
648
11
    return CAIRO_TEST_SUCCESS;
649
}
650

            
651
static cairo_test_status_t
652
11
test_cairo_set_font_size (cairo_t *cr)
653
{
654
11
    cairo_set_font_size (cr, 42);
655

            
656
11
    return CAIRO_TEST_SUCCESS;
657
}
658

            
659
static cairo_test_status_t
660
11
test_cairo_set_font_matrix (cairo_t *cr)
661
{
662
    cairo_matrix_t matrix;
663

            
664
11
    cairo_matrix_init_translate (&matrix, 1, 1);
665
11
    cairo_set_font_matrix (cr, &matrix);
666

            
667
11
    return CAIRO_TEST_SUCCESS;
668
}
669

            
670
static cairo_test_status_t
671
11
test_cairo_get_font_matrix (cairo_t *cr)
672
{
673
    cairo_matrix_t matrix;
674

            
675
11
    cairo_get_font_matrix (cr, &matrix);
676

            
677
11
    return CAIRO_TEST_SUCCESS;
678
}
679

            
680
static cairo_test_status_t
681
11
test_cairo_set_font_options (cairo_t *cr)
682
{
683
11
    cairo_font_options_t *opt = cairo_font_options_create ();
684
11
    cairo_set_font_options (cr, opt);
685
11
    cairo_font_options_destroy (opt);
686

            
687
11
    return CAIRO_TEST_SUCCESS;
688
}
689

            
690
static cairo_test_status_t
691
11
test_cairo_get_font_options (cairo_t *cr)
692
{
693
11
    cairo_font_options_t *opt = cairo_font_options_create ();
694
11
    cairo_get_font_options (cr, opt);
695
11
    cairo_font_options_destroy (opt);
696

            
697
11
    return CAIRO_TEST_SUCCESS;
698
}
699

            
700
static cairo_test_status_t
701
11
test_cairo_set_font_face (cairo_t *cr)
702
{
703
11
    cairo_set_font_face (cr, cairo_get_font_face (cr));
704

            
705
11
    return CAIRO_TEST_SUCCESS;
706
}
707

            
708
static cairo_test_status_t
709
11
test_cairo_set_scaled_font (cairo_t *cr)
710
{
711
11
    cairo_set_scaled_font (cr, cairo_get_scaled_font (cr));
712

            
713
11
    return CAIRO_TEST_SUCCESS;
714
}
715

            
716
static cairo_test_status_t
717
11
test_cairo_show_text (cairo_t *cr)
718
{
719
11
    cairo_show_text (cr, "Cairo");
720

            
721
11
    return CAIRO_TEST_SUCCESS;
722
}
723

            
724
static cairo_test_status_t
725
11
test_cairo_show_glyphs (cairo_t *cr)
726
{
727
    cairo_glyph_t glyph;
728

            
729
11
    glyph.index = 65;
730
11
    glyph.x = 0;
731
11
    glyph.y = 0;
732

            
733
11
    cairo_show_glyphs (cr, &glyph, 1);
734

            
735
11
    return CAIRO_TEST_SUCCESS;
736
}
737

            
738
static cairo_test_status_t
739
11
test_cairo_show_text_glyphs (cairo_t *cr)
740
{
741
    cairo_glyph_t glyph;
742
    cairo_text_cluster_t cluster;
743

            
744
11
    glyph.index = 65;
745
11
    glyph.x = 0;
746
11
    glyph.y = 0;
747

            
748
11
    cluster.num_bytes = 1;
749
11
    cluster.num_glyphs = 1;
750

            
751
11
    cairo_show_text_glyphs (cr, "a", -1, &glyph, 1, &cluster, 1, 0);
752

            
753
11
    return CAIRO_TEST_SUCCESS;
754
}
755

            
756
static cairo_test_status_t
757
11
test_cairo_text_path (cairo_t *cr)
758
{
759
11
    cairo_text_path (cr, "Cairo");
760

            
761
11
    return CAIRO_TEST_SUCCESS;
762
}
763

            
764
static cairo_test_status_t
765
11
test_cairo_glyph_path (cairo_t *cr)
766
{
767
    cairo_glyph_t glyph;
768

            
769
11
    glyph.index = 65;
770
11
    glyph.x = 0;
771
11
    glyph.y = 0;
772

            
773
11
    cairo_glyph_path (cr, &glyph, 1);
774

            
775
11
    return CAIRO_TEST_SUCCESS;
776
}
777

            
778
static cairo_test_status_t
779
11
test_cairo_text_extents (cairo_t *cr)
780
{
781
    cairo_text_extents_t extents;
782

            
783
11
    cairo_text_extents (cr, "Cairo", &extents);
784

            
785
11
    return CAIRO_TEST_SUCCESS;
786
}
787

            
788
static cairo_test_status_t
789
11
test_cairo_glyph_extents (cairo_t *cr)
790
{
791
    cairo_glyph_t glyph;
792
    cairo_text_extents_t extents;
793

            
794
11
    glyph.index = 65;
795
11
    glyph.x = 0;
796
11
    glyph.y = 0;
797

            
798
11
    cairo_glyph_extents (cr, &glyph, 1, &extents);
799

            
800
11
    return CAIRO_TEST_SUCCESS;
801
}
802

            
803
static cairo_test_status_t
804
11
test_cairo_font_extents (cairo_t *cr)
805
{
806
    cairo_font_extents_t extents;
807

            
808
11
    cairo_font_extents (cr, &extents);
809

            
810
11
    return CAIRO_TEST_SUCCESS;
811
}
812

            
813
static cairo_test_status_t
814
11
test_cairo_get_operator (cairo_t *cr)
815
{
816
11
    cairo_get_operator (cr);
817

            
818
11
    return CAIRO_TEST_SUCCESS;
819
}
820

            
821
static cairo_test_status_t
822
11
test_cairo_get_source (cairo_t *cr)
823
{
824
11
    cairo_get_source (cr);
825

            
826
11
    return CAIRO_TEST_SUCCESS;
827
}
828

            
829
static cairo_test_status_t
830
11
test_cairo_get_tolerance (cairo_t *cr)
831
{
832
11
    cairo_get_tolerance (cr);
833

            
834
11
    return CAIRO_TEST_SUCCESS;
835
}
836

            
837
static cairo_test_status_t
838
11
test_cairo_get_antialias (cairo_t *cr)
839
{
840
11
    cairo_get_antialias (cr);
841

            
842
11
    return CAIRO_TEST_SUCCESS;
843
}
844

            
845
static cairo_test_status_t
846
11
test_cairo_has_current_point (cairo_t *cr)
847
{
848
11
    cairo_has_current_point (cr);
849

            
850
11
    return CAIRO_TEST_SUCCESS;
851
}
852

            
853
static cairo_test_status_t
854
11
test_cairo_get_current_point (cairo_t *cr)
855
{
856
    double x, y;
857

            
858
11
    cairo_get_current_point (cr, &x, &y);
859

            
860
11
    return CAIRO_TEST_SUCCESS;
861
}
862

            
863
static cairo_test_status_t
864
11
test_cairo_get_fill_rule (cairo_t *cr)
865
{
866
11
    cairo_get_fill_rule (cr);
867

            
868
11
    return CAIRO_TEST_SUCCESS;
869
}
870

            
871
static cairo_test_status_t
872
11
test_cairo_get_line_width (cairo_t *cr)
873
{
874
11
    cairo_get_line_width (cr);
875

            
876
11
    return CAIRO_TEST_SUCCESS;
877
}
878

            
879
static cairo_test_status_t
880
11
test_cairo_get_line_cap (cairo_t *cr)
881
{
882
11
    cairo_get_line_cap (cr);
883

            
884
11
    return CAIRO_TEST_SUCCESS;
885
}
886

            
887
static cairo_test_status_t
888
11
test_cairo_get_line_join (cairo_t *cr)
889
{
890
11
    cairo_get_line_join (cr);
891

            
892
11
    return CAIRO_TEST_SUCCESS;
893
}
894

            
895
static cairo_test_status_t
896
11
test_cairo_get_miter_limit (cairo_t *cr)
897
{
898
11
    cairo_get_miter_limit (cr);
899

            
900
11
    return CAIRO_TEST_SUCCESS;
901
}
902

            
903
static cairo_test_status_t
904
11
test_cairo_get_dash_count (cairo_t *cr)
905
{
906
11
    cairo_get_dash_count (cr);
907

            
908
11
    return CAIRO_TEST_SUCCESS;
909
}
910

            
911
static cairo_test_status_t
912
11
test_cairo_get_dash (cairo_t *cr)
913
{
914
    double dashes[42];
915
    double offset;
916

            
917
11
    cairo_get_dash (cr, &dashes[0], &offset);
918

            
919
11
    return CAIRO_TEST_SUCCESS;
920
}
921

            
922
static cairo_test_status_t
923
11
test_cairo_get_matrix (cairo_t *cr)
924
{
925
    cairo_matrix_t matrix;
926

            
927
11
    cairo_get_matrix (cr, &matrix);
928

            
929
11
    return CAIRO_TEST_SUCCESS;
930
}
931

            
932
static cairo_test_status_t
933
11
test_cairo_get_target (cairo_t *cr)
934
{
935
11
    cairo_get_target (cr);
936

            
937
11
    return CAIRO_TEST_SUCCESS;
938
}
939

            
940
static cairo_test_status_t
941
11
test_cairo_get_group_target (cairo_t *cr)
942
{
943
11
    cairo_get_group_target (cr);
944

            
945
11
    return CAIRO_TEST_SUCCESS;
946
}
947

            
948
static cairo_test_status_t
949
11
test_cairo_copy_path (cairo_t *cr)
950
{
951
11
    cairo_path_destroy (cairo_copy_path (cr));
952

            
953
11
    return CAIRO_TEST_SUCCESS;
954
}
955

            
956
static cairo_test_status_t
957
11
test_cairo_copy_path_flat (cairo_t *cr)
958
{
959
11
    cairo_path_destroy (cairo_copy_path_flat (cr));
960

            
961
11
    return CAIRO_TEST_SUCCESS;
962
}
963

            
964
static cairo_test_status_t
965
11
test_cairo_append_path (cairo_t *cr)
966
{
967
    cairo_path_data_t data[3];
968
    cairo_path_t path;
969

            
970
11
    path.status = CAIRO_STATUS_SUCCESS;
971
11
    path.data = &data[0];
972
11
    path.num_data = ARRAY_LENGTH(data);
973

            
974
11
    data[0].header.type = CAIRO_PATH_MOVE_TO;
975
11
    data[0].header.length = 2;
976
11
    data[1].point.x = 1;
977
11
    data[1].point.y = 2;
978
11
    data[2].header.type = CAIRO_PATH_CLOSE_PATH;
979
11
    data[2].header.length = 1;
980

            
981
11
    cairo_append_path (cr, &path);
982

            
983
11
    return CAIRO_TEST_SUCCESS;
984
}
985

            
986
static cairo_test_status_t
987
4
test_cairo_surface_create_similar (cairo_surface_t *surface)
988
{
989
    cairo_surface_t *similar;
990
    
991
4
    similar = cairo_surface_create_similar (surface, CAIRO_CONTENT_ALPHA, 100, 100);
992
    
993
4
    cairo_surface_destroy (similar);
994
4
    return CAIRO_TEST_SUCCESS;
995
}
996

            
997
static cairo_test_status_t
998
4
test_cairo_surface_create_for_rectangle (cairo_surface_t *surface)
999
{
    cairo_surface_t *similar;
4
    similar = cairo_surface_create_for_rectangle (surface, 1, 1, 8, 8);
4
    cairo_surface_destroy (similar);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_reference (cairo_surface_t *surface)
{
4
    cairo_surface_destroy (cairo_surface_reference (surface));
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_finish (cairo_surface_t *surface)
{
4
    cairo_surface_finish (surface);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_get_device (cairo_surface_t *surface)
{
4
    /* cairo_device_t *device = */cairo_surface_get_device (surface);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_get_reference_count (cairo_surface_t *surface)
{
4
    unsigned int refcount = cairo_surface_get_reference_count (surface);
4
    if (refcount > 0)
3
        return CAIRO_TEST_SUCCESS;
    /* inert error surfaces have a refcount of 0 */
1
    return cairo_surface_status (surface) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
4
test_cairo_surface_status (cairo_surface_t *surface)
{
4
    cairo_status_t status = cairo_surface_status (surface);
4
    return status < CAIRO_STATUS_LAST_STATUS ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
4
test_cairo_surface_get_type (cairo_surface_t *surface)
{
4
    /* cairo_surface_type_t type = */cairo_surface_get_type (surface);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_get_content (cairo_surface_t *surface)
{
4
    cairo_content_t content = cairo_surface_get_content (surface);
4
    switch (content) {
4
    case CAIRO_CONTENT_COLOR:
    case CAIRO_CONTENT_ALPHA:
    case CAIRO_CONTENT_COLOR_ALPHA:
4
        return CAIRO_TEST_SUCCESS;
    default:
        return CAIRO_TEST_ERROR;
    }
}
static cairo_test_status_t
4
test_cairo_surface_set_user_data (cairo_surface_t *surface)
{
    static cairo_user_data_key_t key;
    cairo_status_t status;
4
    status = cairo_surface_set_user_data (surface, &key, &key, NULL);
4
    if (status == CAIRO_STATUS_NO_MEMORY)
        return CAIRO_TEST_NO_MEMORY;
4
    else if (status)
1
        return CAIRO_TEST_SUCCESS;
3
    if (cairo_surface_get_user_data (surface, &key) != &key)
        return CAIRO_TEST_ERROR;
3
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_set_mime_data (cairo_surface_t *surface)
{
4
    const char *mimetype = "text/x-uri";
4
    const char *data = "https://www.cairographics.org";
    cairo_status_t status;
4
    status = cairo_surface_set_mime_data (surface,
                                          mimetype,
                                          (const unsigned char *) data,
					  strlen (data),
                                          NULL, NULL);
4
    return status ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
4
test_cairo_surface_get_mime_data (cairo_surface_t *surface)
{
4
    const char *mimetype = "text/x-uri";
    const unsigned char *data;
    unsigned long length;
4
    cairo_surface_get_mime_data (surface, mimetype, &data, &length);
4
    return data == NULL && length == 0 ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
4
test_cairo_surface_get_font_options (cairo_surface_t *surface)
{
    cairo_font_options_t *options;
    cairo_status_t status;
4
    options = cairo_font_options_create ();
4
    if (likely (!cairo_font_options_status (options)))
4
        cairo_surface_get_font_options (surface, options);
4
    status = cairo_font_options_status (options);
4
    cairo_font_options_destroy (options);
4
    return status ? CAIRO_TEST_ERROR : CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_flush (cairo_surface_t *surface)
{
4
    cairo_surface_flush (surface);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_mark_dirty (cairo_surface_t *surface)
{
4
    cairo_surface_mark_dirty (surface);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface)
{
4
    cairo_surface_mark_dirty_rectangle (surface, 1, 1, 8, 8);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_set_device_offset (cairo_surface_t *surface)
{
4
    cairo_surface_set_device_offset (surface, 5, 5);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_get_device_offset (cairo_surface_t *surface)
{
    double x, y;
4
    cairo_surface_get_device_offset (surface, &x, &y);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_set_fallback_resolution (cairo_surface_t *surface)
{
4
    cairo_surface_set_fallback_resolution (surface, 42, 42);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_get_fallback_resolution (cairo_surface_t *surface)
{
    double x, y;
4
    cairo_surface_get_fallback_resolution (surface, &x, &y);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_copy_page (cairo_surface_t *surface)
{
4
    cairo_surface_copy_page (surface);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_show_page (cairo_surface_t *surface)
{
4
    cairo_surface_show_page (surface);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_surface_has_show_text_glyphs (cairo_surface_t *surface)
{
4
    cairo_surface_has_show_text_glyphs (surface);
4
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
4
test_cairo_image_surface_get_data (cairo_surface_t *surface)
{
4
    unsigned char *data = cairo_image_surface_get_data (surface);
4
    return data == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
4
test_cairo_image_surface_get_format (cairo_surface_t *surface)
{
4
    cairo_format_t format = cairo_image_surface_get_format (surface);
4
    return format == CAIRO_FORMAT_INVALID || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
4
test_cairo_image_surface_get_width (cairo_surface_t *surface)
{
4
    unsigned int width = cairo_image_surface_get_width (surface);
4
    return width == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
4
test_cairo_image_surface_get_height (cairo_surface_t *surface)
{
4
    unsigned int height = cairo_image_surface_get_height (surface);
4
    return height == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
4
test_cairo_image_surface_get_stride (cairo_surface_t *surface)
{
4
    unsigned int stride = cairo_image_surface_get_stride (surface);
4
    return stride == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
#if CAIRO_HAS_PNG_FUNCTIONS
static cairo_test_status_t
4
test_cairo_surface_write_to_png (cairo_surface_t *surface)
{
    cairo_status_t status;
4
    status = cairo_surface_write_to_png (surface, "/this/file/will/definitely/not/exist.png");
4
    return status ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_status_t
write_func_that_always_fails (void *closure, const unsigned char *data, unsigned int length)
{
    return CAIRO_STATUS_WRITE_ERROR;
}
static cairo_test_status_t
4
test_cairo_surface_write_to_png_stream (cairo_surface_t *surface)
{
    cairo_status_t status;
4
    status = cairo_surface_write_to_png_stream (surface,
                                                write_func_that_always_fails,
                                                NULL);
4
    return status && status != CAIRO_STATUS_WRITE_ERROR ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
#endif /* CAIRO_HAS_PNG_FUNCTIONS */
static cairo_test_status_t
7
test_cairo_recording_surface_ink_extents (cairo_surface_t *surface)
{
    double x, y, w, h;
7
    cairo_recording_surface_ink_extents (surface, &x, &y, &w, &h);
7
    return x == 0 && y == 0 && w == 0 && h == 0 ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
#if CAIRO_HAS_TEE_SURFACE
static cairo_test_status_t
7
test_cairo_tee_surface_add (cairo_surface_t *surface)
{
7
    cairo_surface_t *image = cairo_image_surface_create (CAIRO_FORMAT_A8, 10, 10);
7
    cairo_tee_surface_add (surface, image);
7
    cairo_surface_destroy (image);
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_tee_surface_remove (cairo_surface_t *surface)
{
7
    cairo_surface_t *image = cairo_image_surface_create (CAIRO_FORMAT_A8, 10, 10);
7
    cairo_tee_surface_remove (surface, image);
7
    cairo_surface_destroy (image);
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_tee_surface_index (cairo_surface_t *surface)
{
    cairo_surface_t *master;
    cairo_status_t status;
7
    master = cairo_tee_surface_index (surface, 0);
7
    status = cairo_surface_status (master);
7
    cairo_surface_destroy (master);
7
    return status ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
#endif /* CAIRO_HAS_TEE_SURFACE */
#if CAIRO_HAS_PDF_SURFACE
static cairo_test_status_t
7
test_cairo_pdf_surface_restrict_to_version (cairo_surface_t *surface)
{
7
    cairo_pdf_surface_restrict_to_version (surface, CAIRO_PDF_VERSION_1_4);
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_pdf_surface_set_size (cairo_surface_t *surface)
{
7
    cairo_pdf_surface_set_size (surface, 5, 5);
7
    return CAIRO_TEST_SUCCESS;
}
#endif /* CAIRO_HAS_PDF_SURFACE */
#if CAIRO_HAS_PS_SURFACE
static cairo_test_status_t
7
test_cairo_ps_surface_restrict_to_level (cairo_surface_t *surface)
{
7
    cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2);
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_ps_surface_set_eps (cairo_surface_t *surface)
{
7
    cairo_ps_surface_set_eps (surface, TRUE);
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_ps_surface_get_eps (cairo_surface_t *surface)
{
7
    cairo_bool_t eps = cairo_ps_surface_get_eps (surface);
7
    return eps ? CAIRO_TEST_ERROR : CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_ps_surface_set_size (cairo_surface_t *surface)
{
7
    cairo_ps_surface_set_size (surface, 5, 5);
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_ps_surface_dsc_comment (cairo_surface_t *surface)
{
7
    cairo_ps_surface_dsc_comment (surface, "54, 74, 90, 2010");
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface)
{
7
    cairo_ps_surface_dsc_begin_setup (surface);
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface)
{
7
    cairo_ps_surface_dsc_begin_page_setup (surface);
7
    return CAIRO_TEST_SUCCESS;
}
#endif /* CAIRO_HAS_PS_SURFACE */
#if CAIRO_HAS_QUARTZ_SURFACE
static cairo_test_status_t
test_cairo_quartz_surface_get_cg_context (cairo_surface_t *surface)
{
    CGContextRef context = cairo_quartz_surface_get_cg_context (surface);
    return context == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_QUARTZ) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
#endif /* CAIRO_HAS_QUARTZ_SURFACE */
#if CAIRO_HAS_SVG_SURFACE
static cairo_test_status_t
7
test_cairo_svg_surface_restrict_to_version (cairo_surface_t *surface)
{
7
    cairo_svg_surface_restrict_to_version (surface, CAIRO_SVG_VERSION_1_1);
7
    return CAIRO_TEST_SUCCESS;
}
#endif /* CAIRO_HAS_SVG_SURFACE */
#if CAIRO_HAS_XCB_SURFACE
static cairo_test_status_t
7
test_cairo_xcb_surface_set_size (cairo_surface_t *surface)
{
7
    cairo_xcb_surface_set_size (surface, 5, 5);
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_xcb_surface_set_drawable (cairo_surface_t *surface)
{
7
    cairo_xcb_surface_set_drawable (surface, 0, 5, 5);
7
    return CAIRO_TEST_SUCCESS;
}
#endif
#if CAIRO_HAS_XLIB_SURFACE
static cairo_test_status_t
7
test_cairo_xlib_surface_set_size (cairo_surface_t *surface)
{
7
    cairo_xlib_surface_set_size (surface, 5, 5);
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_xlib_surface_set_drawable (cairo_surface_t *surface)
{
7
    cairo_xlib_surface_set_drawable (surface, 0, 5, 5);
7
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
7
test_cairo_xlib_surface_get_display (cairo_surface_t *surface)
{
7
    Display *display = cairo_xlib_surface_get_display (surface);
7
    return display == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
7
test_cairo_xlib_surface_get_screen (cairo_surface_t *surface)
{
7
    Screen *screen = cairo_xlib_surface_get_screen (surface);
7
    return screen == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
7
test_cairo_xlib_surface_get_visual (cairo_surface_t *surface)
{
7
    Visual *visual = cairo_xlib_surface_get_visual (surface);
7
    return visual == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
7
test_cairo_xlib_surface_get_drawable (cairo_surface_t *surface)
{
7
    Drawable drawable = cairo_xlib_surface_get_drawable (surface);
7
    return drawable == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
7
test_cairo_xlib_surface_get_depth (cairo_surface_t *surface)
{
7
    int depth = cairo_xlib_surface_get_depth (surface);
7
    return depth == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
7
test_cairo_xlib_surface_get_width (cairo_surface_t *surface)
{
7
    int width = cairo_xlib_surface_get_width (surface);
7
    return width == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
static cairo_test_status_t
7
test_cairo_xlib_surface_get_height (cairo_surface_t *surface)
{
7
    int height = cairo_xlib_surface_get_height (surface);
7
    return height == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
}
#endif
#define TEST(name) { #name, test_ ## name }
struct {
    const char *name;
    context_test_func_t func;
} context_tests[] = {
    TEST (cairo_reference),
    TEST (cairo_get_reference_count),
    TEST (cairo_set_user_data),
    TEST (cairo_save),
    TEST (cairo_push_group),
    TEST (cairo_push_group_with_content),
    TEST (cairo_set_operator),
    TEST (cairo_set_source),
    TEST (cairo_set_source_rgb),
    TEST (cairo_set_source_rgba),
    TEST (cairo_set_source_surface),
    TEST (cairo_set_tolerance),
    TEST (cairo_set_antialias),
    TEST (cairo_set_fill_rule),
    TEST (cairo_set_line_width),
    TEST (cairo_set_line_cap),
    TEST (cairo_set_line_join),
    TEST (cairo_set_dash),
    TEST (cairo_set_miter_limit),
    TEST (cairo_translate),
    TEST (cairo_scale),
    TEST (cairo_rotate),
    TEST (cairo_transform),
    TEST (cairo_set_matrix),
    TEST (cairo_identity_matrix),
    TEST (cairo_user_to_device),
    TEST (cairo_user_to_device_distance),
    TEST (cairo_device_to_user),
    TEST (cairo_device_to_user_distance),
    TEST (cairo_new_path),
    TEST (cairo_move_to),
    TEST (cairo_new_sub_path),
    TEST (cairo_line_to),
    TEST (cairo_curve_to),
    TEST (cairo_arc),
    TEST (cairo_arc_negative),
    TEST (cairo_rel_move_to),
    TEST (cairo_rel_line_to),
    TEST (cairo_rel_curve_to),
    TEST (cairo_rectangle),
    TEST (cairo_close_path),
    TEST (cairo_path_extents),
    TEST (cairo_paint),
    TEST (cairo_paint_with_alpha),
    TEST (cairo_mask),
    TEST (cairo_mask_surface),
    TEST (cairo_stroke),
    TEST (cairo_stroke_preserve),
    TEST (cairo_fill),
    TEST (cairo_fill_preserve),
    TEST (cairo_copy_page),
    TEST (cairo_show_page),
    TEST (cairo_in_stroke),
    TEST (cairo_in_fill),
    TEST (cairo_in_clip),
    TEST (cairo_stroke_extents),
    TEST (cairo_fill_extents),
    TEST (cairo_reset_clip),
    TEST (cairo_clip),
    TEST (cairo_clip_preserve),
    TEST (cairo_clip_extents),
    TEST (cairo_copy_clip_rectangle_list),
    TEST (cairo_select_font_face),
    TEST (cairo_set_font_size),
    TEST (cairo_set_font_matrix),
    TEST (cairo_get_font_matrix),
    TEST (cairo_set_font_options),
    TEST (cairo_get_font_options),
    TEST (cairo_set_font_face),
    TEST (cairo_set_scaled_font),
    TEST (cairo_show_text),
    TEST (cairo_show_glyphs),
    TEST (cairo_show_text_glyphs),
    TEST (cairo_text_path),
    TEST (cairo_glyph_path),
    TEST (cairo_text_extents),
    TEST (cairo_glyph_extents),
    TEST (cairo_font_extents),
    TEST (cairo_get_operator),
    TEST (cairo_get_source),
    TEST (cairo_get_tolerance),
    TEST (cairo_get_antialias),
    TEST (cairo_has_current_point),
    TEST (cairo_get_current_point),
    TEST (cairo_get_fill_rule),
    TEST (cairo_get_line_width),
    TEST (cairo_get_line_cap),
    TEST (cairo_get_line_join),
    TEST (cairo_get_miter_limit),
    TEST (cairo_get_dash_count),
    TEST (cairo_get_dash),
    TEST (cairo_get_matrix),
    TEST (cairo_get_target),
    TEST (cairo_get_group_target),
    TEST (cairo_copy_path),
    TEST (cairo_copy_path_flat),
    TEST (cairo_append_path),
};
#undef TEST
#define TEST(name, surface_type, sets_status) { #name, test_ ## name, surface_type, sets_status }
struct {
    const char *name;
    surface_test_func_t func;
    int surface_type; /* cairo_surface_type_t or -1 */
    cairo_bool_t modifies_surface;
} surface_tests[] = {
    TEST (cairo_surface_create_similar, -1, FALSE),
    TEST (cairo_surface_create_for_rectangle, -1, FALSE),
    TEST (cairo_surface_reference, -1, FALSE),
    TEST (cairo_surface_finish, -1, TRUE),
    TEST (cairo_surface_get_device, -1, FALSE),
    TEST (cairo_surface_get_reference_count, -1, FALSE),
    TEST (cairo_surface_status, -1, FALSE),
    TEST (cairo_surface_get_type, -1, FALSE),
    TEST (cairo_surface_get_content, -1, FALSE),
    TEST (cairo_surface_set_user_data, -1, FALSE),
    TEST (cairo_surface_set_mime_data, -1, TRUE),
    TEST (cairo_surface_get_mime_data, -1, FALSE),
    TEST (cairo_surface_get_font_options, -1, FALSE),
    TEST (cairo_surface_flush, -1, TRUE),
    TEST (cairo_surface_mark_dirty, -1, TRUE),
    TEST (cairo_surface_mark_dirty_rectangle, -1, TRUE),
    TEST (cairo_surface_set_device_offset, -1, TRUE),
    TEST (cairo_surface_get_device_offset, -1, FALSE),
    TEST (cairo_surface_set_fallback_resolution, -1, TRUE),
    TEST (cairo_surface_get_fallback_resolution, -1, FALSE),
    TEST (cairo_surface_copy_page, -1, TRUE),
    TEST (cairo_surface_show_page, -1, TRUE),
    TEST (cairo_surface_has_show_text_glyphs, -1, FALSE),
    TEST (cairo_image_surface_get_data, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
    TEST (cairo_image_surface_get_format, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
    TEST (cairo_image_surface_get_width, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
    TEST (cairo_image_surface_get_height, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
    TEST (cairo_image_surface_get_stride, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
#if CAIRO_HAS_PNG_FUNCTIONS
    TEST (cairo_surface_write_to_png, -1, FALSE),
    TEST (cairo_surface_write_to_png_stream, -1, FALSE),
#endif
    TEST (cairo_recording_surface_ink_extents, CAIRO_SURFACE_TYPE_RECORDING, FALSE),
#if CAIRO_HAS_TEE_SURFACE
    TEST (cairo_tee_surface_add, CAIRO_SURFACE_TYPE_TEE, TRUE),
    TEST (cairo_tee_surface_remove, CAIRO_SURFACE_TYPE_TEE, TRUE),
    TEST (cairo_tee_surface_index, CAIRO_SURFACE_TYPE_TEE, FALSE),
#endif
#if CAIRO_HAS_PDF_SURFACE
    TEST (cairo_pdf_surface_restrict_to_version, CAIRO_SURFACE_TYPE_PDF, TRUE),
    TEST (cairo_pdf_surface_set_size, CAIRO_SURFACE_TYPE_PDF, TRUE),
#endif
#if CAIRO_HAS_PS_SURFACE
    TEST (cairo_ps_surface_restrict_to_level, CAIRO_SURFACE_TYPE_PS, TRUE),
    TEST (cairo_ps_surface_set_eps, CAIRO_SURFACE_TYPE_PS, TRUE),
    TEST (cairo_ps_surface_get_eps, CAIRO_SURFACE_TYPE_PS, FALSE),
    TEST (cairo_ps_surface_set_size, CAIRO_SURFACE_TYPE_PS, TRUE),
    TEST (cairo_ps_surface_dsc_comment, CAIRO_SURFACE_TYPE_PS, TRUE),
    TEST (cairo_ps_surface_dsc_begin_setup, CAIRO_SURFACE_TYPE_PS, TRUE),
    TEST (cairo_ps_surface_dsc_begin_page_setup, CAIRO_SURFACE_TYPE_PS, TRUE),
#endif
#if CAIRO_HAS_QUARTZ_SURFACE
    TEST (cairo_quartz_surface_get_cg_context, CAIRO_SURFACE_TYPE_QUARTZ, FALSE),
#endif
#if CAIRO_HAS_SVG_SURFACE
    TEST (cairo_svg_surface_restrict_to_version, CAIRO_SURFACE_TYPE_SVG, TRUE),
#endif
#if CAIRO_HAS_XCB_SURFACE
    TEST (cairo_xcb_surface_set_size, CAIRO_SURFACE_TYPE_XCB, TRUE),
    TEST (cairo_xcb_surface_set_drawable, CAIRO_SURFACE_TYPE_XCB, TRUE),
#endif
#if CAIRO_HAS_XLIB_SURFACE
    TEST (cairo_xlib_surface_set_size, CAIRO_SURFACE_TYPE_XLIB, TRUE),
    TEST (cairo_xlib_surface_set_drawable, CAIRO_SURFACE_TYPE_XLIB, TRUE),
    TEST (cairo_xlib_surface_get_display, CAIRO_SURFACE_TYPE_XLIB, FALSE),
    TEST (cairo_xlib_surface_get_drawable, CAIRO_SURFACE_TYPE_XLIB, FALSE),
    TEST (cairo_xlib_surface_get_screen, CAIRO_SURFACE_TYPE_XLIB, FALSE),
    TEST (cairo_xlib_surface_get_visual, CAIRO_SURFACE_TYPE_XLIB, FALSE),
    TEST (cairo_xlib_surface_get_depth, CAIRO_SURFACE_TYPE_XLIB, FALSE),
    TEST (cairo_xlib_surface_get_width, CAIRO_SURFACE_TYPE_XLIB, FALSE),
    TEST (cairo_xlib_surface_get_height, CAIRO_SURFACE_TYPE_XLIB, FALSE),
#endif
};
static cairo_test_status_t
1
preamble (cairo_test_context_t *ctx)
{
    cairo_surface_t *surface;
    cairo_t *cr;
    cairo_test_status_t test_status;
    cairo_status_t status_before, status_after;
    unsigned int i;
    /* Test an error surface */
56
    for (i = 0; i < ARRAY_LENGTH (surface_tests); i++) {
55
        surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX);
55
        status_before = cairo_surface_status (surface);
55
        assert (status_before);
55
        test_status = surface_tests[i].func (surface);
55
        status_after = cairo_surface_status (surface);
55
        cairo_surface_destroy (surface);
55
        if (test_status != CAIRO_TEST_SUCCESS) {
            cairo_test_log (ctx,
                            "Failed test %s with %d\n",
                            surface_tests[i].name, (int) test_status);
            return test_status;
        }
55
        if (status_before != status_after) {
            cairo_test_log (ctx,
                            "Failed test %s: Modified surface status from %u (%s) to %u (%s)\n",
                            surface_tests[i].name,
                            status_before, cairo_status_to_string (status_before),
                            status_after, cairo_status_to_string (status_after));
            return CAIRO_TEST_ERROR;
        }
    }
    /* Test an error context */
98
    for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
97
        cr = cairo_create (NULL);
97
        status_before = cairo_status (cr);
97
        assert (status_before);
97
        test_status = context_tests[i].func (cr);
97
        status_after = cairo_status (cr);
97
        cairo_destroy (cr);
97
        if (test_status != CAIRO_TEST_SUCCESS) {
            cairo_test_log (ctx,
                            "Failed test %s with %d\n",
                            context_tests[i].name, (int) test_status);
            return test_status;
        }
97
        if (status_before != status_after) {
            cairo_test_log (ctx,
                            "Failed test %s: Modified context status from %u (%s) to %u (%s)\n",
                            context_tests[i].name,
                            status_before, cairo_status_to_string (status_before),
                            status_after, cairo_status_to_string (status_after));
            return CAIRO_TEST_ERROR;
        }
    }
    /* Test a context for an error surface */
98
    for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
97
        surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX);
97
        cr = cairo_create (surface);
97
        cairo_surface_destroy (surface);
97
        status_before = cairo_status (cr);
97
        assert (status_before);
97
        test_status = context_tests[i].func (cr);
97
        status_after = cairo_status (cr);
97
        cairo_destroy (cr);
97
        if (test_status != CAIRO_TEST_SUCCESS) {
            cairo_test_log (ctx,
                            "Failed test %s with %d\n",
                            context_tests[i].name, (int) test_status);
            return test_status;
        }
97
        if (status_before != status_after) {
            cairo_test_log (ctx,
                            "Failed test %s: Modified context status from %u (%s) to %u (%s)\n",
                            context_tests[i].name,
                            status_before, cairo_status_to_string (status_before),
                            status_after, cairo_status_to_string (status_after));
            return CAIRO_TEST_ERROR;
        }
    }
1
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
873
test_context (const cairo_test_context_t *ctx, cairo_t *cr, const char *name, unsigned int i)
{
    cairo_test_status_t test_status;
    cairo_status_t status_before, status_after;
    /* Make sure that there is a current point */
873
    cairo_move_to (cr, 0, 0);
873
    status_before = cairo_status (cr);
873
    test_status = context_tests[i].func (cr);
873
    status_after = cairo_status (cr);
873
    if (test_status != CAIRO_TEST_SUCCESS) {
        cairo_test_log (ctx,
                        "Failed test %s on %s with %d\n",
                        context_tests[i].name, name, (int) test_status);
        return test_status;
    }
873
    if (status_after != CAIRO_STATUS_SURFACE_FINISHED && status_before != status_after) {
        cairo_test_log (ctx,
                        "Failed test %s on %s: Modified context status from %u (%s) to %u (%s)\n",
                        context_tests[i].name, name,
                        status_before, cairo_status_to_string (status_before),
                        status_after, cairo_status_to_string (status_after));
        return CAIRO_TEST_ERROR;
    }
873
    return CAIRO_TEST_SUCCESS;
}
static cairo_test_status_t
3
draw (cairo_t *cr, int width, int height)
{
3
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
    cairo_surface_t *similar, *target;
    cairo_test_status_t test_status;
    cairo_status_t status;
    cairo_t *cr2;
    unsigned int i;
3
    target = cairo_get_target (cr);
    /* Test a finished similar surface */
168
    for (i = 0; i < ARRAY_LENGTH (surface_tests); i++) {
165
        similar = cairo_surface_create_similar (target,
                                                cairo_surface_get_content (target),
                                                10, 10);
165
        cairo_surface_finish (similar);
165
        test_status = surface_tests[i].func (similar);
165
        status = cairo_surface_status (similar);
165
        cairo_surface_destroy (similar);
165
        if (test_status != CAIRO_TEST_SUCCESS) {
            cairo_test_log (ctx,
                            "Failed test %s with %d\n",
                            surface_tests[i].name, (int) test_status);
            return test_status;
        }
165
        if (surface_tests[i].modifies_surface &&
72
            strcmp (surface_tests[i].name, "cairo_surface_finish") &&
69
            strcmp (surface_tests[i].name, "cairo_surface_flush") &&
            status != CAIRO_STATUS_SURFACE_FINISHED) {
            cairo_test_log (ctx,
                            "Failed test %s: Finished surface not set into error state\n",
                            surface_tests[i].name);
            return CAIRO_TEST_ERROR;
        }
    }
    /* Test a context for a finished similar surface */
294
    for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
291
        similar = cairo_surface_create_similar (target,
                                                cairo_surface_get_content (target),
                                                10, 10);
291
        cairo_surface_finish (similar);
291
        cr2 = cairo_create (similar);
291
        test_status = test_context (ctx, cr2, "finished surface", i);
291
        cairo_surface_destroy (similar);
291
        cairo_destroy (cr2);
291
        if (test_status != CAIRO_TEST_SUCCESS)
            return test_status;
    }
    /* Test a context for a similar surface finished later */
294
    for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
291
        similar = cairo_surface_create_similar (target,
                                                cairo_surface_get_content (target),
                                                10, 10);
291
        cr2 = cairo_create (similar);
291
        cairo_surface_finish (similar);
291
        test_status = test_context (ctx, cr2, "finished surface after create", i);
291
        cairo_surface_destroy (similar);
291
        cairo_destroy (cr2);
291
        if (test_status != CAIRO_TEST_SUCCESS)
            return test_status;
    }
    /* Test a context for a similar surface finished later with a path */
294
    for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
291
        similar = cairo_surface_create_similar (target,
                                                cairo_surface_get_content (target),
                                                10, 10);
291
        cr2 = cairo_create (similar);
291
        cairo_rectangle (cr2, 2, 2, 4, 4);
291
        cairo_surface_finish (similar);
291
        test_status = test_context (ctx, cr2, "finished surface with path", i);
291
        cairo_surface_destroy (similar);
291
        cairo_destroy (cr2);
291
        if (test_status != CAIRO_TEST_SUCCESS)
            return test_status;
    }
    /* Test a normal surface for functions that have the wrong type */
168
    for (i = 0; i < ARRAY_LENGTH (surface_tests); i++) {
        cairo_status_t desired_status;
165
        if (surface_tests[i].surface_type == -1)
75
            continue;
90
        similar = cairo_surface_create_similar (target,
                                                cairo_surface_get_content (target),
                                                10, 10);
90
        if (cairo_surface_get_type (similar) == (cairo_surface_type_t) surface_tests[i].surface_type) {
15
            cairo_surface_destroy (similar);
15
            continue;
        }
75
        test_status = surface_tests[i].func (similar);
75
        status = cairo_surface_status (similar);
75
        cairo_surface_destroy (similar);
75
        if (test_status != CAIRO_TEST_SUCCESS) {
            cairo_test_log (ctx,
                            "Failed test %s with %d\n",
                            surface_tests[i].name, (int) test_status);
            return test_status;
        }
75
        desired_status = surface_tests[i].modifies_surface ? CAIRO_STATUS_SURFACE_TYPE_MISMATCH : CAIRO_STATUS_SUCCESS;
75
        if (status != desired_status) {
            cairo_test_log (ctx,
                            "Failed test %s: Surface status should be %u (%s), but is %u (%s)\n",
                            surface_tests[i].name,
                            desired_status, cairo_status_to_string (desired_status),
                            status, cairo_status_to_string (status));
            return CAIRO_TEST_ERROR;
        }
    }
    /* 565-compatible gray background */
3
    cairo_set_source_rgb (cr, 0.51613, 0.55555, 0.51613);
3
    cairo_paint (cr);
3
    return CAIRO_TEST_SUCCESS;
}
1
CAIRO_TEST (api_special_cases,
	    "Check surface functions properly handle wrong surface arguments",
	    "api", /* keywords */
	    NULL, /* requirements */
	    10, 10,
	    preamble, draw)