[tests] New adg_test_invalid_pointer() function
[adg.git] / tests / test-edges.c
blobcb1d6fecb4af4dad1f52e48f59d224f8c59cfe9c
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"
24 static void
25 test_source(void)
27 AdgEdges *edges;
28 AdgTrail *valid_trail, *invalid_trail;
29 AdgTrail *source;
31 edges = adg_edges_new();
32 valid_trail = ADG_TRAIL(adg_path_new());
33 invalid_trail = adg_test_invalid_pointer();
35 /* Using the public APIs */
36 adg_edges_set_source(edges, valid_trail);
37 source = adg_edges_get_source(edges);
38 g_assert(source == valid_trail);
40 adg_edges_set_source(edges, invalid_trail);
41 source = adg_edges_get_source(edges);
42 g_assert(source == valid_trail);
44 adg_edges_set_source(edges, NULL);
45 source = adg_edges_get_source(edges);
46 g_assert(source == NULL);
48 /* Using GObject property methods */
49 g_object_set(edges, "source", valid_trail, NULL);
50 g_object_get(edges, "source", &source, NULL);
51 g_assert(source == valid_trail);
53 g_object_set(edges, "source", invalid_trail, NULL);
54 g_object_get(edges, "source", &source, NULL);
55 g_assert(source == valid_trail);
57 g_object_set(edges, "source", NULL, NULL);
58 g_object_get(edges, "source", &source, NULL);
59 g_assert(source == NULL);
61 g_object_unref(edges);
62 g_object_unref(valid_trail);
65 static void
66 test_critical_angle(void)
68 AdgEdges *edges;
69 gdouble valid_value, invalid_value;
70 gdouble critical_angle;
72 edges = adg_edges_new();
73 valid_value = G_PI / 10;
74 invalid_value = G_PI + 1;
76 /* Using the public APIs */
77 adg_edges_set_critical_angle(edges, valid_value);
78 critical_angle = adg_edges_get_critical_angle(edges);
79 g_assert_cmpfloat(critical_angle, ==, valid_value);
81 adg_edges_set_critical_angle(edges, invalid_value);
82 critical_angle = adg_edges_get_critical_angle(edges);
83 g_assert_cmpfloat(critical_angle, !=, invalid_value);
85 /* Using GObject property methods */
86 g_object_set(edges, "critical-angle", valid_value, NULL);
87 g_object_get(edges, "critical-angle", &critical_angle, NULL);
88 g_assert_cmpfloat(critical_angle, ==, valid_value);
90 g_object_set(edges, "critical-angle", invalid_value, NULL);
91 g_object_get(edges, "critical-angle", &critical_angle, NULL);
92 g_assert_cmpfloat(critical_angle, !=, invalid_value);
94 g_object_unref(edges);
98 int
99 main(int argc, char *argv[])
101 test_init(&argc, &argv);
103 g_test_add_func("/adg/edges/source", test_source);
104 g_test_add_func("/adg/edges/critical-angle", test_critical_angle);
106 return g_test_run();