[glib] Use better assertion macros



commit d9359765acea796473ec9de328d023e5bdc7e96a
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jul 28 18:39:51 2013 -0400

    Use better assertion macros
    
    Use g_assert_cmpint and friends in the convert test, to get
    more telling messages when they fail.

 glib/tests/convert.c |  132 +++++++++++++++++++++++++-------------------------
 1 files changed, 66 insertions(+), 66 deletions(-)
---
diff --git a/glib/tests/convert.c b/glib/tests/convert.c
index 2742fa6..6e0b5fd 100644
--- a/glib/tests/convert.c
+++ b/glib/tests/convert.c
@@ -49,9 +49,9 @@ test_iconv_state (void)
     return; /* silently skip if CP1255 is not supported, see bug 467707 */ 
 
   g_assert_no_error (error);
-  g_assert (bytes_read == 5);
-  g_assert (bytes_written == 10);
-  g_assert (strcmp (out, expected) == 0);
+  g_assert_cmpint (bytes_read, ==, 5);
+  g_assert_cmpint (bytes_written, ==, 10);
+  g_assert_cmpstr (out, ==, expected);
   g_free (out);
 }
 
@@ -71,9 +71,9 @@ test_one_half (void)
                   &error);
 
   g_assert_no_error (error);
-  g_assert (bytes_read == 2);
-  g_assert (bytes_written == 1);
-  g_assert (strcmp (out, "\xbd") == 0);
+  g_assert_cmpint (bytes_read, ==, 2);
+  g_assert_cmpint (bytes_written, ==, 1);
+  g_assert_cmpstr (out, ==, "\xbd");
   g_free (out);
 
   out = g_convert (in, -1, 
@@ -82,9 +82,9 @@ test_one_half (void)
                   &error);
 
   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);
+  g_assert_cmpint (bytes_read, ==, 0);
+  g_assert_cmpint (bytes_written, ==, 0);
+  g_assert_cmpstr (out, ==, NULL);
   g_clear_error (&error);
   g_free (out);
 
@@ -95,9 +95,9 @@ test_one_half (void)
                                 &error);
 
   g_assert_no_error (error);
-  g_assert (bytes_read == 2);
-  g_assert (bytes_written == 1);
-  g_assert (strcmp (out, "a") == 0);
+  g_assert_cmpint (bytes_read, ==, 2);
+  g_assert_cmpint (bytes_written, ==, 1);
+  g_assert_cmpstr (out, ==, "a");
   g_free (out);
 }
 
@@ -118,9 +118,9 @@ test_byte_order (void)
                   &error);
 
   g_assert_no_error (error);
-  g_assert (bytes_read == 4);
-  g_assert (bytes_written == 2);
-  g_assert (strcmp (out, expected) == 0);
+  g_assert_cmpint (bytes_read, ==, 4);
+  g_assert_cmpint (bytes_written, ==, 2);
+  g_assert_cmpstr (out, ==, expected);
   g_free (out);
 
   out = g_convert (in_le, sizeof (in_le), 
@@ -129,9 +129,9 @@ test_byte_order (void)
                   &error);
 
   g_assert_no_error (error);
-  g_assert (bytes_read == 4);
-  g_assert (bytes_written == 2);
-  g_assert (strcmp (out, expected) == 0);
+  g_assert_cmpint (bytes_read, ==, 4);
+  g_assert_cmpint (bytes_written, ==, 2);
+  g_assert_cmpstr (out, ==, expected);
   g_free (out);
 }
 
