[at-spi2-core] Convert atk tests to use GTestUtils



commit ee6295b078c5ef74900ba0a2ddbea3f7066f109e
Author: Mike Gorse <mgorse suse com>
Date:   Sun Jun 26 15:07:24 2022 -0500

    Convert atk tests to use GTestUtils
    
    Fixes #70

 tests/atk/testdocument.c |  43 ++++-----
 tests/atk/testrelation.c | 187 ++++++------------------------------
 tests/atk/testrole.c     |  76 +++------------
 tests/atk/teststateset.c | 244 ++++++++---------------------------------------
 tests/atk/testvalue.c    |  88 ++++-------------
 5 files changed, 122 insertions(+), 516 deletions(-)
---
diff --git a/tests/atk/testdocument.c b/tests/atk/testdocument.c
index bab4cb01..7cacbbd1 100644
--- a/tests/atk/testdocument.c
+++ b/tests/atk/testdocument.c
@@ -22,9 +22,6 @@
 
 #define EXPECTED_NUMBER 5
 
-GMainLoop *global_loop = NULL;
-gint global_number_emissions = 0;
-
 #define TEST_TYPE_DOCUMENT                         (test_document_get_type ())
 #define TEST_DOCUMENT(obj)                         (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_DOCUMENT, 
TestDocument))
 #define TEST_DOCUMENT_CLASS(klass)                 (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_DOCUMENT, 
TestDocumentClass))
@@ -38,6 +35,8 @@ typedef struct _TestDocumentClass   TestDocumentClass;
 struct _TestDocument
 {
   AtkObject parent;
+  GMainLoop *loop;
+  gint number_emissions;
 };
 
 struct _TestDocumentClass
@@ -74,8 +73,10 @@ document_page_changed_cb (AtkDocument *document,
                           gint page_number,
                           gpointer data)
 {
+  TestDocument* test_document = TEST_DOCUMENT (document);
+
   g_print ("Page-changed callback, page_number = %i\n", page_number);
-  global_number_emissions++;
+  test_document->number_emissions++;
 }
 
 static gboolean
@@ -89,18 +90,18 @@ document_emit_page_changed (gpointer data)
   g_signal_emit_by_name (test_document, "page-changed", next_page++, NULL);
 
   if (next_page > EXPECTED_NUMBER) {
-    g_main_loop_quit (global_loop);
+    g_main_loop_quit (test_document->loop);
     return G_SOURCE_REMOVE;
   } else
     return G_SOURCE_CONTINUE;
 }
 
-static gboolean
-init_test_document (void)
+static void
+test_page_changed (void)
 {
-  GObject *my_document;
+  TestDocument *my_document;
 
-  my_document = g_object_new (TEST_TYPE_DOCUMENT, NULL);
+  my_document = TEST_DOCUMENT (g_object_new (TEST_TYPE_DOCUMENT, NULL));
 
   g_signal_connect (my_document, "page-changed",
                     G_CALLBACK (document_page_changed_cb),
@@ -108,25 +109,21 @@ init_test_document (void)
 
   g_idle_add (document_emit_page_changed, my_document);
 
-  return TRUE;
-}
+  my_document->loop = g_main_loop_new (NULL, FALSE);
 
+  g_main_loop_run (my_document->loop);
+
+  g_assert_cmpint (my_document->number_emissions, ==, EXPECTED_NUMBER);
+  g_main_loop_unref (my_document->loop);
+  g_object_unref (my_document);
+}
 
 int
 main (gint  argc,
       char* argv[])
 {
-  global_loop = g_main_loop_new (NULL, FALSE);
-
-  g_print("Starting Document test suite\n");
-
-  init_test_document ();
-  g_main_loop_run (global_loop);
-
-  if (global_number_emissions == EXPECTED_NUMBER)
-    g_print ("Document tests succeeded\n");
-  else
-    g_print ("Document tests failed\n");
+  g_test_init (&argc, &argv, NULL);
+  g_test_add_func ("/atk/document/page_changed", test_page_changed);
 
-  return 0;
+  return g_test_run ();
 }
