doc: update copyright line for 2019
[adg.git] / src / adg / tests / test-color-style.c
blobcfb7f6d61f7f876057121da30721ba89ca53b728
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2019 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_alpha(void)
28 AdgColorStyle *color_style;
29 gdouble valid_alpha1, valid_alpha2, invalid_alpha, alpha;
31 color_style = adg_color_style_new();
32 valid_alpha1 = 1;
33 valid_alpha2 = 0;
34 invalid_alpha = -1;
36 /* Using the public APIs */
37 adg_color_style_set_alpha(color_style, valid_alpha1);
38 alpha = adg_color_style_get_alpha(color_style);
39 adg_assert_isapprox(alpha, valid_alpha1);
41 adg_color_style_set_alpha(color_style, invalid_alpha);
42 alpha = adg_color_style_get_alpha(color_style);
43 adg_assert_isapprox(alpha, valid_alpha1);
45 adg_color_style_set_alpha(color_style, valid_alpha2);
46 alpha = adg_color_style_get_alpha(color_style);
47 adg_assert_isapprox(alpha, valid_alpha2);
49 /* Using GObject property methods */
50 g_object_set(color_style, "alpha", valid_alpha1, NULL);
51 g_object_get(color_style, "alpha", &alpha, NULL);
52 adg_assert_isapprox(alpha, valid_alpha1);
54 g_object_set(color_style, "alpha", invalid_alpha, NULL);
55 g_object_get(color_style, "alpha", &alpha, NULL);
56 adg_assert_isapprox(alpha, valid_alpha1);
58 g_object_set(color_style, "alpha", valid_alpha2, NULL);
59 g_object_get(color_style, "alpha", &alpha, NULL);
60 adg_assert_isapprox(alpha, valid_alpha2);
62 g_object_unref(color_style);
65 static void
66 _adg_property_blue(void)
68 AdgColorStyle *color_style;
69 gdouble valid_blue1, valid_blue2, invalid_blue, blue;
71 color_style = adg_color_style_new();
72 valid_blue1 = 1;
73 valid_blue2 = 0;
74 invalid_blue = -1;
76 /* Using the public APIs */
77 adg_color_style_set_blue(color_style, valid_blue1);
78 blue = adg_color_style_get_blue(color_style);
79 adg_assert_isapprox(blue, valid_blue1);
81 adg_color_style_set_blue(color_style, invalid_blue);
82 blue = adg_color_style_get_blue(color_style);
83 adg_assert_isapprox(blue, valid_blue1);
85 adg_color_style_set_blue(color_style, valid_blue2);
86 blue = adg_color_style_get_blue(color_style);
87 adg_assert_isapprox(blue, valid_blue2);
89 /* Using GObject property methods */
90 g_object_set(color_style, "blue", valid_blue1, NULL);
91 g_object_get(color_style, "blue", &blue, NULL);
92 adg_assert_isapprox(blue, valid_blue1);
94 g_object_set(color_style, "blue", invalid_blue, NULL);
95 g_object_get(color_style, "blue", &blue, NULL);
96 adg_assert_isapprox(blue, valid_blue1);
98 g_object_set(color_style, "blue", valid_blue2, NULL);
99 g_object_get(color_style, "blue", &blue, NULL);
100 adg_assert_isapprox(blue, valid_blue2);
102 g_object_unref(color_style);
105 static void
106 _adg_property_green(void)
108 AdgColorStyle *color_style;
109 gdouble valid_green1, valid_green2, invalid_green, green;
111 color_style = adg_color_style_new();
112 valid_green1 = 1;
113 valid_green2 = 0;
114 invalid_green = -1;
116 /* Using the public APIs */
117 adg_color_style_set_green(color_style, valid_green1);
118 green = adg_color_style_get_green(color_style);
119 adg_assert_isapprox(green, valid_green1);
121 adg_color_style_set_green(color_style, invalid_green);
122 green = adg_color_style_get_green(color_style);
123 adg_assert_isapprox(green, valid_green1);
125 adg_color_style_set_green(color_style, valid_green2);
126 green = adg_color_style_get_green(color_style);
127 adg_assert_isapprox(green, valid_green2);
129 /* Using GObject property methods */
130 g_object_set(color_style, "green", valid_green1, NULL);
131 g_object_get(color_style, "green", &green, NULL);
132 adg_assert_isapprox(green, valid_green1);
134 g_object_set(color_style, "green", invalid_green, NULL);
135 g_object_get(color_style, "green", &green, NULL);
136 adg_assert_isapprox(green, valid_green1);
138 g_object_set(color_style, "green", valid_green2, NULL);
139 g_object_get(color_style, "green", &green, NULL);
140 adg_assert_isapprox(green, valid_green2);
142 g_object_unref(color_style);
145 static void
146 _adg_property_red(void)
148 AdgColorStyle *color_style;
149 gdouble valid_red1, valid_red2, invalid_red, red;
151 color_style = adg_color_style_new();
152 valid_red1 = 1;
153 valid_red2 = 0;
154 invalid_red = -1;
156 /* Using the public APIs */
157 adg_color_style_set_red(color_style, valid_red1);
158 red = adg_color_style_get_red(color_style);
159 adg_assert_isapprox(red, valid_red1);
161 adg_color_style_set_red(color_style, invalid_red);
162 red = adg_color_style_get_red(color_style);
163 adg_assert_isapprox(red, valid_red1);
165 adg_color_style_set_red(color_style, valid_red2);
166 red = adg_color_style_get_red(color_style);
167 adg_assert_isapprox(red, valid_red2);
169 /* Using GObject property methods */
170 g_object_set(color_style, "red", valid_red1, NULL);
171 g_object_get(color_style, "red", &red, NULL);
172 adg_assert_isapprox(red, valid_red1);
174 g_object_set(color_style, "red", invalid_red, NULL);
175 g_object_get(color_style, "red", &red, NULL);
176 adg_assert_isapprox(red, valid_red1);
178 g_object_set(color_style, "red", valid_red2, NULL);
179 g_object_get(color_style, "red", &red, NULL);
180 adg_assert_isapprox(red, valid_red2);
182 g_object_unref(color_style);
187 main(int argc, char *argv[])
189 adg_test_init(&argc, &argv);
191 adg_test_add_object_checks("/adg/color-style/type/object", ADG_TYPE_COLOR_STYLE);
193 g_test_add_func("/adg/color-style/property/alpha", _adg_property_alpha);
194 g_test_add_func("/adg/color-style/property/blue", _adg_property_blue);
195 g_test_add_func("/adg/color-style/property/green", _adg_property_green);
196 g_test_add_func("/adg/color-style/property/red", _adg_property_red);
198 return g_test_run();