summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-07-10 23:28:47 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-07-10 23:28:47 +0000
commit5e20f517a297344c1424f78d9a6784a02b2f82da (patch)
treec48ee46794a4d3d8a5ae79fcbee4dba7c84c6143
parent6a28e306a4b4a779aa62f0eab4e2f1c70241345c (diff)
parent7af6d5966fa48d494037c49658a2a526a646fa45 (diff)
downloadpango-5e20f517a297344c1424f78d9a6784a02b2f82da.tar.gz
Merge branch 'matthiasc/for-master' into 'master'
tests: Avoid a possible invalid access See merge request GNOME/pango!376
-rw-r--r--tests/meson.build1
-rw-r--r--tests/test-break.c2
-rw-r--r--tests/test-font.c1
-rw-r--r--tests/test-itemize.c30
-rw-r--r--tests/test-layout.c41
-rw-r--r--tests/test-shape.c1
6 files changed, 64 insertions, 12 deletions
diff --git a/tests/meson.build b/tests/meson.build
index baf5ad6b..841a78eb 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -16,6 +16,7 @@ test_env = environment()
test_env.set('srcdir', meson.current_source_dir())
test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
+test_env.set('LC_ALL', 'en_US.UTF-8')
tests = [
[ 'test-bidi' ],
diff --git a/tests/test-break.c b/tests/test-break.c
index 0158bd40..66c207a5 100644
--- a/tests/test-break.c
+++ b/tests/test-break.c
@@ -292,7 +292,7 @@ test_break (gconstpointer d)
gchar *diff;
char *old_locale = g_strdup (setlocale (LC_ALL, NULL));
- setlocale (LC_ALL, "en_US.utf8");
+ setlocale (LC_ALL, "en_US.UTF-8");
if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL)
{
char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping break %s", filename);
diff --git a/tests/test-font.c b/tests/test-font.c
index 3c5f3070..f291cec8 100644
--- a/tests/test-font.c
+++ b/tests/test-font.c
@@ -463,7 +463,6 @@ test_match (void)
int
main (int argc, char *argv[])
{
- g_setenv ("LC_ALL", "C", TRUE);
setlocale (LC_ALL, "");
g_test_init (&argc, &argv, NULL);
diff --git a/tests/test-itemize.c b/tests/test-itemize.c
index d1447a0f..0a8515b8 100644
--- a/tests/test-itemize.c
+++ b/tests/test-itemize.c
@@ -236,19 +236,44 @@ test_itemize (gconstpointer d)
GError *error = NULL;
GString *dump;
gchar *diff;
+ PangoFontFamily **families;
+ int n_families;
+ gboolean found_cantarell;
- const char *old_locale = setlocale (LC_ALL, NULL);
- setlocale (LC_ALL, "en_US.utf8");
+ char *old_locale = g_strdup (setlocale (LC_ALL, NULL));
+ setlocale (LC_ALL, "en_US.UTF-8");
if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL)
{
char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping itemization %s", filename);
g_test_skip (msg);
g_free (msg);
+ g_free (old_locale);
return;
}
context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
+ found_cantarell = FALSE;
+ pango_context_list_families (context, &families, &n_families);
+ for (int i = 0; i < n_families; i++)
+ {
+ if (strcmp (pango_font_family_get_name (families[i]), "Cantarell") == 0)
+ {
+ found_cantarell = TRUE;
+ break;
+ }
+ }
+ g_free (families);
+
+ if (!found_cantarell)
+ {
+ char *msg = g_strdup_printf ("Cantarell font not available, skipping itemization %s", filename);
+ g_test_skip (msg);
+ g_free (msg);
+ g_free (old_locale);
+ return;
+ }
+
expected_file = get_expected_filename (filename);
dump = g_string_sized_new (0);
@@ -259,6 +284,7 @@ test_itemize (gconstpointer d)
g_assert_no_error (error);
setlocale (LC_ALL, old_locale);
+ g_free (old_locale);
if (diff && diff[0])
{
diff --git a/tests/test-layout.c b/tests/test-layout.c
index ca9e5da5..8a1054b4 100644
--- a/tests/test-layout.c
+++ b/tests/test-layout.c
@@ -461,17 +461,18 @@ test_file (const char *filename, GString *string)
/* Some checks on extents - we have to be careful here, since we
* don't want to depend on font metrics.
*/
+ pango_layout_get_size (layout, &width, &height);
pango_layout_get_extents (layout, &ink_rect, &logical_rect);
+ g_assert_cmpint (width, ==, logical_rect.width);
+ g_assert_cmpint (height, ==, logical_rect.height);
+
pango_extents_to_pixels (&ink_rect, NULL);
pango_extents_to_pixels (&logical_rect, NULL);
pango_layout_get_pixel_extents (layout, &ink_rect1, &logical_rect1);
- pango_layout_get_size (layout, &width, &height);
pango_layout_get_pixel_size (layout, &width1, &height1);
assert_rectangle_equal (&ink_rect, &ink_rect1);
assert_rectangle_equal (&logical_rect, &logical_rect1);
- g_assert_cmpint (PANGO_PIXELS (width), ==, logical_rect.width);
- g_assert_cmpint (PANGO_PIXELS (height), ==, logical_rect.height);
g_assert_cmpint (width1, ==, logical_rect1.width);
g_assert_cmpint (height1, ==, logical_rect1.height);
@@ -702,20 +703,45 @@ test_layout (gconstpointer d)
GError *error = NULL;
GString *dump;
gchar *diff;
+ PangoFontFamily **families;
+ int n_families;
+ gboolean found_cantarell;
- const char *old_locale = setlocale (LC_ALL, NULL);
- setlocale (LC_ALL, "en_US.utf8");
+ char *old_locale = g_strdup (setlocale (LC_ALL, NULL));
+ setlocale (LC_ALL, "en_US.UTF-8");
if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL)
{
char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping layout %s", filename);
g_test_skip (msg);
g_free (msg);
+ g_free (old_locale);
return;
}
if (context == NULL)
context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
+ found_cantarell = FALSE;
+ pango_context_list_families (context, &families, &n_families);
+ for (int i = 0; i < n_families; i++)
+ {
+ if (strcmp (pango_font_family_get_name (families[i]), "Cantarell") == 0)
+ {
+ found_cantarell = TRUE;
+ break;
+ }
+ }
+ g_free (families);
+
+ if (!found_cantarell)
+ {
+ char *msg = g_strdup_printf ("Cantarell font not available, skipping itemization %s", filename);
+ g_test_skip (msg);
+ g_free (msg);
+ g_free (old_locale);
+ return;
+ }
+
expected_file = get_expected_filename (filename);
dump = g_string_sized_new (0);
@@ -726,6 +752,7 @@ test_layout (gconstpointer d)
g_assert_no_error (error);
setlocale (LC_ALL, old_locale);
+ g_free (old_locale);
if (diff && diff[0])
{
@@ -755,6 +782,8 @@ main (int argc, char *argv[])
const gchar *name;
gchar *path;
+ setlocale (LC_ALL, "");
+
if (g_getenv ("PANGO_TEST_SHOW_FONT"))
opt_show_font = TRUE;
@@ -763,8 +792,6 @@ main (int argc, char *argv[])
{
GString *string;
- setlocale (LC_ALL, "en_US.utf8");
-
string = g_string_sized_new (0);
test_file (argv[1], string);
g_print ("%s", string->str);
diff --git a/tests/test-shape.c b/tests/test-shape.c
index be3e4415..a04291e4 100644
--- a/tests/test-shape.c
+++ b/tests/test-shape.c
@@ -337,7 +337,6 @@ main (int argc, char *argv[])
const gchar *name;
gchar *path;
- g_setenv ("LC_ALL", "en_US.UTF-8", TRUE);
setlocale (LC_ALL, "");
g_test_init (&argc, &argv, NULL);