[at-spi2-core: 5/10] tests: Don't assume ordering of attributes in AtkAccessible




commit 9789f9d1709db8ebde8d05eb900c57a14b101344
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Jul 4 18:22:11 2022 -0500

    tests: Don't assume ordering of attributes in AtkAccessible
    
    While we are at it, test having more than one attribute.

 tests/at-spi2-atk/atk_test_accessible.c    | 40 +++++++++++++++++++-----------
 tests/at-spi2-atk/dummyatk/my-atk-object.c | 14 +++++++----
 2 files changed, 35 insertions(+), 19 deletions(-)
---
diff --git a/tests/at-spi2-atk/atk_test_accessible.c b/tests/at-spi2-atk/atk_test_accessible.c
index 2ab74a13..e6afd9f9 100644
--- a/tests/at-spi2-atk/atk_test_accessible.c
+++ b/tests/at-spi2-atk/atk_test_accessible.c
@@ -159,28 +159,40 @@ atk_test_accessible_get_attributes (gpointer fixture, gconstpointer user_data)
   GHashTableIter iter;
   gpointer key, value;
 
-  gchar *valid_keys[] = { "atspi" };
-  gchar *valid_values[] = { "test" };
+  g_hash_table_iter_init (&iter, attr_hash_tab);
 
-  g_hash_table_iter_init (&iter, attr_hash_tab );
-  int i = 0;
-  while (g_hash_table_iter_next (&iter, &key, &value)) {
-    g_assert_cmpstr (valid_keys[i], ==, (gchar *)key );
-    g_assert_cmpstr (valid_values[i], ==, (gchar *)value );
-    ++i;
-  }
+  while (g_hash_table_iter_next (&iter, &key, &value))
+    {
+      const char *key_str = key;
+      const char *value_str = value;
+
+      if (strcmp (key_str, "atspi1") == 0)
+        {
+          g_assert_cmpstr (value_str, ==, "test1");
+        }
+      else if (strcmp (key_str, "atspi2") == 0)
+        {
+          g_assert_cmpstr (value_str, ==, "test2");
+        }
+      else
+        {
+          g_assert_not_reached ();
+        }
+    }
 }
 
 static void
 atk_test_accessible_get_attributes_as_array (gpointer fixture, gconstpointer user_data)
 {
   AtspiAccessible *obj = get_root_obj (DATA_FILE);
-  gchar *valid_attr[] = { "atspi:test", NULL };
   GArray *attr_arr = atspi_accessible_get_attributes_as_array ( obj, NULL);
-  int i = 0;
-  g_assert (attr_arr->len == (sizeof(valid_attr)/sizeof(gchar *))-1);
-  for( i = 0; i < attr_arr->len; ++i) {
-    g_assert_cmpstr (valid_attr[i], ==, g_array_index (attr_arr, gchar *, i));
+  int i;
+  g_assert_cmpint (attr_arr->len, ==, 2);
+  for(i = 0; i < attr_arr->len; ++i) {
+    const char *pair = g_array_index (attr_arr, gchar *, i);
+
+    g_assert (strcmp (pair, "atspi1:test1") == 0
+              || strcmp (pair, "atspi2:test2") == 0);
   }
 }
 
diff --git a/tests/at-spi2-atk/dummyatk/my-atk-object.c b/tests/at-spi2-atk/dummyatk/my-atk-object.c
index 05b542c4..70950456 100644
--- a/tests/at-spi2-atk/dummyatk/my-atk-object.c
+++ b/tests/at-spi2-atk/dummyatk/my-atk-object.c
@@ -125,14 +125,18 @@ static AtkStateSet *my_atk_object_ref_state_set (AtkObject *accessible)
 
 static AtkAttributeSet *my_atk_object_get_attributes (AtkObject *accessible)
 {
-  AtkAttributeSet *attributes;
+  AtkAttributeSet *attributes = NULL;
   AtkAttribute *attr;
 
-  attr = g_malloc (sizeof (AtkAttribute));
-  attr->name = g_strdup ("atspi");
-  attr->value = g_strdup ("test");
+  attr = g_new0 (AtkAttribute, 1);
+  attr->name = g_strdup ("atspi1");
+  attr->value = g_strdup ("test1");
+  attributes = g_slist_prepend (attributes, attr);
 
-  attributes = g_slist_append (NULL, attr);
+  attr = g_new0 (AtkAttribute, 1);
+  attr->name = g_strdup ("atspi2");
+  attr->value = g_strdup ("test2");
+  attributes = g_slist_prepend (attributes, attr);
 
   return attributes;
 }


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