[glib/ebassi/enum-type-macros: 8/11] Port enums tests to the appropriate assert functions




commit 254eeee8b5463353afff6cc7dcaba4d80572ef06
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Jun 29 15:37:13 2022 +0100

    Port enums tests to the appropriate assert functions
    
    Do not use `g_assert()` inside tests, as the symbol can be disabled.
    Instead, use `g_assert_null()` and `g_assert_nonnull()`.

 gobject/tests/enums.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
---
diff --git a/gobject/tests/enums.c b/gobject/tests/enums.c
index 447d76c0fc..0c465172db 100644
--- a/gobject/tests/enums.c
+++ b/gobject/tests/enums.c
@@ -20,7 +20,7 @@ test_enum_basic (void)
   type = g_enum_register_static ("MyEnum", my_enum_values);
 
   g_value_init (&value, type);
-  g_assert (G_VALUE_HOLDS_ENUM (&value));
+  g_assert_true (G_VALUE_HOLDS_ENUM (&value));
 
   g_value_set_enum (&value, 2);
   g_assert_cmpint (g_value_get_enum (&value), ==, 2);
@@ -33,22 +33,22 @@ test_enum_basic (void)
   g_assert_cmpint (class->n_values, ==, 3);
 
   val = g_enum_get_value (class, 2);
-  g_assert (val != NULL);
+  g_assert_nonnull (val);
   g_assert_cmpstr (val->value_name, ==, "the second value");
   val = g_enum_get_value (class, 15);
-  g_assert (val == NULL);
+  g_assert_null (val);
 
   val = g_enum_get_value_by_name (class, "the third value");
-  g_assert (val != NULL);
+  g_assert_nonnull (val);
   g_assert_cmpint (val->value, ==, 3);
   val = g_enum_get_value_by_name (class, "the color purple");
-  g_assert (val == NULL);
+  g_assert_null (val);
 
   val = g_enum_get_value_by_nick (class, "one");
-  g_assert (val != NULL);
+  g_assert_nonnull (val);
   g_assert_cmpint (val->value, ==, 1);
   val = g_enum_get_value_by_nick (class, "purple");
-  g_assert (val == NULL);
+  g_assert_null (val);
 
   to_string = g_enum_to_string (type, 2);
   g_assert_cmpstr (to_string, ==, "the second value");
@@ -100,7 +100,7 @@ test_flags_basic (void)
                                              no_default_flag_values);
 
   g_value_init (&value, type);
-  g_assert (G_VALUE_HOLDS_FLAGS (&value));
+  g_assert_true (G_VALUE_HOLDS_FLAGS (&value));
 
   g_value_set_flags (&value, 2|8);
   g_assert_cmpint (g_value_get_flags (&value), ==, 2|8);
@@ -111,22 +111,22 @@ test_flags_basic (void)
   g_assert_cmpint (class->n_values, ==, 4);
 
   val = g_flags_get_first_value (class, 2|8);
-  g_assert (val != NULL);
+  g_assert_nonnull (val);
   g_assert_cmpstr (val->value_name, ==, "the second flag");
   val = g_flags_get_first_value (class, 16);
-  g_assert (val == NULL);
+  g_assert_null (val);
 
   val = g_flags_get_value_by_name (class, "the third flag");
-  g_assert (val != NULL);
+  g_assert_nonnull (val);
   g_assert_cmpint (val->value, ==, 8);
   val = g_flags_get_value_by_name (class, "the color purple");
-  g_assert (val == NULL);
+  g_assert_null (val);
 
   val = g_flags_get_value_by_nick (class, "one");
-  g_assert (val != NULL);
+  g_assert_nonnull (val);
   g_assert_cmpint (val->value, ==, 1);
   val = g_flags_get_value_by_nick (class, "purple");
-  g_assert (val == NULL);
+  g_assert_null (val);
 
   test_flags_transform_to_string (&value);
   g_value_unset (&value);
@@ -182,10 +182,10 @@ test_enum_define_type (void)
   g_assert_cmpint (class->n_values, ==, 3);
 
   val = g_enum_get_value (class, 2);
-  g_assert (val != NULL);
+  g_assert_nonnull (val);
   g_assert_cmpstr (val->value_nick, ==, "third-value");
   val = g_enum_get_value (class, 15);
-  g_assert (val == NULL);
+  g_assert_null (val);
 
   g_type_class_unref (class);
 }
@@ -216,11 +216,11 @@ test_flags_define_type (void)
   g_assert_cmpint (class->n_values, ==, 4);
 
   val = g_flags_get_first_value (class, 2|4);
-  g_assert (val != NULL);
+  g_assert_nonnull (val);
   g_assert_cmpstr (val->value_nick, ==, "second");
 
   val = g_flags_get_first_value (class, 8);
-  g_assert (val == NULL);
+  g_assert_null (val);
 
   to_string = g_flags_to_string (test_flags_get_type (), 0);
   g_assert_cmpstr (to_string, ==, "TEST_FLAGS_DEFAULT");


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