@@ -153,7 +153,7 @@ check_utf8_to_ucs4 (const char     *utf8,
       /* check the fast conversion */
       result = g_utf8_to_ucs4_fast (utf8, utf8_len, &items_written);
 
-      g_assert (items_written == ucs4_len);
+      g_assert_cmpint (items_written, ==, ucs4_len);
       g_assert (result);
       for (i = 0; i <= items_written; i++)
        g_assert (result[i] == ucs4[i]);      
@@ -171,8 +171,8 @@ check_utf8_to_ucs4 (const char     *utf8,
       result2 = g_utf8_to_ucs4 (utf8, -1, &items_read2, &items_written2, &error2);
       g_assert (error || items_read2 == items_read);
       g_assert (error || items_written2 == items_written2);
-      g_assert (!!result == !!result2);
-      g_assert (!!error == !!error2);
+      g_assert_cmpint (!!result, ==, !!result2);
+      g_assert_cmpint (!!error, ==, !!error2);
       if (result)
        for (i = 0; i <= items_written; i++)
          g_assert (result[i] == result2[i]);
@@ -188,8 +188,8 @@ check_utf8_to_ucs4 (const char     *utf8,
   if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
     {
       g_assert_no_error (error);
-      g_assert (items_read == error_pos);
-      g_assert (items_written == ucs4_len);
+      g_assert_cmpint (items_read, ==, error_pos);
+      g_assert_cmpint (items_written, ==, ucs4_len);
       g_assert (result);
       for (i = 0; i <= items_written; i++)
        g_assert (result[i] == ucs4[i]);
@@ -199,7 +199,7 @@ check_utf8_to_ucs4 (const char     *utf8,
     {
       g_assert (error != NULL);
       g_assert (result == NULL);
-      g_assert (items_read == error_pos);
+      g_assert_cmpint (items_read, ==, error_pos);
       g_error_free (error);
 
       g_assert (error3 != NULL);
@@ -209,8 +209,8 @@ check_utf8_to_ucs4 (const char     *utf8,
   else
     {
       g_assert_no_error (error);
-      g_assert (items_read == utf8_len);
-      g_assert (items_written == ucs4_len);
+      g_assert_cmpint (items_read, ==, utf8_len);
+      g_assert_cmpint (items_written, ==, ucs4_len);
       g_assert (result);
       for (i = 0; i <= items_written; i++)
        g_assert (result[i] == ucs4[i]);
@@ -248,10 +248,10 @@ check_ucs4_to_utf8 (const gunichar *ucs4,
       
       g_assert (error || items_read2 == items_read);
       g_assert (error || items_written2 == items_written);
-      g_assert (!!result == !!result2);
-      g_assert (!!error == !!error2);
+      g_assert_cmpint (!!result, ==, !!result2);
+      g_assert_cmpint (!!error, ==, !!error2);
       if (result)
-       g_assert (strcmp (result, result2) == 0);
+       g_assert_cmpstr (result, ==, result2);
 
       g_free (result2);
       if (error2)
@@ -265,7 +265,7 @@ check_ucs4_to_utf8 (const gunichar *ucs4,
     {
       g_assert (error != NULL);
       g_assert (result == NULL);
-      g_assert (items_read == error_pos);
+      g_assert_cmpint (items_read, ==, error_pos);
       g_error_free (error);
 
       g_assert (error3 != NULL);
@@ -275,14 +275,14 @@ check_ucs4_to_utf8 (const gunichar *ucs4,
   else
     {
       g_assert_no_error (error);
-      g_assert (items_read == ucs4_len);
-      g_assert (items_written == utf8_len);
+      g_assert_cmpint (items_read, ==, ucs4_len);
+      g_assert_cmpint (items_written, ==, utf8_len);
       g_assert (result);
-      g_assert (strcmp (result, utf8) == 0);
+      g_assert_cmpstr (result, ==, utf8);
 
       g_assert_no_error (error3);
       g_assert (result3);
-      g_assert (strcmp (result3, utf8) == 0);
+      g_assert_cmpstr (result3, ==, utf8);
     }
 
   g_free (result);
@@ -312,8 +312,8 @@ check_utf8_to_utf16 (const char      *utf8,
       result2 = g_utf8_to_utf16 (utf8, -1, &items_read2, &items_written2, &error2);
       g_assert (error || items_read2 == items_read);
       g_assert (error || items_written2 == items_written2);
-      g_assert (!!result == !!result2);
-      g_assert (!!error == !!error2);
+      g_assert_cmpint (!!result, ==, !!result2);
+      g_assert_cmpint (!!error, ==, !!error2);
       if (result)
        for (i = 0; i <= items_written; i++)
          g_assert (result[i] == result2[i]);
@@ -329,8 +329,8 @@ check_utf8_to_utf16 (const char      *utf8,
   if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
     {
       g_assert_no_error (error);
-      g_assert (items_read == error_pos);
-      g_assert (items_written == utf16_len);
+      g_assert_cmpint (items_read, ==, error_pos);
+      g_assert_cmpint (items_written, ==, utf16_len);
       g_assert (result);
       for (i = 0; i <= items_written; i++)
        g_assert (result[i] == utf16[i]);
@@ -340,7 +340,7 @@ check_utf8_to_utf16 (const char      *utf8,
     {
       g_assert (error != NULL);
       g_assert (result == NULL);
-      g_assert (items_read == error_pos);
+      g_assert_cmpint (items_read, ==, error_pos);
       g_error_free (error);
 
       g_assert (error3 != NULL);
@@ -350,8 +350,8 @@ check_utf8_to_utf16 (const char      *utf8,
   else
     {
       g_assert_no_error (error);
-      g_assert (items_read == utf8_len);
-      g_assert (items_written == utf16_len);
+      g_assert_cmpint (items_read, ==, utf8_len);
+      g_assert_cmpint (items_written, ==, utf16_len);
       g_assert (result);
       for (i = 0; i <= items_written; i++)
        g_assert (result[i] == utf16[i]);
@@ -388,10 +388,10 @@ check_utf16_to_utf8 (const gunichar2 *utf16,
       
       g_assert (error || items_read2 == items_read);
       g_assert (error || items_written2 == items_written);
-      g_assert (!!result == !!result2);
-      g_assert (!!error == !!error2);
+      g_assert_cmpint (!!result, ==, !!result2);
+      g_assert_cmpint (!!error, ==, !!error2);
       if (result)
-       g_assert (strcmp (result, result2) == 0);
+       g_assert_cmpstr (result, ==, result2);
 
       g_free (result2);
       if (error2)
@@ -404,18 +404,18 @@ check_utf16_to_utf8 (const gunichar2 *utf16,
   if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
     {
       g_assert_no_error (error);
-      g_assert (items_read == error_pos);
-      g_assert (items_read + 1 == utf16_len);
-      g_assert (items_written == utf8_len);
+      g_assert_cmpint (items_read, ==, error_pos);
+      g_assert_cmpint (items_read + 1, ==, utf16_len);
+      g_assert_cmpint (items_written, ==, utf8_len);
       g_assert (result);
-      g_assert (strcmp (result, utf8) == 0);
+      g_assert_cmpstr (result, ==, utf8);
       g_error_free (error3);
     }
   else if (error_pos)
     {
       g_assert (error != NULL);
       g_assert (result == NULL);
-      g_assert (items_read == error_pos);
+      g_assert_cmpint (items_read, ==, error_pos);
       g_error_free (error);
 
       g_assert (error3 != NULL);
@@ -425,14 +425,14 @@ check_utf16_to_utf8 (const gunichar2 *utf16,
   else
     {
       g_assert_no_error (error);
-      g_assert (items_read == utf16_len);
-      g_assert (items_written == utf8_len);
+      g_assert_cmpint (items_read, ==, utf16_len);
+      g_assert_cmpint (items_written, ==, utf8_len);
       g_assert (result);
-      g_assert (strcmp (result, utf8) == 0);
+      g_assert_cmpstr (result, ==, utf8);
 
       g_assert_no_error (error3);
       g_assert (result3);
-      g_assert (strcmp (result3, utf8) == 0);
+      g_assert_cmpstr (result3, ==, utf8);
     }
 
   g_free (result);
@@ -463,8 +463,8 @@ check_ucs4_to_utf16 (const gunichar  *ucs4,
       
       g_assert (error || items_read2 == items_read);
       g_assert (error || items_written2 == items_written);
-      g_assert (!!result == !!result2);
-      g_assert (!!error == !!error2);
+      g_assert_cmpint (!!result, ==, !!result2);
+      g_assert_cmpint (!!error, ==, !!error2);
       if (result)
       for (i = 0; i <= utf16_len; i++)
        g_assert (result[i] == result2[i]);
@@ -481,7 +481,7 @@ check_ucs4_to_utf16 (const gunichar  *ucs4,
     {
       g_assert (error != NULL);
       g_assert (result == NULL);
-      g_assert (items_read == error_pos);
+      g_assert_cmpint (items_read, ==, error_pos);
       g_error_free (error);
 
       g_assert (error3 != NULL);
@@ -491,8 +491,8 @@ check_ucs4_to_utf16 (const gunichar  *ucs4,
   else
     {
       g_assert_no_error (error);
-      g_assert (items_read == ucs4_len);
-      g_assert (items_written == utf16_len);
+      g_assert_cmpint (items_read, ==, ucs4_len);
+      g_assert_cmpint (items_written, ==, utf16_len);
       g_assert (result);
       for (i = 0; i <= utf16_len; i++)
        g_assert (result[i] == utf16[i]);
@@ -529,8 +529,8 @@ check_utf16_to_ucs4 (const gunichar2 *utf16,
       result2 = g_utf16_to_ucs4 (utf16, -1, &items_read2, &items_written2, &error2);
       g_assert (error || items_read2 == items_read);
       g_assert (error || items_written2 == items_written2);
-      g_assert (!!result == !!result2);
-      g_assert (!!error == !!error2);
+      g_assert_cmpint (!!result, ==, !!result2);
+      g_assert_cmpint (!!error, ==, !!error2);
       if (result)
        for (i = 0; i <= items_written; i++)
          g_assert (result[i] == result2[i]);
@@ -546,9 +546,9 @@ check_utf16_to_ucs4 (const gunichar2 *utf16,
   if (error3 && error3->code == G_CONVERT_ERROR_PARTIAL_INPUT)
     {
       g_assert_no_error (error);
-      g_assert (items_read == error_pos);
-      g_assert (items_read + 1 == utf16_len);
-      g_assert (items_written == ucs4_len);
+      g_assert_cmpint (items_read, ==, error_pos);
+      g_assert_cmpint (items_read + 1, ==, utf16_len);
+      g_assert_cmpint (items_written, ==, ucs4_len);
       g_assert (result);
       for (i = 0; i <= items_written; i++)
        g_assert (result[i] == ucs4[i]);
@@ -558,7 +558,7 @@ check_utf16_to_ucs4 (const gunichar2 *utf16,
     {
       g_assert (error != NULL);
       g_assert (result == NULL);
-      g_assert (items_read == error_pos);
+      g_assert_cmpint (items_read, ==, error_pos);
       g_error_free (error);
 
       g_assert (error3 != NULL);
@@ -568,8 +568,8 @@ check_utf16_to_ucs4 (const gunichar2 *utf16,
   else
     {
       g_assert_no_error (error);
-      g_assert (items_read == utf16_len);
-      g_assert (items_written == ucs4_len);
+      g_assert_cmpint (items_read, ==, utf16_len);
+      g_assert_cmpint (items_written, ==, ucs4_len);
       g_assert (result);
       for (i = 0; i <= ucs4_len; i++)
        g_assert (result[i] == ucs4[i]);


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