[glib/param-speedups2: 3/4] Add tests for g_param_value_is_valid




commit c4654457e5d5112a7039c5993cc15d3ef5657472
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 20 08:53:33 2022 -0400

    Add tests for g_param_value_is_valid

 gobject/tests/param.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/gobject/tests/param.c b/gobject/tests/param.c
index 692f07d21b..fffaaab386 100644
--- a/gobject/tests/param.c
+++ b/gobject/tests/param.c
@@ -48,34 +48,42 @@ test_param_spec_char (void)
   g_assert_true (g_param_value_defaults (pspec, &value));
 
   g_value_set_char (&value, 0);
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_char (&value), ==, 20);
 
   g_value_set_char (&value, 20);
+  g_assert_true (g_param_value_is_valid (pspec, &value));
   g_assert_false (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_char (&value), ==, 20);
 
   g_value_set_char (&value, 40);
+  g_assert_true (g_param_value_is_valid (pspec, &value));
   g_assert_false (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_char (&value), ==, 40);
 
   g_value_set_char (&value, 60);
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_char (&value), ==, 40);
 
   g_value_set_schar (&value, 0);
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_schar (&value), ==, 20);
 
   g_value_set_schar (&value, 20);
+  g_assert_true (g_param_value_is_valid (pspec, &value));
   g_assert_false (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_schar (&value), ==, 20);
 
   g_value_set_schar (&value, 40);
+  g_assert_true (g_param_value_is_valid (pspec, &value));
   g_assert_false (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_schar (&value), ==, 40);
 
   g_value_set_schar (&value, 60);
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_schar (&value), ==, 40);
 
@@ -93,9 +101,11 @@ test_param_spec_string (void)
   g_value_init (&value, G_TYPE_STRING);
 
   g_value_set_string (&value, "foobar");
+  g_assert_true (g_param_value_is_valid (pspec, &value));
   g_assert_false (g_param_value_validate (pspec, &value));
 
   g_value_set_string (&value, "");
+  g_assert_true (g_param_value_is_valid (pspec, &value));
   g_assert_false (g_param_value_validate (pspec, &value));
   g_assert_nonnull (g_value_get_string (&value));
 
@@ -104,6 +114,7 @@ test_param_spec_string (void)
   G_PARAM_SPEC_STRING (pspec)->ensure_non_null = TRUE;
 
   g_value_set_string (&value, NULL);
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_nonnull (g_value_get_string (&value));
 
@@ -114,10 +125,12 @@ test_param_spec_string (void)
   G_PARAM_SPEC_STRING (pspec)->null_fold_if_empty = TRUE;
 
   g_value_set_string (&value, "");
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_null (g_value_get_string (&value));
 
   g_value_set_static_string (&value, "");
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_null (g_value_get_string (&value));
 
@@ -129,10 +142,12 @@ test_param_spec_string (void)
   G_PARAM_SPEC_STRING (pspec)->substitutor = '-';
 
   g_value_set_string (&value, "ABC");
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_string (&value)[0], ==, '-');
 
   g_value_set_static_string (&value, "ABC");
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_string (&value)[0], ==, '-');
 
@@ -141,10 +156,12 @@ test_param_spec_string (void)
   G_PARAM_SPEC_STRING (pspec)->cset_nth = g_strdup ("abc");
 
   g_value_set_string (&value, "aBC");
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_string (&value)[1], ==, '-');
 
   g_value_set_static_string (&value, "aBC");
+  g_assert_false (g_param_value_is_valid (pspec, &value));
   g_assert_true (g_param_value_validate (pspec, &value));
   g_assert_cmpint (g_value_get_string (&value)[1], ==, '-');
 


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