diff --git a/tests/atk/testrelation.c b/tests/atk/testrelation.c
index 6cc0be5e..6fb4ae96 100644
--- a/tests/atk/testrelation.c
+++ b/tests/atk/testrelation.c
@@ -21,7 +21,7 @@
 
 #include <string.h>
 
-static gboolean
+static void
 test_relation (void)
 {
   AtkRelationType type1, type2;
@@ -34,214 +34,89 @@ test_relation (void)
   GPtrArray *array; 
 
   name = atk_relation_type_get_name (ATK_RELATION_LABEL_FOR);
-  g_return_val_if_fail (name, FALSE);
-  if (strcmp (name, "label-for") != 0)
-    {
-      g_print ("Unexpected name for ATK_RELATION_LABEL_FOR %s\n", name);
-      return FALSE;
-    }
+  g_assert_cmpstr (name, ==, "label-for");
 
   name = atk_relation_type_get_name (ATK_RELATION_NODE_CHILD_OF);
-  g_return_val_if_fail (name, FALSE);
-  if (strcmp (name, "node-child-of") != 0)
-    {
-      g_print ("Unexpected name for ATK_RELATION_NODE_CHILD_OF %s\n", name);
-      return FALSE;
-    }
+  g_assert_cmpstr (name, ==, "node-child-of");
 
   name = atk_relation_type_get_name (ATK_RELATION_EMBEDS);
-  g_return_val_if_fail (name, FALSE);
-  if (strcmp (name, "embeds") != 0)
-    {
-      g_print ("Unexpected name for ATK_RELATION_EMBEDS %s\n", name);
-      return FALSE;
-    }
+  g_assert_cmpstr (name, ==, "embeds");
 
   type1 = atk_relation_type_for_name ("embedded-by");
-  if (type1 != ATK_RELATION_EMBEDDED_BY)
-    {
-      g_print ("Unexpected role for ATK_RELATION_EMBEDDED_BY\n");
-      return FALSE;
-    }
+  g_assert_cmpint (type1, ==, ATK_RELATION_EMBEDDED_BY);
 
   type1 = atk_relation_type_for_name ("controlled-by");
-  if (type1 != ATK_RELATION_CONTROLLED_BY)
-    {
-      g_print ("Unexpected name for ATK_RELATION_CONTROLLED_BY\n");
-      return FALSE;
-    }
+  g_assert_cmpint (type1, ==, ATK_RELATION_CONTROLLED_BY);
 
   type1 = atk_relation_type_register ("test-state");
   name = atk_relation_type_get_name (type1);
-  g_return_val_if_fail (name, FALSE);
-  if (strcmp (name, "test-state") != 0)
-    {
-      g_print ("Unexpected name for test-state %s\n", name);
-      return FALSE;
-    }
+  g_assert_cmpstr (name, ==, "test-state");
   type2 = atk_relation_type_for_name ("test-state");
-  if (type1 != type2)
-  {
-    g_print ("Unexpected type for test-state\n");
-    return FALSE;
-  }
+  g_assert_cmpint (type1, ==, type2);
   type2 = atk_relation_type_for_name ("TEST_STATE");
-  if (type2 != 0)
-    {
-      g_print ("Unexpected type for TEST_STATE\n");
-      return FALSE;
-    }
+  g_assert_cmpint (type2, ==, 0);
   /*
    * Check that a non-existent type returns NULL
    */
-  name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
-  if (name)
-    {
-      g_print ("Unexpected name for undefined type %s\n", name);
-      return FALSE;
-    }
+  g_assert_null (atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2));
 
   obj = g_object_new (ATK_TYPE_OBJECT, NULL);
   ret_value = atk_object_add_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
-  if (!ret_value)
-    {
-      g_print ("Unexpected return value for atk_object_add_relationship\n");
-      return FALSE;
-    }
+  g_assert_cmpint (ret_value, !=, 0);
   set = atk_object_ref_relation_set (obj);
