[pango/pango2] Improve test font setup code



commit 37b612d9a4f55fcadb7d8177bd8fed8cdac37b61
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jun 15 16:06:13 2022 -0400

    Improve test font setup code
    
    Make it so that install_fonts() just works, regardless
    whether it is called before or after g_test_init().

 tests/test-break.c    | 16 ++--------------
 tests/test-common.c   |  9 ++++-----
 tests/test-common.h   |  4 ++--
 tests/test-fontsets.c | 24 +-----------------------
 tests/test-itemize.c  |  2 ++
 tests/test-layout.c   | 25 +------------------------
 tests/testserialize.c |  2 +-
 7 files changed, 13 insertions(+), 69 deletions(-)
---
diff --git a/tests/test-break.c b/tests/test-break.c
index f4f75a3b..74c8a4c6 100644
--- a/tests/test-break.c
+++ b/tests/test-break.c
@@ -363,13 +363,11 @@ main (int argc, char *argv[])
 {
   GDir *dir;
   GError *error = NULL;
-  char *opt_fonts = NULL;
   const char *name;
   char *path;
   gboolean opt_legend = 0;
   GOptionContext *option_context;
   GOptionEntry entries[] = {
-    { "fonts", 0, 0, G_OPTION_ARG_FILENAME, &opt_fonts, "Fonts to use", "DIR" },
     { "hex-chars", 0, 0, G_OPTION_ARG_NONE, &opt_hex_chars, "Print all chars in hex", NULL },
     { "legend", 0, 0, G_OPTION_ARG_NONE, &opt_legend, "Explain the output", NULL },
     { NULL, 0 },
@@ -387,12 +385,8 @@ main (int argc, char *argv[])
     }
   g_option_context_free (option_context);
 
-  if (opt_fonts)
-    {
-      install_fonts (opt_fonts);
-      context = pango_context_new ();
-      g_free (opt_fonts);
-    }
+  install_fonts ();
+  context = pango_context_new ();
 
   if (opt_legend)
     {
@@ -424,12 +418,6 @@ main (int argc, char *argv[])
 
   g_test_init (&argc, &argv, NULL);
 
-  if (!opt_fonts)
-    {
-      install_fonts (NULL);
-      context = pango_context_new ();
-    }
-
   path = g_test_build_filename (G_TEST_DIST, "breaks", NULL);
   dir = g_dir_open (path, 0, &error);
   g_free (path);
diff --git a/tests/test-common.c b/tests/test-common.c
index 861a06d6..031de0e3 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -414,7 +414,7 @@ add_synthetic_faces (PangoFontMap *map,
 }
 
 void
-install_fonts (const char *path)
+install_fonts (void)
 {
   PangoFontMap *map;
   GDir *dir;
@@ -422,12 +422,11 @@ install_fonts (const char *path)
   const char *name;
   GPtrArray *generic;
   GPtrArray *synthetic;
-  char *testpath = NULL;
+  char *path = NULL;
 
   map = pango_font_map_new ();
 
-  if (!path)
-    path = testpath = g_test_build_filename (G_TEST_DIST, "fonts", NULL);
+  path = g_build_filename (g_getenv ("G_TEST_SRCDIR"), "fonts", NULL);
 
   dir = g_dir_open (path, 0, &error);
 
@@ -475,7 +474,7 @@ install_fonts (const char *path)
   g_object_unref (map);
   g_dir_close (dir);
 
-  g_free (testpath);
+  g_free (path);
 }
 
 void
diff --git a/tests/test-common.h b/tests/test-common.h
index d29db299..2141100d 100644
--- a/tests/test-common.h
+++ b/tests/test-common.h
@@ -25,7 +25,7 @@ void print_attr_list (PangoAttrList  *attrs,
 
 const char *get_script_name (GUnicodeScript s);
 
-void install_fonts (const char *path);
-void dump_fonts (void);
+void    install_fonts      (void);
+void    dump_fonts         (void);
 
 #endif
diff --git a/tests/test-fontsets.c b/tests/test-fontsets.c
index 62062f84..6701d647 100644
--- a/tests/test-fontsets.c
+++ b/tests/test-fontsets.c
@@ -121,31 +121,12 @@ main (int argc, char *argv[])
 {
   GDir *dir;
   GError *error = NULL;
-  char *opt_fonts = NULL;
   const char *name;
   char *path;
-  GOptionContext *option_context;
-  GOptionEntry entries[] = {
-    { "fonts", 0, 0, G_OPTION_ARG_FILENAME, &opt_fonts, "Fonts to use", "DIR" },
-    { NULL, 0 },
-  };
 
   setlocale (LC_ALL, "");
-  option_context = g_option_context_new ("");
-  g_option_context_add_main_entries (option_context, entries, NULL);
-  g_option_context_set_ignore_unknown_options (option_context, TRUE);
-  if (!g_option_context_parse (option_context, &argc, &argv, &error))
-    {
-      g_error ("failed to parse options: %s", error->message);
-      return 1;
-    }
-  g_option_context_free (option_context);
 
-  if (opt_fonts)
-    {
-      install_fonts (opt_fonts);
-      g_free (opt_fonts);
-    }
+  install_fonts ();
 
  /* allow to easily generate expected output for new test cases */
   if (argc > 1 && argv[1][0] != '-')
@@ -170,9 +151,6 @@ main (int argc, char *argv[])
 
   g_test_init (&argc, &argv, NULL);
 
-  if (!opt_fonts)
-    install_fonts (NULL);
-
   path = g_test_build_filename (G_TEST_DIST, "fontsets", NULL);
   dir = g_dir_open (path, 0, &error);
   g_free (path);
diff --git a/tests/test-itemize.c b/tests/test-itemize.c
index daefff17..02ebf14d 100644
--- a/tests/test-itemize.c
+++ b/tests/test-itemize.c
@@ -332,6 +332,8 @@ main (int argc, char *argv[])
   const char *name;
   char *path;
 
+  install_fonts ();
+
   context = pango_context_new ();
   pango_context_set_language (context, pango_language_from_string ("en-us"));
 
diff --git a/tests/test-layout.c b/tests/test-layout.c
index c99b94f3..54bfbfeb 100644
--- a/tests/test-layout.c
+++ b/tests/test-layout.c
@@ -102,32 +102,12 @@ main (int argc, char *argv[])
 {
   GDir *dir;
   GError *error = NULL;
-  char *opt_fonts = NULL;
   const char *name;
   char *path;
-  GOptionContext *option_context;
-  GOptionEntry entries[] = {
-    { "fonts", 0, 0, G_OPTION_ARG_FILENAME, &opt_fonts, "Fonts to use", "DIR" },
-    { NULL, 0 },
-  };
 
   setlocale (LC_ALL, "");
-  option_context = g_option_context_new ("");
-  g_option_context_add_main_entries (option_context, entries, NULL);
-  g_option_context_set_ignore_unknown_options (option_context, TRUE);
 
-  if (!g_option_context_parse (option_context, &argc, &argv, &error))
-    {
-      g_error ("failed to parse options: %s", error->message);
-      return 1;
-    }
-  g_option_context_free (option_context);
-
-  if (opt_fonts)
-    {
-      install_fonts (opt_fonts);
-      g_free (opt_fonts);
-    }
+  install_fonts ();
 
   /* allow to easily generate expected output for new test cases */
   if (argc > 1 && argv[1][0] != '-')
@@ -163,9 +143,6 @@ main (int argc, char *argv[])
 
   g_test_init (&argc, &argv, NULL);
 
-  if (!opt_fonts)
-    install_fonts (NULL);
-
   path = g_test_build_filename (G_TEST_DIST, "layouts", NULL);
   dir = g_dir_open (path, 0, &error);
   g_free (path);
diff --git a/tests/testserialize.c b/tests/testserialize.c
index da2c78d7..0b8e7824 100644
--- a/tests/testserialize.c
+++ b/tests/testserialize.c
@@ -437,7 +437,7 @@ main (int argc, char *argv[])
 {
   g_test_init (&argc, &argv, NULL);
 
-  install_fonts (NULL);
+  install_fonts ();
 
   g_test_add_func ("/serialize/attr-list", test_serialize_attr_list);
   g_test_add_func ("/serialize/tab-array", test_serialize_tab_array);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]