summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2008-09-27 01:43:29 +0000
committerDan Winship <danw@src.gnome.org>2008-09-27 01:43:29 +0000
commit5c53925ed08402549be0c306cd0544af209f8934 (patch)
tree19a6eb8750ba1d7076849e9afce98f4278f7150f /tests
parent764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0 (diff)
downloadglib-5c53925ed08402549be0c306cd0544af209f8934.tar.gz
Bug 553447 $(Q#|(B g_assert_no_error()
* glib/gtestutils.h (g_assert_no_error, g_assert_error): Macros to assert that a GError is not set, or else is set to a particular error. * glib/gtestutils.c (g_assertion_message_error): utility for those macros * glib/tests/keyfile.c: * tests/asyncqueue-test.c: * tests/bookmarkfile-test.c: * tests/convert-test.c: * tests/file-test.c: Use g_assert_error/g_assert_no_error svn path=/trunk/; revision=7555
Diffstat (limited to 'tests')
-rw-r--r--tests/asyncqueue-test.c2
-rw-r--r--tests/bookmarkfile-test.c87
-rw-r--r--tests/convert-test.c44
-rw-r--r--tests/file-test.c4
4 files changed, 39 insertions, 98 deletions
diff --git a/tests/asyncqueue-test.c b/tests/asyncqueue-test.c
index da65d7531..eb38d9ec5 100644
--- a/tests/asyncqueue-test.c
+++ b/tests/asyncqueue-test.c
@@ -162,7 +162,7 @@ main (int argc, char *argv[])
g_thread_pool_push (thread_pool, GINT_TO_POINTER (i), &error);
- g_assert (error == NULL);
+ g_assert_no_error (error);
}
if (!SORT_QUEUE_AFTER) {
diff --git a/tests/bookmarkfile-test.c b/tests/bookmarkfile-test.c
index 06019ca1f..40e9a0581 100644
--- a/tests/bookmarkfile-test.c
+++ b/tests/bookmarkfile-test.c
@@ -16,68 +16,6 @@
#define TEST_APP_NAME "bookmarkfile-test"
#define TEST_APP_EXEC "bookmarkfile-test %f"
-static void
-test_assert_empty_error (GError **error)
-{
- if (*error != NULL)
- {
- g_warning ("Unexpected error (d: %s, c: %d): %s\n",
- g_quark_to_string ((*error)->domain),
- (*error)->code,
- (*error)->message);
- g_error_free (*error);
-
- g_assert_not_reached ();
- }
-}
-
-static void
-test_assert_not_empty_error (GError **error,
- GQuark domain,
- gint code)
-{
- if (*error == NULL)
- {
- g_warning ("Unexpected success (%s domain expected)\n",
- g_quark_to_string (domain));
-
- g_assert_not_reached ();
- }
-
- if ((*error)->domain != domain)
- {
- g_warning ("Unexpected domain %s (%s domain expected)\n",
- g_quark_to_string ((*error)->domain),
- g_quark_to_string (domain));
-
- g_assert_not_reached ();
- }
-
- if ((*error)->code != code)
- {
- g_warning ("Unexpected code %d (%d code expected)\n",
- (*error)->code,
- code);
-
- g_assert_not_reached ();
- }
-
- g_error_free (*error);
- *error = NULL;
-}
-
-static void
-test_assert_str_equal (const gchar *str,
- const gchar *cmp)
-{
- if (strcmp (str, cmp) != 0)
- {
- g_warning ("Unexpected string '%s' ('%s' expected)\n", str, cmp);
-
- g_assert_not_reached ();
- }
-}
-
static gboolean
test_load (GBookmarkFile *bookmark,
const gchar *filename)
@@ -139,13 +77,13 @@ test_modify (GBookmarkFile *bookmark)
g_bookmark_file_set_description (bookmark, NULL, "a bookmark file");
text = g_bookmark_file_get_title (bookmark, NULL, &error);
- test_assert_empty_error (&error);
- test_assert_str_equal (text, "a file");
+ g_assert_no_error (error);
+ g_assert_cmpstr (text, ==, "a file");
g_free (text);
text = g_bookmark_file_get_description (bookmark, NULL, &error);
- test_assert_empty_error (&error);
- test_assert_str_equal (text, "a bookmark file");
+ g_assert_no_error (error);
+ g_assert_cmpstr (text, ==, "a bookmark file");
g_free (text);
g_print ("ok\n");
@@ -154,14 +92,15 @@ test_modify (GBookmarkFile *bookmark)
g_bookmark_file_set_description (bookmark, TEST_URI_0, "a description");
text = g_bookmark_file_get_title (bookmark, TEST_URI_0, &error);
- test_assert_empty_error (&error);
- test_assert_str_equal (text, "a title");
+ g_assert_no_error (error);
+ g_assert_cmpstr (text, ==, "a title");
g_free (text);
g_print ("ok\n");
g_print ("\t=> check non existing bookmark...");
g_bookmark_file_get_description (bookmark, TEST_URI_1, &error);
- test_assert_not_empty_error (&error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
+ g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
+ g_clear_error (&error);
g_print ("ok\n");
g_print ("\t=> check application...");
@@ -175,7 +114,7 @@ test_modify (GBookmarkFile *bookmark)
&count,
&stamp,
&error);
- test_assert_empty_error (&error);
+ g_assert_no_error (error);
g_assert (count == 1);
g_assert (stamp == g_bookmark_file_get_modified (bookmark, TEST_URI_0, NULL));
g_free (text);
@@ -185,7 +124,8 @@ test_modify (GBookmarkFile *bookmark)
&count,
&stamp,
&error);
- test_assert_not_empty_error (&error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED);
+ g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED);
+ g_clear_error (&error);
g_print ("ok\n");
g_print ("\t=> check groups...");
@@ -196,9 +136,10 @@ test_modify (GBookmarkFile *bookmark)
g_print ("\t=> check remove...");
g_assert (g_bookmark_file_remove_item (bookmark, TEST_URI_1, &error) == TRUE);
- test_assert_empty_error (&error);
+ g_assert_no_error (error);
g_assert (g_bookmark_file_remove_item (bookmark, TEST_URI_1, &error) == FALSE);
- test_assert_not_empty_error (&error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
+ g_assert_error (error, G_BOOKMARK_FILE_ERROR, G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND);
+ g_clear_error (&error);
g_print ("ok\n");
return TRUE;
diff --git a/tests/convert-test.c b/tests/convert-test.c
index f21972737..10b8c0003 100644
--- a/tests/convert-test.c
+++ b/tests/convert-test.c
@@ -48,7 +48,7 @@ test_iconv_state (void)
if (error && error->code == G_CONVERT_ERROR_NO_CONVERSION)
return; /* silently skip if CP1255 is not supported, see bug 467707 */
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (bytes_read == 5);
g_assert (bytes_written == 10);
g_assert (strcmp (out, expected) == 0);
@@ -70,7 +70,7 @@ test_one_half (void)
&bytes_read, &bytes_written,
&error);
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (bytes_read == 2);
g_assert (bytes_written == 1);
g_assert (strcmp (out, "\xbd") == 0);
@@ -81,7 +81,7 @@ test_one_half (void)
&bytes_read, &bytes_written,
&error);
- g_assert (error && error->code == G_CONVERT_ERROR_ILLEGAL_SEQUENCE);
+ g_assert_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE);
g_assert (bytes_read == 0);
g_assert (bytes_written == 0);
g_assert (out == NULL);
@@ -94,7 +94,7 @@ test_one_half (void)
&bytes_read, &bytes_written,
&error);
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (bytes_read == 2);
g_assert (bytes_written == 1);
g_assert (strcmp (out, "a") == 0);
@@ -117,7 +117,7 @@ test_byte_order (void)
&bytes_read, &bytes_written,
&error);
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (bytes_read == 4);
g_assert (bytes_written == 2);
g_assert (strcmp (out, expected) == 0);
@@ -128,7 +128,7 @@ test_byte_order (void)
&bytes_read, &bytes_written,
&error);
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (bytes_read == 4);
g_assert (bytes_written == 2);
g_assert (strcmp (out, expected) == 0);
@@ -187,7 +187,7 @@ check_utf8_to_ucs4 (const char *utf8,
if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
{
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (items_read == error_pos);
g_assert (items_written == ucs4_len);
g_assert (result);
@@ -207,14 +207,14 @@ check_utf8_to_ucs4 (const char *utf8,
}
else
{
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (items_read == utf8_len);
g_assert (items_written == ucs4_len);
g_assert (result);
for (i = 0; i <= items_written; i++)
g_assert (result[i] == ucs4[i]);
- g_assert (error3 == NULL);
+ g_assert_no_error (error3);
g_assert (result3);
for (i = 0; i <= ucs4_len; i++)
g_assert (result3[i] == ucs4[i]);
@@ -273,13 +273,13 @@ check_ucs4_to_utf8 (const gunichar *ucs4,
}
else
{
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (items_read == ucs4_len);
g_assert (items_written == utf8_len);
g_assert (result);
g_assert (strcmp (result, utf8) == 0);
- g_assert (error3 == NULL);
+ g_assert_no_error (error3);
g_assert (result3);
g_assert (strcmp (result3, utf8) == 0);
}
@@ -327,7 +327,7 @@ check_utf8_to_utf16 (const char *utf8,
if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
{
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (items_read == error_pos);
g_assert (items_written == utf16_len);
g_assert (result);
@@ -347,14 +347,14 @@ check_utf8_to_utf16 (const char *utf8,
}
else
{
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (items_read == utf8_len);
g_assert (items_written == utf16_len);
g_assert (result);
for (i = 0; i <= items_written; i++)
g_assert (result[i] == utf16[i]);
- g_assert (error3 == NULL);
+ g_assert_no_error (error3);
g_assert (result3);
for (i = 0; i <= utf16_len; i++)
g_assert (result3[i] == utf16[i]);
@@ -401,7 +401,7 @@ check_utf16_to_utf8 (const gunichar2 *utf16,
if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
{
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (items_read == error_pos);
g_assert (items_read + 1 == utf16_len);
g_assert (items_written == utf8_len);
@@ -421,13 +421,13 @@ check_utf16_to_utf8 (const gunichar2 *utf16,
}
else
{
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (items_read == utf16_len);
g_assert (items_written == utf8_len);
g_assert (result);
g_assert (strcmp (result, utf8) == 0);
- g_assert (error3 == NULL);
+ g_assert_no_error (error3);
g_assert (result3);
g_assert (strcmp (result3, utf8) == 0);
}
@@ -487,14 +487,14 @@ check_ucs4_to_utf16 (const gunichar *ucs4,
}
else
{
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (items_read == ucs4_len);
g_assert (items_written == utf16_len);
g_assert (result);
for (i = 0; i <= utf16_len; i++)
g_assert (result[i] == utf16[i]);
- g_assert (error3 == NULL);
+ g_assert_no_error (error3);
g_assert (result3);
for (i = 0; i <= utf16_len; i++)
g_assert (result3[i] == utf16[i]);
@@ -542,7 +542,7 @@ check_utf16_to_ucs4 (const gunichar2 *utf16,
if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
{
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (items_read == error_pos);
g_assert (items_read + 1 == utf16_len);
g_assert (items_written == ucs4_len);
@@ -563,14 +563,14 @@ check_utf16_to_ucs4 (const gunichar2 *utf16,
}
else
{
- g_assert (error == NULL);
+ g_assert_no_error (error);
g_assert (items_read == utf16_len);
g_assert (items_written == ucs4_len);
g_assert (result);
for (i = 0; i <= ucs4_len; i++)
g_assert (result[i] == ucs4[i]);
- g_assert (error3 == NULL);
+ g_assert_no_error (error3);
g_assert (result3);
for (i = 0; i <= ucs4_len; i++)
g_assert (result3[i] == ucs4[i]);
diff --git a/tests/file-test.c b/tests/file-test.c
index b38d16545..adab1f20f 100644
--- a/tests/file-test.c
+++ b/tests/file-test.c
@@ -132,12 +132,12 @@ test_readlink (void)
error = NULL;
data = g_file_read_link (link3, &error);
g_assert (data == NULL && "could read link3");
- g_assert (error != NULL && "error not set");
+ g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
error = NULL;
data = g_file_read_link (filename, &error);
g_assert (data == NULL && "could read regular file as link");
- g_assert (error != NULL && "error not set");
+ g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL);
remove (filename);
remove (link1);