From 345006481db01173fe39cf71072730d72fd084ae Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Sun, 20 Feb 2011 22:14:43 +0100 Subject: [PATCH] [AdgText] Added property tests Finishing touches on AdgText. By using pango instead of the toy API, some problems, such as missing diameter symbol, will vanish. Closes issue #48: http://dev.entidi.com/p/adg/issues/48/ --- src/adg/tests/.gitignore | 1 + src/adg/tests/Makefile.am | 6 +++ src/adg/tests/test-text.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 src/adg/tests/test-text.c diff --git a/src/adg/tests/.gitignore b/src/adg/tests/.gitignore index f77d75cf..e32adc79 100644 --- a/src/adg/tests/.gitignore +++ b/src/adg/tests/.gitignore @@ -20,5 +20,6 @@ /test-stroke /test-table /test-table-style +/test-text /test-title-block /test-toy-text diff --git a/src/adg/tests/Makefile.am b/src/adg/tests/Makefile.am index 9c6bb104..99401d1b 100644 --- a/src/adg/tests/Makefile.am +++ b/src/adg/tests/Makefile.am @@ -110,6 +110,12 @@ TEST_PROGS+= test-canvas$(EXEEXT) test_canvas_SOURCES= test-canvas.c \ $(test_internals) +if HAVE_PANGO +TEST_PROGS+= test-text$(EXEEXT) +test_text_SOURCES= test-text.c \ + $(test_internals) +endif + endif diff --git a/src/adg/tests/test-text.c b/src/adg/tests/test-text.c new file mode 100644 index 00000000..ff25c063 --- /dev/null +++ b/src/adg/tests/test-text.c @@ -0,0 +1,124 @@ +/* ADG - Automatic Drawing Generation + * Copyright (C) 2011 Nicola Fontana + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + + +#include "test-internal.h" + + +static void +_adg_test_font_dress(void) +{ + AdgToyText *toy_text; + AdgTextual *textual; + AdgDress valid_dress_1, valid_dress_2, incompatible_dress; + AdgDress font_dress; + + toy_text = adg_toy_text_new(NULL); + textual = (AdgTextual *) toy_text; + valid_dress_1 = ADG_DRESS_FONT_QUOTE_ANNOTATION; + valid_dress_2 = ADG_DRESS_FONT; + incompatible_dress = ADG_DRESS_LINE; + + /* Using the public APIs */ + adg_textual_set_font_dress(textual, valid_dress_1); + font_dress = adg_textual_get_font_dress(textual); + g_assert_cmpint(font_dress, ==, valid_dress_1); + + adg_textual_set_font_dress(textual, incompatible_dress); + font_dress = adg_textual_get_font_dress(textual); + g_assert_cmpint(font_dress, ==, valid_dress_1); + + adg_textual_set_font_dress(textual, valid_dress_2); + font_dress = adg_textual_get_font_dress(textual); + g_assert_cmpint(font_dress, ==, valid_dress_2); + + /* Using GObject property methods */ + g_object_set(toy_text, "font-dress", valid_dress_1, NULL); + g_object_get(toy_text, "font-dress", &font_dress, NULL); + g_assert_cmpint(font_dress, ==, valid_dress_1); + + g_object_set(toy_text, "font-dress", incompatible_dress, NULL); + g_object_get(toy_text, "font-dress", &font_dress, NULL); + g_assert_cmpint(font_dress, ==, valid_dress_1); + + g_object_set(toy_text, "font-dress", valid_dress_2, NULL); + g_object_get(toy_text, "font-dress", &font_dress, NULL); + g_assert_cmpint(font_dress, ==, valid_dress_2); + + g_object_unref(toy_text); +} + +static void +_adg_test_text(void) +{ + AdgToyText *toy_text; + AdgTextual *textual; + const gchar *valid_text, *latin1_text; + gchar *text; + + toy_text = adg_toy_text_new(NULL); + textual = (AdgTextual *) toy_text; + valid_text = "This is some text..."; + latin1_text = "This is some àèìòù Latin1 text..."; + + /* Using the public APIs */ + adg_textual_set_text(textual, valid_text); + text = adg_textual_dup_text(textual); + g_assert_cmpstr(text, ==, valid_text); + g_free(text); + + adg_textual_set_text(textual, latin1_text); + text = adg_textual_dup_text(textual); + g_assert_cmpstr(text, ==, latin1_text); + g_free(text); + + adg_textual_set_text(textual, NULL); + text = adg_textual_dup_text(textual); + g_assert(text == NULL); + g_free(text); + + /* Using GObject property methods */ + g_object_set(toy_text, "text", valid_text, NULL); + g_object_get(toy_text, "text", &text, NULL); + g_assert_cmpstr(text, ==, valid_text); + g_free(text); + + g_object_set(toy_text, "text", latin1_text, NULL); + g_object_get(toy_text, "text", &text, NULL); + g_assert_cmpstr(text, ==, latin1_text); + g_free(text); + + g_object_set(toy_text, "text", NULL, NULL); + g_object_get(toy_text, "text", &text, NULL); + g_assert(text == NULL); + + g_object_unref(toy_text); +} + + +int +main(int argc, char *argv[]) +{ + adg_test_init(&argc, &argv); + + adg_test_add_func("/adg/text/font-dress", _adg_test_font_dress); + adg_test_add_func("/adg/text/text", _adg_test_text); + + return g_test_run(); +} -- 2.11.4.GIT