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"
25 _adg_test_dashes(void)
29 const gdouble
*dashes
;
30 const gdouble dashes_array
[] = { 1., 2., 3. };
32 dash
= adg_dash_new();
33 g_assert(dash
!= NULL
);
34 num_dashes
= adg_dash_get_num_dashes(dash
);
35 g_assert_cmpint(num_dashes
, ==, 0);
36 dashes
= adg_dash_get_dashes(dash
);
37 g_assert(dashes
== NULL
);
39 adg_dash_append_dash(dash
, 1234.);
40 num_dashes
= adg_dash_get_num_dashes(dash
);
41 g_assert_cmpint(num_dashes
, ==, 1);
42 dashes
= adg_dash_get_dashes(dash
);
43 g_assert(dashes
!= NULL
);
44 g_assert_cmpfloat(dashes
[0], ==, 1234.);
46 adg_dash_append_dashes(dash
, 2, 0., 4321.);
47 num_dashes
= adg_dash_get_num_dashes(dash
);
48 g_assert_cmpint(num_dashes
, ==, 3);
49 dashes
= adg_dash_get_dashes(dash
);
50 g_assert(dashes
!= NULL
);
51 g_assert_cmpfloat(dashes
[0], ==, 1234.);
52 g_assert_cmpfloat(dashes
[1], ==, 0.);
53 g_assert_cmpfloat(dashes
[2], ==, 4321.);
55 adg_dash_clear_dashes(dash
);
56 num_dashes
= adg_dash_get_num_dashes(dash
);
57 g_assert_cmpint(num_dashes
, ==, 0);
58 dashes
= adg_dash_get_dashes(dash
);
59 g_assert(dashes
== NULL
);
61 adg_dash_append_dashes_array(dash
, 3, dashes_array
);
62 num_dashes
= adg_dash_get_num_dashes(dash
);
63 g_assert_cmpint(num_dashes
, ==, 3);
64 dashes
= adg_dash_get_dashes(dash
);
65 g_assert(dashes
!= NULL
);
66 g_assert_cmpfloat(dashes
[0], ==, 1.);
67 g_assert_cmpfloat(dashes
[1], ==, 2.);
68 g_assert_cmpfloat(dashes
[2], ==, 3.);
70 adg_dash_destroy(dash
);
72 dash
= adg_dash_new_with_dashes(3, 1., 2., 3.);
73 g_assert(dash
!= NULL
);
74 num_dashes
= adg_dash_get_num_dashes(dash
);
75 g_assert_cmpint(num_dashes
, ==, 3);
76 dashes
= adg_dash_get_dashes(dash
);
77 g_assert(dashes
!= NULL
);
78 g_assert_cmpfloat(dashes
[0], ==, 1.);
79 g_assert_cmpfloat(dashes
[1], ==, 2.);
80 g_assert_cmpfloat(dashes
[2], ==, 3.);
82 adg_dash_destroy(dash
);
86 _adg_test_offset(void)
91 dash
= adg_dash_new();
93 /* Ensure the default is 0 */
94 offset
= adg_dash_get_offset(dash
);
95 g_assert_cmpfloat(offset
, ==, 0);
97 /* Check some special values */
98 adg_dash_set_offset(dash
, G_MINDOUBLE
);
99 offset
= adg_dash_get_offset(dash
);
100 g_assert_cmpfloat(offset
, ==, G_MINDOUBLE
);
102 adg_dash_set_offset(dash
, G_MAXDOUBLE
);
103 offset
= adg_dash_get_offset(dash
);
104 g_assert_cmpfloat(offset
, ==, G_MAXDOUBLE
);
106 adg_dash_set_offset(dash
, 0);
107 offset
= adg_dash_get_offset(dash
);
108 g_assert_cmpfloat(offset
, ==, 0);
110 adg_dash_destroy(dash
);
115 main(int argc
, char *argv
[])
117 adg_test_init(&argc
, &argv
);
119 adg_test_add_func("/adg/dash/dashes", _adg_test_dashes
);
120 adg_test_add_func("/adg/dash/offset", _adg_test_offset
);