From 0d1945ed2c602e295e433ce7e9e1ecbc6600c76a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 8 Sep 2014 11:55:06 -0400 Subject: Add some tests for PangoFontDescription This just a small beginning, much more is needed here. --- tests/Makefile.am | 2 ++ tests/test-font.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/test-font.c diff --git a/tests/Makefile.am b/tests/Makefile.am index b9ed3138..b048ea0f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -50,6 +50,7 @@ check_PROGRAMS = \ testscript \ markup-parse \ test-layout \ + test-font \ $(NULL) if HAVE_CAIRO @@ -74,6 +75,7 @@ test_pangocairo_threads_LDADD = $(TEST_PANGOCAIRO_LIBS) $(CAIRO_LIBS) $(GLIB_LIB dump_boundaries_LDADD = $(TEST_PANGO_LIBS) $(GLIB_LIBS) markup_parse_LDADD = $(TEST_PANGOCAIRO_LIBS) $(GLIB_LIBS) test_layout_LDADD = $(TEST_PANGOCAIRO_LIBS) $(GLIB_LIBS) +test_font_LDADD = $(TEST_PANGOCAIRO_LIBS) $(GLIB_LIBS) if HAVE_CXX check_PROGRAMS += cxx-test diff --git a/tests/test-font.c b/tests/test-font.c new file mode 100644 index 00000000..5603a59f --- /dev/null +++ b/tests/test-font.c @@ -0,0 +1,92 @@ +/* Pango + * test-font.c: Test PangoFontDescription + * + * Copyright (C) 2014 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include + +#include + +static void +test_parse (void) +{ + PangoFontDescription *desc; + + desc = pango_font_description_from_string ("Cantarell 14"); + + g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Cantarell"); + g_assert (!pango_font_description_get_size_is_absolute (desc)); + g_assert_cmpint (pango_font_description_get_size (desc), ==, 14 * PANGO_SCALE); + g_assert_cmpint (pango_font_description_get_style (desc), ==, PANGO_STYLE_NORMAL); + g_assert_cmpint (pango_font_description_get_variant (desc), ==, PANGO_VARIANT_NORMAL); + g_assert_cmpint (pango_font_description_get_weight (desc), ==, PANGO_WEIGHT_NORMAL); + g_assert_cmpint (pango_font_description_get_stretch (desc), ==, PANGO_STRETCH_NORMAL); + g_assert_cmpint (pango_font_description_get_gravity (desc), ==, PANGO_GRAVITY_SOUTH); + g_assert_cmpint (pango_font_description_get_set_fields (desc), ==, PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_STYLE | PANGO_FONT_MASK_VARIANT | PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STRETCH | PANGO_FONT_MASK_SIZE); + + pango_font_description_free (desc); + + desc = pango_font_description_from_string ("Sans Bold Italic Condensed 22.5px"); + + g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Sans"); + g_assert (pango_font_description_get_size_is_absolute (desc)); + g_assert_cmpint (pango_font_description_get_size (desc), ==, 225 * PANGO_SCALE / 10); + g_assert_cmpint (pango_font_description_get_style (desc), ==, PANGO_STYLE_ITALIC); + g_assert_cmpint (pango_font_description_get_variant (desc), ==, PANGO_VARIANT_NORMAL); + g_assert_cmpint (pango_font_description_get_weight (desc), ==, PANGO_WEIGHT_BOLD); + g_assert_cmpint (pango_font_description_get_stretch (desc), ==, PANGO_STRETCH_CONDENSED); + g_assert_cmpint (pango_font_description_get_gravity (desc), ==, PANGO_GRAVITY_SOUTH); g_assert_cmpint (pango_font_description_get_set_fields (desc), ==, PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_STYLE | PANGO_FONT_MASK_VARIANT | PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STRETCH | PANGO_FONT_MASK_SIZE); + + pango_font_description_free (desc); +} + +static void +test_roundtrip (void) +{ + PangoFontDescription *desc; + gchar *str; + + desc = pango_font_description_from_string ("Cantarell 14"); + str = pango_font_description_to_string (desc); + g_assert_cmpstr (str, ==, "Cantarell 14"); + pango_font_description_free (desc); + g_free (str); + + desc = pango_font_description_from_string ("Sans Bold Italic Condensed 22.5px"); + str = pango_font_description_to_string (desc); + g_assert_cmpstr (str, ==, "Sans Bold Italic Condensed 22.5px"); + pango_font_description_free (desc); + g_free (str); +} + +int +main (int argc, char *argv[]) +{ + g_setenv ("LC_ALL", "C", TRUE); + setlocale (LC_ALL, ""); + + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/pango/fontdescription/parse", test_parse); + g_test_add_func ("/pango/fontdescription/roundtrip", test_roundtrip); + + return g_test_run (); +} -- cgit v1.2.1