-  if (!set)
-    {
-      g_print ("Unexpected return value for atk_object_ref_relation_set\n");
-      return FALSE;
-    }
+  g_assert_nonnull (set);
   n_relations = atk_relation_set_get_n_relations (set);
-  if (n_relations != 1)
-    {
-      g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", 
n_relations, 1);
-      return FALSE;
-    }
+  g_assert_cmpint (n_relations, ==, 1);
   relation = atk_relation_set_get_relation (set, 0);  
-  if (!relation)
-    {
-      g_print ("Unexpected return value for atk_object_relation_set_get_relation\n");
-      return FALSE;
-    }
+  g_assert_nonnull (relation);
   type1 = atk_relation_get_relation_type (relation);
-  if (type1 != ATK_RELATION_LABEL_FOR)
-    {
-      g_print ("Unexpected return value for atk_relation_get_relation_type\n");
-      return FALSE;
-    }
+  g_assert_cmpint (type1, ==, ATK_RELATION_LABEL_FOR);
   array = atk_relation_get_target (relation);
-  if (obj != g_ptr_array_index (array, 0))
-    {
-      g_print ("Unexpected return value for atk_relation_get_target\n");
-      return FALSE;
-    }
+  g_assert (obj == g_ptr_array_index (array, 0));
   g_object_unref (set);
-  ret_value = atk_object_remove_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
-  if (!ret_value)
-    {
-      g_print ("Unexpected return value for atk_object_remove_relationship\n");
-      return FALSE;
-    }
+  g_assert_true (atk_object_remove_relationship (obj, ATK_RELATION_LABEL_FOR, obj));
   set = atk_object_ref_relation_set (obj);
-  if (!set)
-    {
-      g_print ("Unexpected return value for atk_object_ref_relation_set\n");
-      return FALSE;
-    }
+  g_assert_nonnull (set);
   n_relations = atk_relation_set_get_n_relations (set);
-  if (n_relations != 0)
-    {
-      g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", 
n_relations, 0);
-      return FALSE;
-    }
+  g_assert_cmpint (atk_relation_set_get_n_relations (set), ==, 0);
   g_object_unref (set);
   g_object_unref (obj);
-  return TRUE;
 }
 
-static gboolean
+static void
 test_text_attr (void)
 {
   AtkTextAttribute attr1, attr2;
   const gchar *name;
 
   name = atk_text_attribute_get_name (ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
-  g_return_val_if_fail (name, FALSE);
-  if (strcmp (name, "pixels-inside-wrap") != 0)
-    {
-      g_print ("Unexpected name for ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP %s\n", name);
-      return FALSE;
-    }
+  g_assert_cmpstr (name, ==, "pixels-inside-wrap");
 
   name = atk_text_attribute_get_name (ATK_TEXT_ATTR_BG_STIPPLE);
-  g_return_val_if_fail (name, FALSE);
-  if (strcmp (name, "bg-stipple") != 0)
-    {
-      g_print ("Unexpected name for ATK_TEXT_ATTR_BG_STIPPLE %s\n", name);
-      return FALSE;
-    }
+  g_assert_cmpstr (name, ==, "bg-stipple");
 
   attr1 = atk_text_attribute_for_name ("left-margin");
-  if (attr1 != ATK_TEXT_ATTR_LEFT_MARGIN)
-    {
-      g_print ("Unexpected attribute for left-margin\n");
-      return FALSE;
-    }
+  g_assert_cmpint (attr1, ==, ATK_TEXT_ATTR_LEFT_MARGIN);
 
   attr1 = atk_text_attribute_register ("test-attribute");
   name = atk_text_attribute_get_name (attr1);
-  g_return_val_if_fail (name, FALSE);
-  if (strcmp (name, "test-attribute") != 0)
-    {
-      g_print ("Unexpected name for test-attribute %s\n", name);
-      return FALSE;
-    }
+  g_assert_cmpstr (name, ==, "test-attribute");
   attr2 = atk_text_attribute_for_name ("test-attribute");
-  if (attr1 != attr2)
-  {
-    g_print ("Unexpected attribute for test-attribute\n");
-    return FALSE;
-  }
-  attr2 = atk_text_attribute_for_name ("TEST_ATTR");
-  if (attr2 != 0)
-    {
-      g_print ("Unexpected attribute for TEST_ATTR\n");
-      return FALSE;
-    }
+  g_assert_cmpint (attr1, ==, attr2);
+  g_assert_cmpint (atk_text_attribute_for_name ("TEST_ATTR"), ==, 0);
   /*
    * Check that a non-existent attribute returns NULL
    */
-  name = atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
-  if (name)
-    {
-      g_print ("Unexpected name for undefined attribute %s\n", name);
-      return FALSE;
-    }
-  return TRUE;
+  g_assert_null (atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2));
 }
 
 int
 main (gint  argc,
       char* argv[])
 {
-  gboolean b_ret;
+  g_test_init (&argc, &argv, NULL);
+  g_test_add_func ("/atk/relation/relation",       test_relation);
+  g_test_add_func ("/atk/relation/text_attr", test_text_attr);
 
-  g_print("Starting Relation test suite\n");
-
-  b_ret = test_relation ();
-  if (b_ret)
-    g_print ("Relation tests succeeded\n");
-  else
-    g_print ("Relation tests failed\n");
-
-  b_ret = test_text_attr ();
-  if (b_ret)
-    g_print ("Text Attribute tests succeeded\n");
-  else
-    g_print ("Text Attribute tests failed\n");
-
-  return 0;
+  return g_test_run ();
 }
