summaryrefslogtreecommitdiff
path: root/tests/test-no-fonts.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-09-26 20:41:19 -0400
committerMatthias Clasen <mclasen@redhat.com>2022-09-26 20:46:00 -0400
commite27ac590d44e87adac235c1b63429dc5f832f782 (patch)
tree4d473b24ef7c97d57ff89f9751c58baf30ff6696 /tests/test-no-fonts.c
parentf47e506bb0f692a4e2c6e498f2433cf781acb4eb (diff)
downloadpango-e27ac590d44e87adac235c1b63429dc5f832f782.tar.gz
Add a test for no-fontsno-font-fixes
Test that the layout is made up entirely of unknown glyphs if we have no font. The main point of this test is to ensure that we don't crash if analysis->font is NULL.
Diffstat (limited to 'tests/test-no-fonts.c')
-rw-r--r--tests/test-no-fonts.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/tests/test-no-fonts.c b/tests/test-no-fonts.c
new file mode 100644
index 00000000..c057874d
--- /dev/null
+++ b/tests/test-no-fonts.c
@@ -0,0 +1,109 @@
+/* Pango
+ * test-no-fonts.c: Check that lack of fonts is survivable
+ *
+ * Copyright (C) 2022 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 <glib.h>
+#include <string.h>
+#include <locale.h>
+
+#ifndef G_OS_WIN32
+#include <unistd.h>
+#endif
+
+#include "config.h"
+#include <pango/pangocairo.h>
+#include <pango/pangocairo-fc.h>
+#include <pango/pangofc-fontmap.h>
+#include "test-common.h"
+
+
+static void
+install_fonts (const char *dir)
+{
+ FcConfig *config;
+ PangoFontMap *map;
+ char *path;
+ gsize len;
+ char *conf;
+
+ map = g_object_new (PANGO_TYPE_CAIRO_FC_FONT_MAP, NULL);
+
+ config = FcConfigCreate ();
+
+ path = g_build_filename (dir, "fonts.conf", NULL);
+ g_file_get_contents (path, &conf, &len, NULL);
+
+ if (!FcConfigParseAndLoadFromMemory (config, (const FcChar8 *) conf, TRUE))
+ g_error ("Failed to parse fontconfig configuration");
+
+ g_free (conf);
+ g_free (path);
+
+ FcConfigAppFontAddDir (config, (const FcChar8 *) dir);
+ pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (map), config);
+ FcConfigDestroy (config);
+
+ pango_cairo_font_map_set_default (PANGO_CAIRO_FONT_MAP (map));
+
+ g_object_unref (map);
+}
+
+static void
+test_nofonts (void)
+{
+ PangoContext *context;
+ const char *text;
+ PangoLayout *layout;
+ int missing;
+
+ context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
+ layout = pango_layout_new (context);
+
+ text = "Schlaf, Kindlein schlaf! "
+ "Der Vater hüt' die Schaf, "
+ "die Mutter schúttelt's Bäumelein, "
+ "da fällt herab ein Träumelein. "
+ "Schlaf, Kindlein schlaf!";
+
+ pango_layout_set_text (layout, text, -1);
+ missing = pango_layout_get_unknown_glyphs_count (layout);
+ g_assert_cmpint (missing, ==, g_utf8_strlen (text, -1));
+
+ g_object_unref (layout);
+ g_object_unref (context);
+}
+
+int
+main (int argc, char *argv[])
+{
+ char *path;
+
+ setlocale (LC_ALL, "");
+
+ g_test_init (&argc, &argv, NULL);
+
+ path = g_test_build_filename (G_TEST_DIST, "nofonts", NULL);
+ install_fonts (path);
+ g_free (path);
+
+ g_test_add_func ("/layout/nofonts", test_nofonts);
+
+ return g_test_run ();
+}