1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2010 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"
25 _adg_test_direction(void)
28 gdouble valid_value
, invalid_value
;
31 ldim
= adg_ldim_new();
32 valid_value
= -G_PI_2
;
33 invalid_value
= G_PI
+ 1;
35 /* Using the public APIs */
36 adg_ldim_set_direction(ldim
, valid_value
);
37 direction
= adg_ldim_get_direction(ldim
);
38 g_assert_cmpfloat(direction
, ==, valid_value
);
40 adg_ldim_set_direction(ldim
, -G_PI
);
41 direction
= adg_ldim_get_direction(ldim
);
42 g_assert_cmpfloat(direction
, ==, G_PI
);
44 adg_ldim_set_direction(ldim
, invalid_value
);
45 direction
= adg_ldim_get_direction(ldim
);
46 g_assert_cmpfloat(direction
, !=, invalid_value
);
48 /* Using GObject property methods */
49 g_object_set(ldim
, "direction", valid_value
, NULL
);
50 g_object_get(ldim
, "direction", &direction
, NULL
);
51 g_assert_cmpfloat(direction
, ==, valid_value
);
53 g_object_set(ldim
, "direction", -G_PI
, NULL
);
54 g_object_get(ldim
, "direction", &direction
, NULL
);
55 g_assert_cmpfloat(direction
, ==, G_PI
);
57 g_object_set(ldim
, "direction", invalid_value
, NULL
);
58 g_object_get(ldim
, "direction", &direction
, NULL
);
59 g_assert_cmpfloat(direction
, !=, invalid_value
);
65 _adg_test_has_extension1(void)
68 gboolean invalid_boolean
;
69 gboolean has_extension1
;
71 ldim
= adg_ldim_new();
72 invalid_boolean
= (gboolean
) 1234;
74 /* Using the public APIs */
75 adg_ldim_switch_extension1(ldim
, FALSE
);
76 has_extension1
= adg_ldim_has_extension1(ldim
);
77 g_assert(!has_extension1
);
79 adg_ldim_switch_extension1(ldim
, invalid_boolean
);
80 has_extension1
= adg_ldim_has_extension1(ldim
);
81 g_assert(!has_extension1
);
83 adg_ldim_switch_extension1(ldim
, TRUE
);
84 has_extension1
= adg_ldim_has_extension1(ldim
);
85 g_assert(has_extension1
);
87 /* Using GObject property methods */
88 g_object_set(ldim
, "has-extension1", FALSE
, NULL
);
89 g_object_get(ldim
, "has-extension1", &has_extension1
, NULL
);
90 g_assert(!has_extension1
);
92 g_object_set(ldim
, "has-extension1", invalid_boolean
, NULL
);
93 g_object_get(ldim
, "has-extension1", &has_extension1
, NULL
);
94 g_assert(!has_extension1
);
96 g_object_set(ldim
, "has-extension1", TRUE
, NULL
);
97 g_object_get(ldim
, "has-extension1", &has_extension1
, NULL
);
98 g_assert(has_extension1
);
100 g_object_unref(ldim
);
104 _adg_test_has_extension2(void)
107 gboolean invalid_boolean
;
108 gboolean has_extension2
;
110 ldim
= adg_ldim_new();
111 invalid_boolean
= (gboolean
) 1234;
113 /* Using the public APIs */
114 adg_ldim_switch_extension2(ldim
, FALSE
);
115 has_extension2
= adg_ldim_has_extension2(ldim
);
116 g_assert(!has_extension2
);
118 adg_ldim_switch_extension2(ldim
, invalid_boolean
);
119 has_extension2
= adg_ldim_has_extension2(ldim
);
120 g_assert(!has_extension2
);
122 adg_ldim_switch_extension2(ldim
, TRUE
);
123 has_extension2
= adg_ldim_has_extension2(ldim
);
124 g_assert(has_extension2
);
126 /* Using GObject property methods */
127 g_object_set(ldim
, "has-extension2", FALSE
, NULL
);
128 g_object_get(ldim
, "has-extension2", &has_extension2
, NULL
);
129 g_assert(!has_extension2
);
131 g_object_set(ldim
, "has-extension2", invalid_boolean
, NULL
);
132 g_object_get(ldim
, "has-extension2", &has_extension2
, NULL
);
133 g_assert(!has_extension2
);
135 g_object_set(ldim
, "has-extension2", TRUE
, NULL
);
136 g_object_get(ldim
, "has-extension2", &has_extension2
, NULL
);
137 g_assert(has_extension2
);
139 g_object_unref(ldim
);
144 main(int argc
, char *argv
[])
146 adg_test_init(&argc
, &argv
);
148 adg_test_add_func("/adg/ldim/direction", _adg_test_direction
);
149 adg_test_add_func("/adg/ldim/has-extension1", _adg_test_has_extension1
);
150 adg_test_add_func("/adg/ldim/has-extension2", _adg_test_has_extension2
);