diff --git a/tests/atk/testrole.c b/tests/atk/testrole.c
index a50f0968..265e3d48 100644
--- a/tests/atk/testrole.c
+++ b/tests/atk/testrole.c
@@ -21,89 +21,35 @@
 #include <atk/atk.h>
 #include <string.h>
 
-static gboolean
+static void
 test_role (void)
 {
   AtkRole role1, role2;
   const gchar *name;
-  gboolean result = TRUE;
 
   name = atk_role_get_name (ATK_ROLE_PAGE_TAB);
-  if (!name || strcmp (name, "page tab") != 0)
-    {
-      g_print ("Unexpected name for ATK_ROLE_PAGE_TAB."
-               " Expected 'page tab', received '%s'\n", name);
-      result = FALSE;
-    }
+  g_assert_cmpstr (name, ==, "page tab");
 
   name = atk_role_get_name (ATK_ROLE_LAYERED_PANE);
-  if (!name || strcmp (name, "layered pane") != 0)
-    {
-      g_print ("Unexpected name for ATK_ROLE_LAYERED_PANE."
-               " Expected 'layered pane', received '%s'\n", name);
-      result = FALSE;
-    }
+  g_assert_cmpstr (name, ==, "layered pane");
 
   role1 = atk_role_for_name ("list item");
-  if (role1 != ATK_ROLE_LIST_ITEM)
-    {
-      g_print ("Unexpected role for list item."
-               " Expected %i, received %i\n", ATK_ROLE_LIST_ITEM, role1);
-      result = FALSE;
-    }
+  g_assert_cmpint (role1, ==, ATK_ROLE_LIST_ITEM);
 
   role2 = atk_role_for_name ("TEST_ROLE");
-  if (role2 != ATK_ROLE_INVALID)
-    {
-      g_print ("Unexpected role for TEST_ROLE. Expected %i, received %i\n", ATK_ROLE_INVALID, role2);
-      result = FALSE;
-    }
+  g_assert_cmpint (role2, ==, ATK_ROLE_INVALID);
   /*
    * Check that a non-existent role returns NULL
    */
-  name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
-  if (name)
-    {
-      g_print ("Unexpected name for undefined role %s\n", name);
-      result = FALSE;
-    }
-
-  return result;
-}
-
-static void
-print_roles()
-{
-  AtkRole role;
-
-  g_print("(Role, name, localized name) defined by the ATK library:\n");
-
-  for (role = ATK_ROLE_INVALID; role < ATK_ROLE_LAST_DEFINED; role++)
-    g_print ("(%i, %s, %s)\n", role,
-             atk_role_get_name(role), atk_role_get_localized_name(role));
-
-  g_print("(Role, name, localized name) for the extra roles:\n");
-  for (;atk_role_get_name(role) != NULL; role++)
-    g_print ("(%i, %s, %s)\n", role,
-             atk_role_get_name(role), atk_role_get_localized_name(role));
-
+  g_assert_null (atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2));
 }
 
 int
