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()`.
This commit is contained in:
Emmanuele Bassi 2022-06-29 15:37:13 +01:00
parent 28edd84e77
commit 6cbf7a7461

View File

@ -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");