1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2015 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.
25 static cairo_path_data_t data
[] = {
26 { .header
= { CPML_MOVE
, 2 } },
27 { .point
= { 1, 2 } },
28 { .header
= { CPML_LINE
, 2 } },
31 static cairo_path_t path
= {
39 _cpml_method_primitive_deep_dup(void)
41 CpmlSegment segment
= { &path
, data
, G_N_ELEMENTS(data
) };
42 CpmlPrimitive primitive
, *dup_primitive
;
44 g_assert_null(cpml_primitive_deep_dup(NULL
));
46 /* Test full duplication */
47 primitive
.segment
= &segment
;
48 primitive
.org
= &data
[1];
49 primitive
.data
= &data
[2];
51 dup_primitive
= cpml_primitive_deep_dup(&primitive
);
52 g_assert_nonnull(dup_primitive
);
53 g_assert_nonnull(dup_primitive
->segment
);
54 g_assert_nonnull(dup_primitive
->org
);
55 g_assert_nonnull(dup_primitive
->data
);
56 g_assert_false(dup_primitive
->segment
== primitive
.segment
);
57 g_assert_false(dup_primitive
->org
== primitive
.org
);
58 g_assert_false(dup_primitive
->data
== primitive
.data
);
59 g_free(dup_primitive
);
61 /* Test duplication with NULL fields */
62 primitive
.segment
= NULL
;
64 dup_primitive
= cpml_primitive_deep_dup(&primitive
);
65 g_assert_nonnull(dup_primitive
);
66 g_assert_null(dup_primitive
->segment
);
67 g_assert_nonnull(dup_primitive
->org
);
68 g_assert_nonnull(dup_primitive
->data
);
69 g_free(dup_primitive
);
73 dup_primitive
= cpml_primitive_deep_dup(&primitive
);
74 g_assert_nonnull(dup_primitive
);
75 g_assert_null(dup_primitive
->segment
);
76 g_assert_null(dup_primitive
->org
);
77 g_assert_nonnull(dup_primitive
->data
);
78 g_free(dup_primitive
);
80 primitive
.data
= NULL
;
82 dup_primitive
= cpml_primitive_deep_dup(&primitive
);
83 g_assert_nonnull(dup_primitive
);
84 g_assert_null(dup_primitive
->segment
);
85 g_assert_null(dup_primitive
->org
);
86 g_assert_null(dup_primitive
->data
);
87 g_free(dup_primitive
);
91 _cpml_method_segment_deep_dup(void)
93 CpmlSegment segment
, *dup_segment
;
95 g_assert_null(cpml_segment_deep_dup(NULL
));
97 /* Test full duplication */
100 segment
.num_data
= G_N_ELEMENTS(data
);
102 dup_segment
= cpml_segment_deep_dup(&segment
);
103 g_assert_nonnull(dup_segment
);
104 g_assert_null(dup_segment
->path
);
105 g_assert_nonnull(dup_segment
->data
);
106 g_assert_false(dup_segment
->data
== segment
.data
);
107 g_assert_cmpint(dup_segment
->num_data
, ==, segment
.num_data
);
110 /* Test duplication with NULL fields */
113 dup_segment
= cpml_segment_deep_dup(&segment
);
114 g_assert_nonnull(dup_segment
);
115 g_assert_null(dup_segment
->path
);
116 g_assert_nonnull(dup_segment
->data
);
117 g_assert_false(dup_segment
->data
== segment
.data
);
118 g_assert_cmpint(dup_segment
->num_data
, ==, segment
.num_data
);
123 dup_segment
= cpml_segment_deep_dup(&segment
);
124 g_assert_nonnull(dup_segment
);
125 g_assert_cmpint(dup_segment
->num_data
, ==, 0);
126 g_assert_null(dup_segment
->data
);
130 segment
.num_data
= 0;
132 dup_segment
= cpml_segment_deep_dup(&segment
);
133 g_assert_nonnull(dup_segment
);
134 g_assert_cmpint(dup_segment
->num_data
, ==, 0);
135 g_assert_null(dup_segment
->data
);
141 main(int argc
, char *argv
[])
143 adg_test_init(&argc
, &argv
);
145 adg_test_add_boxed_checks("/cpml/pair/type/boxed", CPML_TYPE_PAIR
, g_new0(CpmlPair
, 1));
147 adg_test_add_boxed_checks("/cpml/primitive/type/boxed", CPML_TYPE_PRIMITIVE
, g_new0(CpmlPrimitive
, 1));
148 g_test_add_func("/cpml/primitive/method/deep-dup", _cpml_method_primitive_deep_dup
);
150 adg_test_add_boxed_checks("/cpml/segment/type/boxed", CPML_TYPE_SEGMENT
, g_new0(CpmlSegment
, 1));
151 g_test_add_func("/cpml/segment/method/deep-dup", _cpml_method_segment_deep_dup
);
153 adg_test_add_enum_checks("/cpml/cpml-primitive-type/type/enum", CPML_TYPE_PRIMITIVE_TYPE
);
155 adg_test_add_enum_checks("/cpml/curve-offset-algorithm/type/enum", CPML_TYPE_CURVE_OFFSET_ALGORITHM
);