-main (int argc, char **argv)
+main (gint  argc,
+      char* argv[])
 {
-  gboolean b_ret;
-
-  g_print ("Starting Role test suite\n");
-
-  b_ret = test_role ();
-
-  print_roles();
-
-  if (b_ret)
-    g_print ("Role tests succeeded\n");
-  else
-    g_print ("Role tests failed\n");
+  g_test_init (&argc, &argv, NULL);
+  g_test_add_func ("/atk/role/roles", test_role);
 
-  return 0;
+  return g_test_run ();
 }
diff --git a/tests/atk/teststateset.c b/tests/atk/teststateset.c
index a9a3a6c8..3deb54d8 100644
--- a/tests/atk/teststateset.c
+++ b/tests/atk/teststateset.c
@@ -21,106 +21,40 @@
 
 #include <string.h>
 
-static gboolean  test_state_set (void);
-static gboolean  test_state (void);
+static void  test_state_set (void);
+static void  test_state (void);
 
-static gboolean
+static void
 test_state_set (void)
 {
   AtkStateSet *state_set1, *state_set2, *state_set3;
   AtkStateType state_array[3];
-  gboolean b_val;
 
   state_set1 = atk_state_set_new ();
 
-  b_val = atk_state_set_is_empty (state_set1);  
-  if (!b_val)
-  {
-    g_print ("New state set is not empty\n");
-    return FALSE;
-  }
+  g_assert_true (atk_state_set_is_empty (state_set1));
 
-  b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
-  if (!b_val)
-  {
-    g_print ("Adding new state set failed\n");
-    return FALSE;
-  }
+  g_assert_true (atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE));
 
-  b_val = atk_state_set_is_empty (state_set1);  
-  if (b_val)
-  {
-    g_print ("New state set is empty when it should not be\n");
-    return FALSE;
-  }
+  g_assert_false (atk_state_set_is_empty (state_set1));
 
-  b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
-  if (b_val)
-  {
-    g_print ("Adding new state set succeeded when it should not have\n");
-    return FALSE;
-  }
+  g_assert_false (atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE));
 
   state_array[0] = ATK_STATE_ACTIVE;
   state_array[1] = ATK_STATE_VISIBLE;
   state_array[2] = ATK_STATE_BUSY;
   atk_state_set_add_states (state_set1, state_array, 3);
 
-  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE);
-  if (!b_val)
-  {
-    g_print ("Contains state failed for ATK_STATE_ACTIVE but should not have\n");
-    return FALSE;
-  }
- 
-  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
-  if (!b_val)
-  {
-    g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
-    return FALSE;
-  }
- 
-  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
-  if (!b_val)
-  {
-    g_print ("Contains state failed for ATK_STATE_BUSY but should not have\n");
-    return FALSE;
-  }
- 
-  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VERTICAL);
-  if (b_val)
-  {
-    g_print ("Contains state succeeded for ATK_STATE_VERTICAL but should not have\n");
-    return FALSE;
-  }
+  g_assert_true (atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE));
+  g_assert_true (atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE));
+  g_assert_true (atk_state_set_contains_state (state_set1, ATK_STATE_BUSY));
+  g_assert_false (atk_state_set_contains_state (state_set1, ATK_STATE_VERTICAL));
  
   atk_state_set_remove_state (state_set1, ATK_STATE_BUSY);
