[librsvg] (#415): Test the all the values in the RsvgError enum



commit 9c3a619641dfa1dfd48137cf8fa1afd0b7962da2
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Feb 15 12:07:37 2019 -0600

    (#415): Test the all the values in the RsvgError enum
    
    Finishes fixing https://gitlab.gnome.org/GNOME/librsvg/issues/415

 tests/api.c | 65 +++++++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 46 insertions(+), 19 deletions(-)
---
diff --git a/tests/api.c b/tests/api.c
index ac235412..557eba18 100644
--- a/tests/api.c
+++ b/tests/api.c
@@ -14,7 +14,6 @@
 /*
   Untested:
   rsvg_handle_internal_set_testing
-  rsvg_error_get_type() and the error enum
 */
 
 static void
@@ -80,6 +79,51 @@ flags_registration (void)
     g_type_class_unref (type_class);
 }
 
+static gboolean
+enum_value_matches (GEnumValue *v,
+                    gint value,
+                    const char *value_name,
+                    const char *value_nick)
+{
+    return (v->value == value
+            && strcmp (v->value_name, value_name) == 0
+            && strcmp (v->value_nick, value_nick) == 0);
+}
+
+static void
+error_registration (void)
+{
+    GType ty;
+    GTypeQuery q;
+    GTypeClass *type_class;
+    GEnumClass *enum_class;
+
+    g_assert_cmpint (RSVG_ERROR, !=, 0);
+
+    ty = RSVG_TYPE_ERROR;
+
+    g_assert (ty != G_TYPE_INVALID);
+
+    g_type_query (ty, &q);
+    g_assert (q.type == ty);
+    g_assert (G_TYPE_IS_ENUM (q.type));
+    g_assert_cmpstr (q.type_name, ==, "RsvgError");
+
+    type_class = g_type_class_ref (ty);
+    g_assert (G_IS_ENUM_CLASS (type_class));
+    g_assert (G_ENUM_CLASS_TYPE (type_class) == ty);
+
+    enum_class = G_ENUM_CLASS (type_class);
+    g_assert (enum_class->n_values == 1);
+
+    g_assert (enum_value_matches (&enum_class->values[0],
+                                  RSVG_ERROR_FAILED,
+                                  "RSVG_ERROR_FAILED",
+                                  "failed"));
+
+    g_type_class_unref (type_class);
+}
+
 static char *
 get_test_filename (const char *basename) {
     return g_build_filename (test_utils_get_test_data_path (),
@@ -259,22 +303,6 @@ set_dpi (void)
     g_free (filename);
 }
 
-static void
-error_quark (void)
-{
-    g_assert_cmpint (rsvg_error_quark(), !=, 0);
-}
-
-static void
-auto_generated (void)
-{
-    GTypeQuery q;
-
-    g_type_query (RSVG_TYPE_ERROR, &q);
-    g_assert (G_TYPE_IS_ENUM (q.type));
-    g_assert_cmpstr (q.type_name, ==, "RsvgError");
-}
-
 static void
 base_uri (void)
 {
@@ -873,10 +901,9 @@ main (int argc, char **argv)
 
     g_test_add_func ("/api/handle_has_gtype", handle_has_gtype);
     g_test_add_func ("/api/flags_registration", flags_registration);
+    g_test_add_func ("/api/error_registration", error_registration);
     g_test_add_func ("/api/noops", noops);
     g_test_add_func ("/api/set_dpi", set_dpi);
-    g_test_add_func ("/api/error_quark", error_quark);
-    g_test_add_func ("/api/auto_generated", auto_generated);
     g_test_add_func ("/api/base_uri", base_uri);
     g_test_add_func ("/api/base_gfile", base_gfile);
     g_test_add_func ("/api/handle_write_close_free", handle_write_close_free);


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