test: updated test units
[adg.git] / src / adg / tests / test-trail.c
blobaa07ecc179f7e073be698515af542647554388d6
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 cairo_path_t *
25 _adg_path_callback(AdgTrail *trail, gpointer user_data)
27 static cairo_path_data_t data[] = {
28 { .header = { CPML_MOVE, 2 }},
29 { .point = { 0, 1 }},
30 { .header = { CPML_LINE, 2 }},
31 { .point = { 2, 3 }},
32 { .header = { CPML_LINE, 2 }},
33 { .point = { 4, 5 }}
35 static cairo_path_t path = {
36 CAIRO_STATUS_SUCCESS,
37 data,
38 G_N_ELEMENTS(data)
41 return &path;
45 static void
46 _adg_test_max_angle(void)
48 AdgTrail *trail;
49 gdouble valid_value, invalid_value;
50 gdouble max_angle;
52 trail = adg_trail_new(_adg_path_callback, NULL);
53 valid_value = G_PI / 10;
54 invalid_value = G_PI + 1;
56 /* Using the public APIs */
57 adg_trail_set_max_angle(trail, valid_value);
58 max_angle = adg_trail_get_max_angle(trail);
59 g_assert_cmpfloat(max_angle, ==, valid_value);
61 adg_trail_set_max_angle(trail, invalid_value);
62 max_angle = adg_trail_get_max_angle(trail);
63 g_assert_cmpfloat(max_angle, !=, invalid_value);
65 /* Using GObject property methods */
66 g_object_set(trail, "max-angle", valid_value, NULL);
67 g_object_get(trail, "max-angle", &max_angle, NULL);
68 g_assert_cmpfloat(max_angle, ==, valid_value);
70 g_object_set(trail, "max-angle", invalid_value, NULL);
71 g_object_get(trail, "max-angle", &max_angle, NULL);
72 g_assert_cmpfloat(max_angle, !=, invalid_value);
74 g_object_unref(trail);
78 int
79 main(int argc, char *argv[])
81 adg_test_init(&argc, &argv);
83 adg_test_add_func("/adg/trail/max-angle", _adg_test_max_angle);
85 return g_test_run();