-  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
-  if (b_val)
-  {
-    g_print ("Contains state succeeded for ATK_STATE_BUSY but should not have\n");
-    return FALSE;
-  }
-  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
-  if (!b_val)
-  {
-    g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
-    return FALSE;
-  }
-
-  b_val = atk_state_set_contains_states (state_set1, state_array, 3);
-  if (b_val)
-  {
-    g_print ("Contains states succeeded should not have\n");
-    return FALSE;
-  }
-
-  b_val = atk_state_set_contains_states (state_set1, state_array, 2);
-  if (!b_val)
-  {
-    g_print ("Contains states failed should not have\n");
-    return FALSE;
-  }
+  g_assert_false (atk_state_set_contains_state (state_set1, ATK_STATE_BUSY));
+  g_assert_true (atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE));
+  g_assert_false (atk_state_set_contains_states (state_set1, state_array, 3));
+  g_assert_true (atk_state_set_contains_states (state_set1, state_array, 2));
 
   state_array[0] = ATK_STATE_SINGLE_LINE;
   state_array[1] = ATK_STATE_VISIBLE;
@@ -130,166 +64,66 @@ test_state_set (void)
   atk_state_set_add_states (state_set2, state_array, 3);
 
   state_set3 = atk_state_set_and_sets (state_set1, state_set2);
-  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
-  if (!b_val)
-  {
-    g_print ("Contains state failed for ATK_STATE_VISIBLE after and but should not have\n");
-    return FALSE;
-  }
-  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_BUSY);
-  if (b_val)
-  {
-    g_print ("Contains state succeeded for ATK_STATE_BUSY after and but should not have\n");
-    return FALSE;
-  }
+  g_assert_true (atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE));
+  g_assert_false (atk_state_set_contains_state (state_set3, ATK_STATE_BUSY));
   g_object_unref (state_set3);
 
   atk_state_set_remove_state (state_set1, ATK_STATE_VISIBLE);
   state_set3 = atk_state_set_and_sets (state_set1, state_set2);
-  if (state_set3)
-  {
-    g_print ("state_set 3 is not NULL after and but should be\n");
-    return FALSE;
-  }
+  g_assert_null (state_set3);
  
   state_set3 = atk_state_set_or_sets (state_set1, state_set2);
-  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
-  if (!b_val)
-  {
-    g_print ("Contains state failed for ATK_STATE_VISIBLE after or but should not have\n");
-    return FALSE;
-  }
-
-  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_INVALID);
-  if (b_val)
-  {
-    g_print ("Contains state succeeded for ATK_STATE_INVALID after or but should not have\n");
-    return FALSE;
-  }
+  g_assert_true (atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE));
+  g_assert_false (atk_state_set_contains_state (state_set3, ATK_STATE_INVALID));
   g_object_unref (state_set3);
 
-  b_val = atk_state_set_add_state (state_set1, ATK_STATE_VISIBLE);
-  if (!b_val)
-  {
-    g_print ("Adding new state set failed\n");
-    return FALSE;
-  }
+  g_assert_true (atk_state_set_add_state (state_set1, ATK_STATE_VISIBLE));
   state_set3 = atk_state_set_xor_sets (state_set1, state_set2);
-  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
-  if (b_val)
-  {
-    g_print ("Contains state succeeded for ATK_STATE_VISIBLE after xor but should not have\n");
-    return FALSE;
-  }
-
-  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_ACTIVE);
-  if (!b_val)
-  {
-    g_print ("Contains state failed for ATK_STATE_ACTIVE after xor but should not have\n");
-    return FALSE;
-  }
+  g_assert_false (atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE));
+  g_assert_true (atk_state_set_contains_state (state_set3, ATK_STATE_ACTIVE));
 
   atk_state_set_clear_states (state_set1);
-  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE);
-  if (b_val)
-  {
-    g_print ("Contains state succeeded for ATK_STATE_ACTIVE but should not have\n");
-    return FALSE;
-  }
+  g_assert_false (atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE));
 
   g_object_unref (state_set1);
   g_object_unref (state_set2);
   g_object_unref (state_set3);
-  return TRUE;
-
 }
 
