build: depends on cairo-gobject if introspection is enabled
[adg.git] / src / adg / tests / test-color-style.c
blob78146d1d33101811bc9f4985b0f46cced0db6962
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 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 "test-internal.h"
24 static void
25 _adg_test_alpha(void)
27 AdgColorStyle *color_style;
28 gdouble valid_alpha1, valid_alpha2, invalid_alpha, alpha;
30 color_style = adg_color_style_new();
31 valid_alpha1 = 1;
32 valid_alpha2 = 0;
33 invalid_alpha = -1;
35 /* Using the public APIs */
36 adg_color_style_set_alpha(color_style, valid_alpha1);
37 alpha = adg_color_style_get_alpha(color_style);
38 g_assert_cmpfloat(alpha, ==, valid_alpha1);
40 adg_color_style_set_alpha(color_style, invalid_alpha);
41 alpha = adg_color_style_get_alpha(color_style);
42 g_assert_cmpfloat(alpha, ==, valid_alpha1);
44 adg_color_style_set_alpha(color_style, valid_alpha2);
45 alpha = adg_color_style_get_alpha(color_style);
46 g_assert_cmpfloat(alpha, ==, valid_alpha2);
48 /* Using GObject property methods */
49 g_object_set(color_style, "alpha", valid_alpha1, NULL);
50 g_object_get(color_style, "alpha", &alpha, NULL);
51 g_assert_cmpfloat(alpha, ==, valid_alpha1);
53 g_object_set(color_style, "alpha", invalid_alpha, NULL);
54 g_object_get(color_style, "alpha", &alpha, NULL);
55 g_assert_cmpfloat(alpha, ==, valid_alpha1);
57 g_object_set(color_style, "alpha", valid_alpha2, NULL);
58 g_object_get(color_style, "alpha", &alpha, NULL);
59 g_assert_cmpfloat(alpha, ==, valid_alpha2);
61 g_object_unref(color_style);
64 static void
65 _adg_test_blue(void)
67 AdgColorStyle *color_style;
68 gdouble valid_blue1, valid_blue2, invalid_blue, blue;
70 color_style = adg_color_style_new();
71 valid_blue1 = 1;
72 valid_blue2 = 0;
73 invalid_blue = -1;
75 /* Using the public APIs */
76 adg_color_style_set_blue(color_style, valid_blue1);
77 blue = adg_color_style_get_blue(color_style);
78 g_assert_cmpfloat(blue, ==, valid_blue1);
80 adg_color_style_set_blue(color_style, invalid_blue);
81 blue = adg_color_style_get_blue(color_style);
82 g_assert_cmpfloat(blue, ==, valid_blue1);
84 adg_color_style_set_blue(color_style, valid_blue2);
85 blue = adg_color_style_get_blue(color_style);
86 g_assert_cmpfloat(blue, ==, valid_blue2);
88 /* Using GObject property methods */
89 g_object_set(color_style, "blue", valid_blue1, NULL);
90 g_object_get(color_style, "blue", &blue, NULL);
91 g_assert_cmpfloat(blue, ==, valid_blue1);
93 g_object_set(color_style, "blue", invalid_blue, NULL);
94 g_object_get(color_style, "blue", &blue, NULL);
95 g_assert_cmpfloat(blue, ==, valid_blue1);
97 g_object_set(color_style, "blue", valid_blue2, NULL);
98 g_object_get(color_style, "blue", &blue, NULL);
99 g_assert_cmpfloat(blue, ==, valid_blue2);
101 g_object_unref(color_style);
104 static void
105 _adg_test_green(void)
107 AdgColorStyle *color_style;
108 gdouble valid_green1, valid_green2, invalid_green, green;
110 color_style = adg_color_style_new();
111 valid_green1 = 1;
112 valid_green2 = 0;
113 invalid_green = -1;
115 /* Using the public APIs */
116 adg_color_style_set_green(color_style, valid_green1);
117 green = adg_color_style_get_green(color_style);
118 g_assert_cmpfloat(green, ==, valid_green1);
120 adg_color_style_set_green(color_style, invalid_green);
121 green = adg_color_style_get_green(color_style);
122 g_assert_cmpfloat(green, ==, valid_green1);
124 adg_color_style_set_green(color_style, valid_green2);
125 green = adg_color_style_get_green(color_style);
126 g_assert_cmpfloat(green, ==, valid_green2);
128 /* Using GObject property methods */
129 g_object_set(color_style, "green", valid_green1, NULL);
130 g_object_get(color_style, "green", &green, NULL);
131 g_assert_cmpfloat(green, ==, valid_green1);
133 g_object_set(color_style, "green", invalid_green, NULL);
134 g_object_get(color_style, "green", &green, NULL);
135 g_assert_cmpfloat(green, ==, valid_green1);
137 g_object_set(color_style, "green", valid_green2, NULL);
138 g_object_get(color_style, "green", &green, NULL);
139 g_assert_cmpfloat(green, ==, valid_green2);
141 g_object_unref(color_style);
144 static void
145 _adg_test_red(void)
147 AdgColorStyle *color_style;
148 gdouble valid_red1, valid_red2, invalid_red, red;
150 color_style = adg_color_style_new();
151 valid_red1 = 1;
152 valid_red2 = 0;
153 invalid_red = -1;
155 /* Using the public APIs */
156 adg_color_style_set_red(color_style, valid_red1);
157 red = adg_color_style_get_red(color_style);
158 g_assert_cmpfloat(red, ==, valid_red1);
160 adg_color_style_set_red(color_style, invalid_red);
161 red = adg_color_style_get_red(color_style);
162 g_assert_cmpfloat(red, ==, valid_red1);
164 adg_color_style_set_red(color_style, valid_red2);
165 red = adg_color_style_get_red(color_style);
166 g_assert_cmpfloat(red, ==, valid_red2);
168 /* Using GObject property methods */
169 g_object_set(color_style, "red", valid_red1, NULL);
170 g_object_get(color_style, "red", &red, NULL);
171 g_assert_cmpfloat(red, ==, valid_red1);
173 g_object_set(color_style, "red", invalid_red, NULL);
174 g_object_get(color_style, "red", &red, NULL);
175 g_assert_cmpfloat(red, ==, valid_red1);
177 g_object_set(color_style, "red", valid_red2, NULL);
178 g_object_get(color_style, "red", &red, NULL);
179 g_assert_cmpfloat(red, ==, valid_red2);
181 g_object_unref(color_style);
186 main(int argc, char *argv[])
188 adg_test_init(&argc, &argv);
190 adg_test_add_func("/adg/color-style/alpha", _adg_test_alpha);
191 adg_test_add_func("/adg/color-style/blue", _adg_test_blue);
192 adg_test_add_func("/adg/color-style/green", _adg_test_green);
193 adg_test_add_func("/adg/color-style/red", _adg_test_red);
195 return g_test_run();