adg: properly initialize AdgToyText:local-mix
[adg.git] / src / adg / tests / test-toy-text.c
blob54d3b8c7df13dd8433dc386f7c7afb102421ae7b
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 void
25 _adg_test_local_mix(void)
27 AdgToyText *toy_text;
28 AdgEntity *entity;
30 /* Check default local mix method */
31 toy_text = adg_text_new("");
32 entity = (AdgEntity *) toy_text;
33 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_ANCESTORS_NORMALIZED);
34 adg_entity_destroy(entity);
36 /* Check local mix method overriding */
37 toy_text = g_object_new(ADG_TYPE_TEXT, "local-mix", ADG_MIX_DISABLED, NULL);
38 entity = (AdgEntity *) toy_text;
39 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_DISABLED);
40 adg_entity_destroy(entity);
42 /* Check default mix using GObject methods */
43 toy_text = g_object_new(ADG_TYPE_TEXT, NULL);
44 entity = (AdgEntity *) toy_text;
45 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_ANCESTORS_NORMALIZED);
46 adg_entity_destroy(entity);
49 static void
50 _adg_test_font_dress(void)
52 AdgToyText *toy_text;
53 AdgTextual *textual;
54 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
55 AdgDress font_dress;
57 toy_text = adg_toy_text_new(NULL);
58 textual = (AdgTextual *) toy_text;
59 valid_dress_1 = ADG_DRESS_FONT_QUOTE_ANNOTATION;
60 valid_dress_2 = ADG_DRESS_FONT;
61 incompatible_dress = ADG_DRESS_LINE;
63 /* Using the public APIs */
64 adg_textual_set_font_dress(textual, valid_dress_1);
65 font_dress = adg_textual_get_font_dress(textual);
66 g_assert_cmpint(font_dress, ==, valid_dress_1);
68 adg_textual_set_font_dress(textual, incompatible_dress);
69 font_dress = adg_textual_get_font_dress(textual);
70 g_assert_cmpint(font_dress, ==, valid_dress_1);
72 adg_textual_set_font_dress(textual, valid_dress_2);
73 font_dress = adg_textual_get_font_dress(textual);
74 g_assert_cmpint(font_dress, ==, valid_dress_2);
76 /* Using GObject property methods */
77 g_object_set(toy_text, "font-dress", valid_dress_1, NULL);
78 g_object_get(toy_text, "font-dress", &font_dress, NULL);
79 g_assert_cmpint(font_dress, ==, valid_dress_1);
81 g_object_set(toy_text, "font-dress", incompatible_dress, NULL);
82 g_object_get(toy_text, "font-dress", &font_dress, NULL);
83 g_assert_cmpint(font_dress, ==, valid_dress_1);
85 g_object_set(toy_text, "font-dress", valid_dress_2, NULL);
86 g_object_get(toy_text, "font-dress", &font_dress, NULL);
87 g_assert_cmpint(font_dress, ==, valid_dress_2);
89 adg_entity_destroy(ADG_ENTITY(toy_text));
92 static void
93 _adg_test_text(void)
95 AdgToyText *toy_text;
96 AdgTextual *textual;
97 const gchar *valid_text, *latin1_text;
98 gchar *text;
100 toy_text = adg_toy_text_new(NULL);
101 textual = (AdgTextual *) toy_text;
102 valid_text = "This is some text...";
103 latin1_text = "This is some àèìòù Latin1 text...";
105 /* Using the public APIs */
106 adg_textual_set_text(textual, valid_text);
107 text = adg_textual_dup_text(textual);
108 g_assert_cmpstr(text, ==, valid_text);
109 g_free(text);
111 adg_textual_set_text(textual, latin1_text);
112 text = adg_textual_dup_text(textual);
113 g_assert_cmpstr(text, ==, latin1_text);
114 g_free(text);
116 adg_textual_set_text(textual, NULL);
117 text = adg_textual_dup_text(textual);
118 g_assert(text == NULL);
119 g_free(text);
121 /* Using GObject property methods */
122 g_object_set(toy_text, "text", valid_text, NULL);
123 g_object_get(toy_text, "text", &text, NULL);
124 g_assert_cmpstr(text, ==, valid_text);
125 g_free(text);
127 g_object_set(toy_text, "text", latin1_text, NULL);
128 g_object_get(toy_text, "text", &text, NULL);
129 g_assert_cmpstr(text, ==, latin1_text);
130 g_free(text);
132 g_object_set(toy_text, "text", NULL, NULL);
133 g_object_get(toy_text, "text", &text, NULL);
134 g_assert(text == NULL);
136 adg_entity_destroy(ADG_ENTITY(toy_text));
141 main(int argc, char *argv[])
143 adg_test_init(&argc, &argv);
145 adg_test_add_func("/adg/toy-text/local-mix", _adg_test_font_dress);
146 adg_test_add_func("/adg/toy-text/font-dress", _adg_test_font_dress);
147 adg_test_add_func("/adg/toy-text/text", _adg_test_text);
149 return g_test_run();