-static gboolean
+static void
 test_state (void)
 {
   AtkStateType type1, type2;
   const gchar *name;
 
   name = atk_state_type_get_name (ATK_STATE_VISIBLE);
-  g_return_val_if_fail (name, FALSE);
-  if (strcmp (name, "visible") != 0)
-  {
-    g_print ("Unexpected name for ATK_STATE_VISIBLE %s\n", name);
-    return FALSE;
-  }
+  g_assert_cmpstr (name, ==, "visible");
 
   name = atk_state_type_get_name (ATK_STATE_MODAL);
-  g_return_val_if_fail (name, FALSE);
-  if (strcmp (name, "modal") != 0)
-  {
-    g_print ("Unexpected name for ATK_STATE_MODAL %s\n", name);
-    return FALSE;
-  }
+  g_assert_cmpstr (name, ==, "modal");
 
-  type1 = atk_state_type_for_name ("focused");
-  if (type1 != ATK_STATE_FOCUSED)
-  {
-    g_print ("Unexpected type for focused\n");
-    return FALSE;
-  }
+  g_assert_cmpint (atk_state_type_for_name ("focused"), ==, ATK_STATE_FOCUSED);
 
   type1 = atk_state_type_register ("test-state");
   name = atk_state_type_get_name (type1);
-  g_return_val_if_fail (name, FALSE);
-  if (strcmp (name, "test-state") != 0)
-  {
-    g_print ("Unexpected name for test-state %s\n", name);
-    return FALSE;
-  }
+  g_assert_cmpstr (name, ==, "test-state");
   type2 = atk_state_type_for_name ("test-state");
-  g_return_val_if_fail (name, FALSE);
-  if (type1 != type2)
-  {
-    g_print ("Unexpected type for test-state %d %d\n", type1, type2);
-    return FALSE;
-  }
-  type2 = atk_state_type_for_name ("TEST_STATE");
-  if (type2 != 0)
-  {
-    g_print ("Unexpected type for TEST_STATE\n");
-    return FALSE;
-  }
+  g_assert_cmpint (type1, ==, type2);
+  g_assert_cmpint (atk_state_type_for_name ("TEST_STATE"), ==, 0);
+
   /*
    * Check that a non-existent type returns NULL
    */
-  name = atk_state_type_get_name (ATK_STATE_LAST_DEFINED +2);
-  if (name)
-  {
-    g_print ("Unexpected name for undefined type\n");
-    return FALSE;
-  }
-  return TRUE;
+  g_assert_null (atk_state_type_get_name (ATK_STATE_LAST_DEFINED +2));
 }
 
 int
-main (gint argc, char* argv[])
+main (gint  argc,
+      char* argv[])
 {
-  gboolean b_ret;
-
-  g_print("Starting State Set test suite\n");
+  g_test_init (&argc, &argv, NULL);
+  g_test_add_func ("/atk/state/state_set", test_state_set);
+  g_test_add_func ("/atk/state/state",     test_state);
 
-  b_ret = test_state_set ();
-  if (b_ret)
-  {
-    g_print ("State Set tests succeeded\n");
-  }
-  else
-  {
-    g_print ("State Set tests failed\n");
-  }
-  b_ret = test_state ();
-  if (b_ret)
-  {
-    g_print ("State tests succeeded\n");
-  }
-  else
-  {
-    g_print ("State tests failed\n");
-  }
-  return 0;
+  return g_test_run ();
 }
diff --git a/tests/atk/testvalue.c b/tests/atk/testvalue.c
index bad7168b..6bc8a54e 100644
--- a/tests/atk/testvalue.c
+++ b/tests/atk/testvalue.c
@@ -51,8 +51,6 @@
 #define UPPER_LIMIT 1.0
 #define INCREMENT 0.15
 
-GMainLoop *global_loop = NULL;
-gint global_number_emissions = 0;
 gboolean test_success = TRUE;
 GObject *my_value;
 
@@ -70,6 +68,9 @@ struct _TestValue
 {
   AtkObject parent;
 
+  GMainLoop *loop;
+  gint number_emissions;
+
   gdouble value;
 };
 
