summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-01-24 11:02:21 -0500
committerMarco Trevisan (TreviƱo) <mail@3v1n0.net>2021-05-05 17:17:48 +0200
commit17f0d88e96ae4242c1f835f9eb1e429ae5687770 (patch)
tree93b333ed7cf647de9b5e28f71a21dd22c7d1e687
parentaf62cc0ff88c36a2647eb2fd6d7ad146c41fb304 (diff)
downloadpango-17f0d88e96ae4242c1f835f9eb1e429ae5687770.tar.gz
tests: Add tests for pango_font_describe
Test that round-tripping through pango_font_describe works. This is currently broken for scalable bitmap fonts, such as color Emoji fonts. We skip the test on OS X where we are most likely missing the fonts. (cherry-picked from commit 49b1f80a)
-rw-r--r--tests/meson.build2
-rw-r--r--tests/test-font.c69
2 files changed, 71 insertions, 0 deletions
diff --git a/tests/meson.build b/tests/meson.build
index c0cd0e72..4b0d4182 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -8,6 +8,8 @@ endif
if host_system == 'windows'
test_cflags += '-DHAVE_WIN32'
+elif host_system == 'darwin'
+ test_cflags += '-DHAVE_CARBON'
endif
test_env = [
diff --git a/tests/test-font.c b/tests/test-font.c
index 6b8f45be..dd110571 100644
--- a/tests/test-font.c
+++ b/tests/test-font.c
@@ -188,6 +188,73 @@ test_extents (void)
g_object_unref (context);
}
+static void
+test_roundtrip_plain (void)
+{
+ PangoFontMap *fontmap;
+ PangoContext *context;
+ PangoFontDescription *desc, *desc2;
+ PangoFont *font;
+
+#ifdef HAVE_CARBON
+ /* We probably don't have the right fonts */
+ g_test_skip ("Skipping font-dependent tests on OS X");
+ return;
+#endif
+
+ fontmap = pango_cairo_font_map_get_default ();
+ context = pango_font_map_create_context (fontmap);
+
+ desc = pango_font_description_from_string ("Cantarell 11");
+
+ font = pango_context_load_font (context, desc);
+ desc2 = pango_font_describe (font);
+
+ g_assert (pango_font_description_equal (desc2, desc));
+
+ pango_font_description_free (desc2);
+ g_object_unref (font);
+ pango_font_description_free (desc);
+ g_object_unref (context);
+}
+
+static void
+test_roundtrip_emoji (void)
+{
+ PangoFontMap *fontmap;
+ PangoContext *context;
+ PangoFontDescription *desc, *desc2;
+ PangoFont *font;
+
+#ifdef HAVE_CARBON
+ /* We probably don't have the right fonts */
+ g_test_skip ("Skipping font-dependent tests on OS X");
+ return;
+#endif
+
+ fontmap = pango_cairo_font_map_get_default ();
+ context = pango_font_map_create_context (fontmap);
+
+ /* This is how pango_itemize creates the emoji font desc */
+ desc = pango_font_description_from_string ("Cantarell 11");
+ pango_font_description_set_family_static (desc, "emoji");
+
+ font = pango_context_load_font (context, desc);
+ desc2 = pango_font_describe (font);
+
+ /* We can't expect the family name to match, since we go in with
+ * a generic family
+ */
+ pango_font_description_unset_fields (desc, PANGO_FONT_MASK_FAMILY);
+ pango_font_description_unset_fields (desc2, PANGO_FONT_MASK_FAMILY);
+ g_assert (pango_font_description_equal (desc2, desc));
+
+ pango_font_description_free (desc2);
+ g_object_unref (font);
+ pango_font_description_free (desc);
+ g_object_unref (context);
+}
+
int
main (int argc, char *argv[])
{
@@ -203,6 +270,8 @@ main (int argc, char *argv[])
g_test_add_func ("/pango/fontdescription/roundtrip", test_roundtrip);
g_test_add_func ("/pango/fontdescription/variation", test_variation);
g_test_add_func ("/pango/font/extents", test_extents);
+ g_test_add_func ("/pango/font/roundtrip/plain", test_roundtrip_plain);
+ g_test_add_func ("/pango/font/roundtrip/emoji", test_roundtrip_emoji);
return g_test_run ();
}