[libdazzle/wip/rishi/tests-fix-assertions] tests: Don't use g_assert




commit deb386a74192edb6f15f8339070d43304ae1fc78
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Apr 1 01:16:38 2021 +0200

    tests: Don't use g_assert
    
    The g_assert macro can be turned off by defining G_DISABLE_ASSERT.
    Therefore, it's not meant to be used in unit tests because the tests
    will be ineffective if compiled with G_DISABLE_ASSERT.
    
    In addition to that, g_assert_true and friends emit a more human
    readable error message in case the condition is not satisfied.

 tests/test-binding-group.c | 18 +++++++++---------
 tests/test-task-cache.c    | 16 ++++++++--------
 2 files changed, 17 insertions(+), 17 deletions(-)
---
diff --git a/tests/test-binding-group.c b/tests/test-binding-group.c
index 8f79707..d7d7e6d 100644
--- a/tests/test-binding-group.c
+++ b/tests/test-binding-group.c
@@ -245,8 +245,8 @@ celsius_to_fahrenheit (GBinding     *binding,
 {
   gdouble celsius, fahrenheit;
 
-  g_assert (G_VALUE_HOLDS (from_value, G_TYPE_DOUBLE));
-  g_assert (G_VALUE_HOLDS (to_value, G_TYPE_DOUBLE));
+  g_assert_true (G_VALUE_HOLDS (from_value, G_TYPE_DOUBLE));
+  g_assert_true (G_VALUE_HOLDS (to_value, G_TYPE_DOUBLE));
 
   celsius = g_value_get_double (from_value);
   fahrenheit = (9 * celsius / 5) + 32.0;
@@ -267,8 +267,8 @@ fahrenheit_to_celsius (GBinding     *binding,
 {
   gdouble celsius, fahrenheit;
 
-  g_assert (G_VALUE_HOLDS (from_value, G_TYPE_DOUBLE));
-  g_assert (G_VALUE_HOLDS (to_value, G_TYPE_DOUBLE));
+  g_assert_true (G_VALUE_HOLDS (from_value, G_TYPE_DOUBLE));
+  g_assert_true (G_VALUE_HOLDS (to_value, G_TYPE_DOUBLE));
 
   fahrenheit = g_value_get_double (from_value);
   celsius = 5 * (fahrenheit - 32.0) / 9;
@@ -341,7 +341,7 @@ test_binding_group_default (void)
 
   g_assert_null (dzl_binding_group_get_source (group));
   dzl_binding_group_set_source (group, source);
-  g_assert (dzl_binding_group_get_source (group) == (GObject *)source);
+  g_assert_true (dzl_binding_group_get_source (group) == (GObject *)source);
 
   for (i = 0; i < 2; ++i)
     {
@@ -356,7 +356,7 @@ test_binding_group_default (void)
       dzl_binding_group_set_source (group, NULL);
       g_assert_null (dzl_binding_group_get_source (group));
       dzl_binding_group_set_source (group, source);
-      g_assert (dzl_binding_group_get_source (group) == (GObject *)source);
+      g_assert_true (dzl_binding_group_get_source (group) == (GObject *)source);
     }
 
   g_object_unref (group);
@@ -388,7 +388,7 @@ test_binding_group_bidirectional (void)
 
   g_assert_null (dzl_binding_group_get_source (group));
   dzl_binding_group_set_source (group, source);
-  g_assert (dzl_binding_group_get_source (group) == (GObject *)source);
+  g_assert_true (dzl_binding_group_get_source (group) == (GObject *)source);
 
   for (i = 0; i < 2; ++i)
     {
@@ -403,7 +403,7 @@ test_binding_group_bidirectional (void)
       dzl_binding_group_set_source (group, NULL);
       g_assert_null (dzl_binding_group_get_source (group));
       dzl_binding_group_set_source (group, source);
-      g_assert (dzl_binding_group_get_source (group) == (GObject *)source);
+      g_assert_true (dzl_binding_group_get_source (group) == (GObject *)source);
     }
 
   g_object_unref (group);
@@ -554,7 +554,7 @@ test_binding_group_weak_ref_source (void)
                           G_BINDING_BIDIRECTIONAL);
 
   g_object_add_weak_pointer (G_OBJECT (source), (gpointer)&source);
-  g_assert (dzl_binding_group_get_source (group) == (GObject *)source);
+  g_assert_true (dzl_binding_group_get_source (group) == (GObject *)source);
   g_object_unref (source);
   g_assert_null (source);
   g_assert_null (dzl_binding_group_get_source (group));
diff --git a/tests/test-task-cache.c b/tests/test-task-cache.c
index abc2774..b493a5b 100644
--- a/tests/test-task-cache.c
+++ b/tests/test-task-cache.c
@@ -25,10 +25,10 @@ get_foo_cb (GObject      *object,
 
   ret = dzl_task_cache_get_finish (cache, result, &error);
   g_assert_no_error (error);
-  g_assert (ret != NULL);
-  g_assert (ret == foo);
+  g_assert_nonnull (ret);
+  g_assert_true (ret == foo);
 
-  g_assert (dzl_task_cache_evict (cache, "foo"));
+  g_assert_true (dzl_task_cache_evict (cache, "foo"));
   g_object_unref (ret);
 
   g_main_loop_quit (main_loop);
@@ -47,15 +47,15 @@ test_task_cache (void)
                               100 /* msec */,
                               populate_callback, NULL, NULL);
 
-  g_assert (!dzl_task_cache_peek (cache, "foo"));
-  g_assert (!dzl_task_cache_evict (cache, "foo"));
+  g_assert_null (dzl_task_cache_peek (cache, "foo"));
+  g_assert_false (dzl_task_cache_evict (cache, "foo"));
 
   dzl_task_cache_get_async (cache, "foo", TRUE, NULL, get_foo_cb, NULL);
 
   g_main_loop_run (main_loop);
   g_main_loop_unref (main_loop);
 
-  g_assert (foo == NULL);
+  g_assert_null (foo);
 }
 
 static void
@@ -101,8 +101,8 @@ test_task_cache_raw_value (void)
                               100 /* msec */,
                               populate_callback_raw_value, NULL, NULL);
 
-  g_assert (!dzl_task_cache_peek (cache, "foo"));
-  g_assert (!dzl_task_cache_evict (cache, "foo"));
+  g_assert_null (dzl_task_cache_peek (cache, "foo"));
+  g_assert_false (dzl_task_cache_evict (cache, "foo"));
 
   dzl_task_cache_get_async (cache, "foo", TRUE, NULL, get_foo_raw_value_cb, NULL);
 


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