@@ -226,8 +227,10 @@ value_page_changed_cb (AtkValue *value,
                        gchar *new_description,
                        gpointer data)
 {
+  TestValue* test_value = TEST_VALUE (value);
+
   g_print ("value-changed callback=(%f,%s)\n", new_value, new_description);
-  global_number_emissions++;
+  test_value->number_emissions++;
 }
 
 /**
@@ -242,89 +245,40 @@ do_value_changed (gpointer data)
   atk_value_set_value (ATK_VALUE (test_value),
                        test_value->value + INCREMENT);
 
-  if (global_number_emissions == EXPECTED_NUMBER) {
-    g_main_loop_quit (global_loop);
+  if (test_value->number_emissions == EXPECTED_NUMBER) {
+    g_main_loop_quit (test_value->loop);
     return G_SOURCE_REMOVE;
   } else
     return G_SOURCE_CONTINUE;
 }
 
-/**
- * Prints all the info from an AtkValue
- */
 static void
-print_info (AtkValue *atk_value)
-{
-  double value;
-  gchar *description;
-  AtkRange *range;
-  GSList *sub_ranges;
-  GSList *iter;
-  gdouble increment;
-  gint i = 0;
-
-  atk_value_get_value_and_text (atk_value, &value, &description);
-  range = atk_value_get_range (atk_value);
-  increment = atk_value_get_increment (atk_value);
-  atk_value_set_value (atk_value, 0);
-
-  g_print ("Current AtkValue data:\n");
-  g_print ("\t (value,description)=(%f,%s) \n", value, description);
-  if (range != NULL)
-    g_print ("\t (min,max,description)=(%f, %f, %s)\n",
-             atk_range_get_lower_limit (range), atk_range_get_upper_limit (range), atk_range_get_description 
(range));
-  else
-    test_success = FALSE; /* Any AtkValue implementation should provide a range */
-  g_print ("\t minimum increment=%f\n", increment);
-
-  if (range)
-    atk_range_free (range);
-
-  sub_ranges = atk_value_get_sub_ranges (atk_value);
-  for (iter = sub_ranges; iter != NULL; iter = g_slist_next (iter),i++) {
-    range = iter->data;
-    g_print ("\t\t sub_range%i = (%f, %f, %s)\n", i,
-             atk_range_get_lower_limit (range), atk_range_get_upper_limit (range), atk_range_get_description 
(range));
-  }
-
-  g_slist_free_full (sub_ranges, (GDestroyNotify) atk_range_free);
-}
-
-
-static gboolean
-init_test_value (void)
+test_page_changed (void)
 {
-  my_value = g_object_new (TEST_TYPE_VALUE, NULL);
+  TestValue *my_value = TEST_VALUE (g_object_new (TEST_TYPE_VALUE, NULL));
 
   g_signal_connect (my_value, "value-changed",
                     G_CALLBACK (value_page_changed_cb),
                     NULL);
 
-  print_info (ATK_VALUE (my_value));
-
   g_idle_add (do_value_changed, my_value);
 
-  return TRUE;
-}
+  my_value->loop = g_main_loop_new (NULL, FALSE);
 
+  g_main_loop_run (my_value->loop);
+
+  g_assert_cmpint (my_value->number_emissions, ==, EXPECTED_NUMBER);
+  g_main_loop_unref (my_value->loop);
+  g_object_unref (my_value);
+}
 
 int
 main (gint  argc,
       char* argv[])
 {
-  global_loop = g_main_loop_new (NULL, FALSE);
+  g_test_init (&argc, &argv, NULL);
+  g_test_add_func ("/atk/value/page_changed", test_page_changed);
 
-  g_print("Starting Value test suite\n\n\n");
-
-  init_test_value ();
-  g_main_loop_run (global_loop);
-
-  if (global_number_emissions == EXPECTED_NUMBER && test_success)
-    g_print ("\n\nValue tests succeeded\n\n\n");
-  else
-    g_print ("\n\nValue tests failed\n\n\n");
-
-  print_info (ATK_VALUE (my_value));
-
-  return 0;
+  return g_test_run ();
 }
+


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