1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2021 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
26 _adg_property_pattern(void)
28 AdgFillStyle
*fill_style
;
29 cairo_pattern_t
*valid_pattern_1
, *valid_pattern_2
;
30 const cairo_pattern_t
*pattern
;
31 cairo_pattern_t
*pattern_dup
;
33 fill_style
= ADG_FILL_STYLE(adg_ruled_fill_new());
34 valid_pattern_1
= cairo_pattern_create_rgba(0, 0, 0, 0);
35 valid_pattern_2
= cairo_pattern_create_linear(1, 2, 3, 4);
37 /* Using the public APIs */
38 adg_fill_style_set_pattern(fill_style
, valid_pattern_1
);
39 pattern
= adg_fill_style_get_pattern(fill_style
);
40 g_assert_true(pattern
== valid_pattern_1
);
42 adg_fill_style_set_pattern(fill_style
, NULL
);
43 pattern
= adg_fill_style_get_pattern(fill_style
);
44 g_assert_null(pattern
);
46 adg_fill_style_set_pattern(fill_style
, valid_pattern_2
);
47 pattern
= adg_fill_style_get_pattern(fill_style
);
48 g_assert_true(pattern
== valid_pattern_2
);
50 /* Using GObject property methods */
51 g_object_set(fill_style
, "pattern", valid_pattern_1
, NULL
);
52 g_object_get(fill_style
, "pattern", &pattern_dup
, NULL
);
53 g_assert_true(pattern_dup
== valid_pattern_1
);
54 cairo_pattern_destroy(pattern_dup
);
56 g_object_set(fill_style
, "pattern", NULL
, NULL
);
57 g_object_get(fill_style
, "pattern", &pattern_dup
, NULL
);
58 g_assert_null(pattern_dup
);
59 cairo_pattern_destroy(pattern_dup
);
61 g_object_set(fill_style
, "pattern", valid_pattern_2
, NULL
);
62 g_object_get(fill_style
, "pattern", &pattern_dup
, NULL
);
63 g_assert_true(pattern_dup
== valid_pattern_2
);
64 cairo_pattern_destroy(pattern_dup
);
66 cairo_pattern_destroy(valid_pattern_1
);
67 cairo_pattern_destroy(valid_pattern_2
);
68 g_object_unref(fill_style
);
73 main(int argc
, char *argv
[])
75 adg_test_init(&argc
, &argv
);
77 adg_test_add_object_checks("/adg/fill-style/type/object", ADG_TYPE_FILL_STYLE
);
79 g_test_add_func("/adg/fill-style/property/pattern", _adg_property_pattern
);