doc: update copyright line for 2021
[adg.git] / src / adg / tests / test-text.c
blobc065a4eaf7a5fe680825dd8caf9fddeb5cf17e3b
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2021 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 <adg-test.h>
22 #include <adg.h>
25 static void
26 _adg_property_local_mix(void)
28 AdgText *text;
29 AdgEntity *entity;
31 /* Check default local mix method */
32 text = adg_text_new("");
33 entity = (AdgEntity *) text;
34 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_ANCESTORS_NORMALIZED);
35 adg_entity_destroy(entity);
37 /* Check local mix method overriding */
38 text = g_object_new(ADG_TYPE_TEXT, "local-mix", ADG_MIX_DISABLED, NULL);
39 entity = (AdgEntity *) text;
40 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_DISABLED);
41 adg_entity_destroy(entity);
43 /* Check default mix using GObject methods */
44 text = g_object_new(ADG_TYPE_TEXT, NULL);
45 entity = (AdgEntity *) text;
46 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_ANCESTORS_NORMALIZED);
47 adg_entity_destroy(entity);
50 static void
51 _adg_property_font_dress(void)
53 AdgText *text;
54 AdgTextual *textual;
55 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
56 AdgDress font_dress;
58 text = adg_text_new(NULL);
59 textual = (AdgTextual *) text;
60 valid_dress_1 = ADG_DRESS_FONT_QUOTE_ANNOTATION;
61 valid_dress_2 = ADG_DRESS_FONT;
62 incompatible_dress = ADG_DRESS_LINE;
64 /* Using the public APIs */
65 adg_textual_set_font_dress(textual, valid_dress_1);
66 font_dress = adg_textual_get_font_dress(textual);
67 g_assert_cmpint(font_dress, ==, valid_dress_1);
69 adg_textual_set_font_dress(textual, incompatible_dress);
70 font_dress = adg_textual_get_font_dress(textual);
71 g_assert_cmpint(font_dress, ==, valid_dress_1);
73 adg_textual_set_font_dress(textual, valid_dress_2);
74 font_dress = adg_textual_get_font_dress(textual);
75 g_assert_cmpint(font_dress, ==, valid_dress_2);
77 /* Using GObject property methods */
78 g_object_set(text, "font-dress", valid_dress_1, NULL);
79 g_object_get(text, "font-dress", &font_dress, NULL);
80 g_assert_cmpint(font_dress, ==, valid_dress_1);
82 g_object_set(text, "font-dress", incompatible_dress, NULL);
83 g_object_get(text, "font-dress", &font_dress, NULL);
84 g_assert_cmpint(font_dress, ==, valid_dress_1);
86 g_object_set(text, "font-dress", valid_dress_2, NULL);
87 g_object_get(text, "font-dress", &font_dress, NULL);
88 g_assert_cmpint(font_dress, ==, valid_dress_2);
90 adg_entity_destroy(ADG_ENTITY(text));
93 static void
94 _adg_property_text(void)
96 AdgText *text;
97 AdgTextual *textual;
98 const gchar *valid_text, *latin1_text;
99 gchar *string;
101 text = adg_text_new(NULL);
102 textual = (AdgTextual *) text;
103 valid_text = "This is some string...";
104 latin1_text = "This is some àèìòù Latin1 string...";
106 /* Using the public APIs */
107 adg_textual_set_text(textual, valid_text);
108 string = adg_textual_dup_text(textual);
109 g_assert_cmpstr(string, ==, valid_text);
110 g_free(string);
112 adg_textual_set_text(textual, latin1_text);
113 string = adg_textual_dup_text(textual);
114 g_assert_cmpstr(string, ==, latin1_text);
115 g_free(string);
117 adg_textual_set_text(textual, NULL);
118 string = adg_textual_dup_text(textual);
119 g_assert_null(string);
120 g_free(string);
122 /* Using GObject property methods */
123 g_object_set(text, "text", valid_text, NULL);
124 g_object_get(text, "text", &string, NULL);
125 g_assert_cmpstr(string, ==, valid_text);
126 g_free(string);
128 g_object_set(text, "text", latin1_text, NULL);
129 g_object_get(text, "text", &string, NULL);
130 g_assert_cmpstr(string, ==, latin1_text);
131 g_free(string);
133 g_object_set(text, "text", NULL, NULL);
134 g_object_get(text, "text", &string, NULL);
135 g_assert_null(string);
137 adg_entity_destroy(ADG_ENTITY(text));
142 main(int argc, char *argv[])
144 adg_test_init(&argc, &argv);
146 adg_test_add_object_checks("/adg/text/type/object", ADG_TYPE_TEXT);
147 adg_test_add_entity_checks("/adg/text/type/entity", ADG_TYPE_TEXT);
149 adg_test_add_global_space_checks("/adg/text/behavior/global-space", adg_text_new("Testing"));
151 g_test_add_func("/adg/text/property/local-mix", _adg_property_local_mix);
152 g_test_add_func("/adg/text/property/font-dress", _adg_property_font_dress);
153 g_test_add_func("/adg/text/property/string", _adg_property_text);
155 return g_test_run();