doc: update copyright line for 2021
[adg.git] / src / adg / tests / test-arrow.c
blob121eb87cdfb49f20d6a7bfd5e6f79251a01f058d
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.
21 #include <adg-test.h>
22 #include <adg.h>
25 static void
26 _adg_property_local_mix(void)
28 AdgArrow *arrow;
29 AdgEntity *entity;
31 /* Check default local mix method */
32 arrow = adg_arrow_new();
33 entity = (AdgEntity *) arrow;
34 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_PARENT);
35 adg_entity_destroy(entity);
37 /* Check local mix method overriding */
38 arrow = g_object_new(ADG_TYPE_ARROW, "local-mix", ADG_MIX_DISABLED, NULL);
39 entity = (AdgEntity *) arrow;
40 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_DISABLED);
41 adg_entity_destroy(entity);
43 /* Check default mix using GObject methods */
44 arrow = g_object_new(ADG_TYPE_ARROW, NULL);
45 entity = (AdgEntity *) arrow;
46 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_PARENT);
47 adg_entity_destroy(entity);
50 static void
51 _adg_property_angle(void)
53 AdgArrow *arrow;
54 gdouble valid_value, invalid_value;
55 gdouble angle;
57 valid_value = -G_PI_2;
58 invalid_value = G_PI + 1;
59 arrow = adg_arrow_new();
61 /* Using the public APIs */
62 adg_arrow_set_angle(arrow, valid_value);
63 angle = adg_arrow_get_angle(arrow);
64 adg_assert_isapprox(angle, valid_value);
66 adg_arrow_set_angle(arrow, -G_PI);
67 angle = adg_arrow_get_angle(arrow);
68 adg_assert_isapprox(angle, G_PI);
70 adg_arrow_set_angle(arrow, invalid_value);
71 angle = adg_arrow_get_angle(arrow);
72 g_assert_cmpfloat(angle, !=, invalid_value);
74 /* Using GObject property methods */
75 g_object_set(arrow, "angle", valid_value, NULL);
76 g_object_get(arrow, "angle", &angle, NULL);
77 adg_assert_isapprox(angle, valid_value);
79 g_object_set(arrow, "angle", -G_PI, NULL);
80 g_object_get(arrow, "angle", &angle, NULL);
81 adg_assert_isapprox(angle, G_PI);
83 g_object_set(arrow, "angle", invalid_value, NULL);
84 g_object_get(arrow, "angle", &angle, NULL);
85 g_assert_cmpfloat(angle, !=, invalid_value);
87 adg_entity_destroy((AdgEntity *) arrow);
91 int
92 main(int argc, char *argv[])
94 adg_test_init(&argc, &argv);
96 adg_test_add_object_checks("/adg/arrow/type/object", ADG_TYPE_ARROW);
97 adg_test_add_entity_checks("/adg/arrow/type/entity", ADG_TYPE_ARROW);
99 g_test_add_func("/adg/arrow/property/local-mix", _adg_property_local_mix);
100 g_test_add_func("/adg/arrow/property/angle", _adg_property_angle);
102 return g_test_run();