summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/markup-parse.c10
-rw-r--r--tests/test-break.c21
-rw-r--r--tests/test-font.c34
-rw-r--r--tests/test-itemize.c20
-rw-r--r--tests/test-layout.c13
-rw-r--r--tests/test-shape.c3
-rw-r--r--tests/testboundaries.c111
-rw-r--r--tests/testboundaries_ucd.c80
-rw-r--r--tests/testscript.c40
9 files changed, 123 insertions, 209 deletions
diff --git a/tests/markup-parse.c b/tests/markup-parse.c
index dff0ccc4..5f1454a1 100644
--- a/tests/markup-parse.c
+++ b/tests/markup-parse.c
@@ -48,12 +48,8 @@ test_file (const gchar *filename, GString *string)
char *str;
int start, end;
- if (!g_file_get_contents (filename, &contents, &length, &error))
- {
- fprintf (stderr, "%s\n", error->message);
- g_error_free (error);
- return;
- }
+ g_file_get_contents (filename, &contents, &length, &error);
+ g_assert_no_error (error);
ret = pango_parse_markup (contents, length, 0, &attrs, &text, NULL, &error);
g_free (contents);
@@ -152,7 +148,7 @@ main (int argc, char *argv[])
string = g_string_sized_new (0);
test_file (argv[1], string);
- g_print ("%s", string->str);
+ g_test_message ("%s", string->str);
return 0;
}
diff --git a/tests/test-break.c b/tests/test-break.c
index 8549b678..f4faaab3 100644
--- a/tests/test-break.c
+++ b/tests/test-break.c
@@ -51,12 +51,8 @@ test_file (const gchar *filename, GString *string)
PangoAttrList *attributes;
PangoLayout *layout;
- if (!g_file_get_contents (filename, &contents, &length, &error))
- {
- fprintf (stderr, "%s\n", error->message);
- g_error_free (error);
- return;
- }
+ g_file_get_contents (filename, &contents, &length, &error);
+ g_assert_no_error (error);
test = contents;
@@ -68,12 +64,8 @@ test_file (const gchar *filename, GString *string)
len = g_utf8_strlen (test, -1) + 1;
attrs = g_new (PangoLogAttr, len);
- if (!pango_parse_markup (test, -1, 0, &attributes, &text, NULL, &error))
- {
- fprintf (stderr, "%s\n", error->message);
- g_error_free (error);
- return;
- }
+ pango_parse_markup (test, -1, 0, &attributes, &text, NULL, &error);
+ g_assert_no_error (error);
layout = pango_layout_new (context);
pango_layout_set_text (layout, text, length);
@@ -260,7 +252,8 @@ test_break (gconstpointer d)
if (diff && diff[0])
{
- g_printerr ("Contents don't match expected contents:\n%s", diff);
+ g_test_message ("Contents don't match expected contents");
+ g_test_message ("%s", diff);
g_test_fail ();
g_free (diff);
}
@@ -291,7 +284,7 @@ main (int argc, char *argv[])
string = g_string_sized_new (0);
test_file (argv[1], string);
- printf ("%s", string->str);
+ g_test_message ("%s", string->str);
return 0;
}
diff --git a/tests/test-font.c b/tests/test-font.c
index 5ef6cc39..486504f9 100644
--- a/tests/test-font.c
+++ b/tests/test-font.c
@@ -133,25 +133,21 @@ test_metrics (void)
metrics = pango_context_get_metrics (context, desc, pango_language_get_default ());
- g_test_message ("%s metrics\n"
- "\tascent %d\n"
- "\tdescent %d\n"
- "\theight %d\n"
- "\tchar width %d\n"
- "\tdigit width %d\n"
- "\tunderline position %d\n"
- "\tunderline thickness %d\n"
- "\tstrikethrough position %d\n"
- "\tstrikethrough thickness %d\n",
- str,
- pango_font_metrics_get_ascent (metrics),
- pango_font_metrics_get_descent (metrics),
- pango_font_metrics_get_height (metrics),
- pango_font_metrics_get_approximate_char_width (metrics),
- pango_font_metrics_get_approximate_digit_width (metrics),
- pango_font_metrics_get_underline_position (metrics),
- pango_font_metrics_get_underline_thickness (metrics),
- pango_font_metrics_get_strikethrough_position (metrics),
+ g_test_message ("%s metrics", str);
+ g_test_message ("\tascent: %d", pango_font_metrics_get_ascent (metrics));
+ g_test_message ("\tdescent: %d", pango_font_metrics_get_descent (metrics));
+ g_test_message ("\theight: %d", pango_font_metrics_get_height (metrics));
+ g_test_message ("\tchar width: %d",
+ pango_font_metrics_get_approximate_char_width (metrics));
+ g_test_message ("\tdigit width: %d",
+ pango_font_metrics_get_approximate_digit_width (metrics));
+ g_test_message ("\tunderline position: %d",
+ pango_font_metrics_get_underline_position (metrics));
+ g_test_message ("\tunderline thickness: %d",
+ pango_font_metrics_get_underline_thickness (metrics));
+ g_test_message ("\tstrikethrough position: %d",
+ pango_font_metrics_get_strikethrough_position (metrics));
+ g_test_message ("\tstrikethrough thickness: %d",
pango_font_metrics_get_strikethrough_thickness (metrics));
pango_font_metrics_unref (metrics);
diff --git a/tests/test-itemize.c b/tests/test-itemize.c
index d66c40d1..167e4e80 100644
--- a/tests/test-itemize.c
+++ b/tests/test-itemize.c
@@ -118,12 +118,8 @@ test_file (const gchar *filename, GString *string)
GList *items, *l;
const char *sep = "";
- if (!g_file_get_contents (filename, &contents, &length, &error))
- {
- fprintf (stderr, "%s\n", error->message);
- g_error_free (error);
- return;
- }
+ g_file_get_contents (filename, &contents, &length, &error);
+ g_assert_no_error (error);
test = contents;
@@ -131,13 +127,8 @@ test_file (const gchar *filename, GString *string)
while (test[0] == '#')
test = strchr (test, '\n') + 1;
-
- if (!pango_parse_markup (test, -1, 0, &attrs, &text, NULL, &error))
- {
- fprintf (stderr, "%s\n", error->message);
- g_error_free (error);
- return;
- }
+ pango_parse_markup (test, -1, 0, &attrs, &text, NULL, &error);
+ g_assert_no_error (error);
s1 = g_string_new ("Items: ");
s2 = g_string_new ("Font: ");
@@ -257,7 +248,8 @@ test_itemize (gconstpointer d)
if (diff && diff[0])
{
- g_printerr ("Contents don't match expected contents:\n%s", diff);
+ g_test_message ("Contents don't match expected contents");
+ g_test_message ("%s", diff);
g_test_fail ();
g_free (diff);
}
diff --git a/tests/test-layout.c b/tests/test-layout.c
index cbbffd2c..2fc78240 100644
--- a/tests/test-layout.c
+++ b/tests/test-layout.c
@@ -238,12 +238,8 @@ test_file (const gchar *filename, GString *string)
PangoWrapMode wrap = PANGO_WRAP_WORD;
PangoFontDescription *desc;
- if (!g_file_get_contents (filename, &contents, &length, &error))
- {
- fprintf (stderr, "%s\n", error->message);
- g_error_free (error);
- return;
- }
+ g_file_get_contents (filename, &contents, &length, &error);
+ g_assert_no_error (error);
p = strchr (contents, '\n');
g_assert (p);
@@ -319,7 +315,8 @@ test_layout (gconstpointer d)
if (diff && diff[0])
{
- g_printerr ("Contents don't match expected contents:\n%s", diff);
+ g_test_message ("Contents don't match expected contents");
+ g_test_message ("%s", diff);
g_test_fail ();
g_free (diff);
}
@@ -350,7 +347,7 @@ main (int argc, char *argv[])
string = g_string_sized_new (0);
test_file (argv[1], string);
- g_print ("%s", string->str);
+ g_test_message ("%s", string->str);
return 0;
}
diff --git a/tests/test-shape.c b/tests/test-shape.c
index 6c1ae296..c2488dbf 100644
--- a/tests/test-shape.c
+++ b/tests/test-shape.c
@@ -319,7 +319,8 @@ test_shape (gconstpointer d)
if (diff && diff[0])
{
- g_printerr ("Contents don't match expected contents:\n%s", diff);
+ g_test_message ("Contents don't match expected contents");
+ g_test_message ("%s", diff);
g_test_fail ();
g_free (diff);
}
diff --git a/tests/testboundaries.c b/tests/testboundaries.c
index 75da772e..2390bb28 100644
--- a/tests/testboundaries.c
+++ b/tests/testboundaries.c
@@ -46,27 +46,6 @@ static gunichar current_wc = 0;
static const char *line_start = NULL;
static const char *line_end = NULL;
-static void fail (const char *format, ...) G_GNUC_PRINTF (1, 2) G_GNUC_NORETURN;
-static void fail (const char *format, ...)
-{
- char *str;
- char *line_text;
-
- va_list args;
-
- va_start (args, format);
- str = g_strdup_vprintf (format, args);
- va_end (args);
-
- line_text = g_strndup (line_start, line_end - line_start);
-
- fprintf (stderr, "line %d offset %d char is " CHFORMAT ": %s\n (line is '%s')\n", line, offset, current_wc, str, line_text);
- g_free (str);
- g_free (line_text);
-
- exit (1);
-}
-
typedef void (* CharForeachFunc) (gunichar wc,
gunichar prev_wc,
gunichar next_wc,
@@ -175,28 +154,36 @@ check_line_char (gunichar wc,
{
if (prev_wc == '\r')
{
- if (attr->is_line_break)
- fail ("line break between \\r and \\n");
+ g_test_message ("Do not line break between \\r and \\n");
+ g_assert_false (attr->is_line_break);
}
- if (next_attr && !next_attr->is_line_break)
- fail ("no line break after \\n");
+ if (next_attr != NULL)
+ {
+ g_test_message ("Line break after \\n");
+ g_assert_true (next_attr->is_line_break);
+ }
}
- if (attr->is_line_break && prev_wc == 0)
- fail ("first char in string should not be marked as a line break");
+ if (attr->is_line_break)
+ {
+ g_test_message ("first char in string should not be marked as a line break");
+ g_assert_false (prev_wc == 0);
+ }
if (break_type == G_UNICODE_BREAK_SPACE)
{
- if (attr->is_line_break && prev_attr != NULL &&
- !attr->is_mandatory_break &&
- !(next_wc && g_unichar_break_type (next_wc) == G_UNICODE_BREAK_COMBINING_MARK))
- fail ("can't break lines before a space unless a mandatory break char precedes it or a combining mark follows; prev char was " CHFORMAT, prev_wc);
+ g_test_message ("can't break lines before a space unless a mandatory break char precedes it or a combining mark follows; prev char was: " CHFORMAT, prev_wc);
+ g_assert_false (attr->is_line_break && prev_attr != NULL &&
+ !attr->is_mandatory_break &&
+ !(next_wc && g_unichar_break_type (next_wc) == G_UNICODE_BREAK_COMBINING_MARK));
}
- if (attr->is_mandatory_break && !attr->is_line_break)
- fail ("mandatory breaks must also be marked as regular breaks");
-
+ if (attr->is_mandatory_break)
+ {
+ g_test_message ("mandatory breaks must also be marked as regular breaks");
+ g_assert_true (attr->is_line_break);
+ }
/* FIXME use the break tables from break.c to automatically
@@ -204,23 +191,23 @@ check_line_char (gunichar wc,
* be that hard to do.
*/
- if (break_type == G_UNICODE_BREAK_OPEN_PUNCTUATION &&
- prev_break_type == G_UNICODE_BREAK_OPEN_PUNCTUATION &&
- attr->is_line_break &&
- !attr->is_mandatory_break)
- fail ("can't break between two open punctuation chars");
-
- if (break_type == G_UNICODE_BREAK_CLOSE_PUNCTUATION &&
- prev_break_type == G_UNICODE_BREAK_CLOSE_PUNCTUATION &&
- attr->is_line_break &&
- !attr->is_mandatory_break)
- fail ("can't break between two close punctuation chars");
-
- if (break_type == G_UNICODE_BREAK_QUOTATION &&
- prev_break_type == G_UNICODE_BREAK_ALPHABETIC &&
- attr->is_line_break &&
- !attr->is_mandatory_break)
- fail ("can't break letter-quotemark sequence");
+ g_test_message ("can't break between two open punctuation chars");
+ g_assert_false (break_type == G_UNICODE_BREAK_OPEN_PUNCTUATION &&
+ prev_break_type == G_UNICODE_BREAK_OPEN_PUNCTUATION &&
+ attr->is_line_break &&
+ !attr->is_mandatory_break);
+
+ g_test_message ("can't break between two close punctuation chars");
+ g_assert_false (break_type == G_UNICODE_BREAK_CLOSE_PUNCTUATION &&
+ prev_break_type == G_UNICODE_BREAK_CLOSE_PUNCTUATION &&
+ attr->is_line_break &&
+ !attr->is_mandatory_break);
+
+ g_test_message ("can't break letter-quotemark sequence");
+ g_assert_false (break_type == G_UNICODE_BREAK_QUOTATION &&
+ prev_break_type == G_UNICODE_BREAK_ALPHABETIC &&
+ attr->is_line_break &&
+ !attr->is_mandatory_break);
}
static void
@@ -290,8 +277,7 @@ check_invariants (const char *text)
int len;
PangoLogAttr *attrs;
- if (!g_utf8_validate (text, -1, NULL))
- fail ("Invalid UTF-8 in test text");
+ g_assert_true (g_utf8_validate (text, -1, NULL));
len = g_utf8_strlen (text, -1);
attrs = g_new0 (PangoLogAttr, len + 1);
@@ -318,24 +304,20 @@ check_invariants (const char *text)
static void
test_boundaries (void)
{
- gchar *text;
- const gchar *filename;
-#if GLIB_CHECK_VERSION(2, 37, 2)
+ const char *filename;
+ GError *error = NULL;
+ char *text;
+
filename = g_test_get_filename (G_TEST_DIST, "boundaries.utf8", NULL);
-#else
- filename = SRCDIR "/boundaries.utf8";
-#endif
- g_print ("sample file: %s\n", filename);
+ g_test_message ("sample file: %s\n", filename);
- if (!g_file_get_contents (filename, &text, NULL, NULL))
- fail ("Couldn't open sample text file");
+ g_file_get_contents (filename, &text, NULL, &error);
+ g_assert_no_error (error);
check_invariants (text);
g_free (text);
-
- printf ("testboundaries passed\n");
}
int
@@ -347,4 +329,3 @@ main (int argc, char *argv[])
return g_test_run ();
}
-
diff --git a/tests/testboundaries_ucd.c b/tests/testboundaries_ucd.c
index 53f7b4cb..ee5617bc 100644
--- a/tests/testboundaries_ucd.c
+++ b/tests/testboundaries_ucd.c
@@ -230,32 +230,28 @@ do_test (const gchar *filename,
error = NULL;
channel = g_io_channel_new_file (filename, "r", &error);
- if (!channel)
+ if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
{
- if (error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT)
- {
- g_print ("%s not found. Skipping test.\n", filename);
- goto done;
- }
- else
- {
- g_printerr ("%s: %s\n", filename, error->message);
- exit (1);
- }
+ g_test_skip ("Test file not found");
+ return;
}
- g_print ("Testing %s.\n", filename);
+
+ g_assert_no_error (error);
+
+ g_test_message ("Filename: %s", filename);
i = 1;
for (;;)
{
error = NULL;
status = g_io_channel_read_line (channel, &line, &length, &terminator_pos, &error);
+ g_assert_no_error (error);
switch (status)
{
case G_IO_STATUS_ERROR:
- g_printerr ("%s: %s\n", filename, error->message);
- exit (1);
+ failed = TRUE;
+ goto done;
case G_IO_STATUS_EOF:
goto done;
@@ -268,11 +264,8 @@ do_test (const gchar *filename,
break;
}
- if (! parse_line (line, bits, &string, &expected_attrs, &num_attrs))
- {
- g_printerr ("%s: error parsing line %d: %s\n", filename, i, line);
- exit (1);
- }
+ g_test_message ("Parsing line: %s", line);
+ g_assert_true (parse_line (line, bits, &string, &expected_attrs, &num_attrs));
if (num_attrs > 0)
{
@@ -293,11 +286,10 @@ do_test (const gchar *filename,
comments = "";
}
- g_printerr ("%s: line %d failed\n"
- " expected: %s\n"
- " returned: %s\n"
- " comments: %s\n\n",
- filename, i, line, str, comments);
+ g_test_message ("%s: line %d failed", filename, i);
+ g_test_message (" expected: %s", line);
+ g_test_message (" returned: %s", str);
+ g_test_message (" comments: %s", comments);
g_free (str);
failed = TRUE;
@@ -316,20 +308,16 @@ done:
if (error)
g_error_free (error);
- g_assert (!failed);
+ g_assert_true (!failed);
}
static void
test_grapheme_break (void)
{
- const gchar *filename;
+ const char *filename;
AttrBits bits;
-#if GLIB_CHECK_VERSION(2, 37, 2)
filename = g_test_get_filename (G_TEST_DIST, "GraphemeBreakTest.txt", NULL);
-#else
- filename = SRCDIR "/GraphemeBreakTest.txt";
-#endif
bits.bits = 0;
bits.attr.is_cursor_position = 1;
do_test (filename, bits);
@@ -338,14 +326,10 @@ test_grapheme_break (void)
static void
test_emoji_break (void)
{
- const gchar *filename;
+ const char *filename;
AttrBits bits;
-#if GLIB_CHECK_VERSION(2, 37, 2)
filename = g_test_get_filename (G_TEST_DIST, "EmojiBreakTest.txt", NULL);
-#else
- filename = SRCDIR "/EmojiBreakTest.txt";
-#endif
bits.bits = 0;
bits.attr.is_cursor_position = 1;
do_test (filename, bits);
@@ -354,14 +338,10 @@ test_emoji_break (void)
static void
test_char_break (void)
{
- const gchar *filename;
+ const char *filename;
AttrBits bits;
-#if GLIB_CHECK_VERSION(2, 37, 2)
filename = g_test_get_filename (G_TEST_DIST, "CharBreakTest.txt", NULL);
-#else
- filename = SRCDIR "/CharBreakTest.txt";
-#endif
bits.bits = 0;
bits.attr.is_char_break = 1;
do_test (filename, bits);
@@ -370,14 +350,10 @@ test_char_break (void)
static void
test_word_break (void)
{
- const gchar *filename;
+ const char *filename;
AttrBits bits;
-#if GLIB_CHECK_VERSION(2, 37, 2)
filename = g_test_get_filename (G_TEST_DIST, "WordBreakTest.txt", NULL);
-#else
- filename = SRCDIR "/WordBreakTest.txt";
-#endif
bits.bits = 0;
bits.attr.is_word_boundary = 1;
do_test (filename, bits);
@@ -386,14 +362,10 @@ test_word_break (void)
static void
test_sentence_break (void)
{
- const gchar *filename;
+ const char *filename;
AttrBits bits;
-#if GLIB_CHECK_VERSION(2, 37, 2)
filename = g_test_get_filename (G_TEST_DIST, "SentenceBreakTest.txt", NULL);
-#else
- filename = SRCDIR "/SentenceBreakTest.txt";
-#endif
bits.bits = 0;
bits.attr.is_sentence_boundary = 1;
do_test (filename, bits);
@@ -402,17 +374,15 @@ test_sentence_break (void)
static void
test_line_break (void)
{
- const gchar *filename;
+ const char *filename;
AttrBits bits;
-#if GLIB_CHECK_VERSION(2, 37, 2)
+
filename = g_test_get_filename (G_TEST_DIST, "LineBreakTest.txt", NULL);
-#else
- filename = SRCDIR "/LineBreakTest.txt";
-#endif
bits.bits = 0;
bits.attr.is_line_break = 1;
bits.attr.is_mandatory_break = 1;
+
do_test (filename, bits);
}
diff --git a/tests/testscript.c b/tests/testscript.c
index aa610b44..33e8ad2e 100644
--- a/tests/testscript.c
+++ b/tests/testscript.c
@@ -60,18 +60,6 @@
#include "pango/pango-script.h"
-#undef VERBOSE
-
-#define ASSERT(stmt) G_STMT_START { \
- if (stmt) { } \
- else \
- { \
- g_warning ("%s:%d (%s): assertion '%s' failed", \
- __FILE__, __LINE__, G_STRFUNC, #stmt); \
- exit (1); \
- } \
-} G_STMT_END
-
typedef struct
{
const char *run_text_escaped;
@@ -170,9 +158,7 @@ test_script_iter (void)
iter = pango_script_iter_new (all->str, -1);
-#ifdef VERBOSE
- g_print ("Total length: %d\n", all->len);
-#endif
+ g_test_message ("Total length: %" G_GSIZE_FORMAT "\n", all->len);
pos = all->str;
for (i = 0; i < G_N_ELEMENTS(test_data); i++)
@@ -181,16 +167,18 @@ test_script_iter (void)
gboolean result;
pango_script_iter_get_range (iter, &start, &end, &script);
-#ifdef VERBOSE
- g_print ("Range: %d-%d: %d\n", start - all->str, end - all->str, script);
-#endif
- ASSERT (start == pos);
- ASSERT (end == next_pos);
- ASSERT (script == test_data[i].run_code);
+ g_test_message ("Range: %d-%d: %d\n",
+ (int) (start - all->str),
+ (int) (end - all->str),
+ script);
+
+ g_assert_true (start == pos);
+ g_assert_true (end == next_pos);
+ g_assert_true (script == test_data[i].run_code);
result = pango_script_iter_next (iter);
- ASSERT (result == (i != G_N_ELEMENTS (test_data) - 1));
+ g_assert_true (result == (i != G_N_ELEMENTS (test_data) - 1));
pos = next_pos;
}
@@ -204,10 +192,10 @@ test_script_iter (void)
pango_script_iter_get_range (iter, &start, &end, &script);
- ASSERT (start == all->str);
- ASSERT (end == all->str);
- ASSERT (script == PANGO_SCRIPT_COMMON);
- ASSERT (!pango_script_iter_next (iter));
+ g_assert_true (start == all->str);
+ g_assert_true (end == all->str);
+ g_assert_true (script == PANGO_SCRIPT_COMMON);
+ g_assert_true (!pango_script_iter_next (iter));
pango_script_iter_free (iter);