Visual Studio builds: Don't build introspection by default
[platform/upstream/atk.git] / tests / testrelation.c
index 9ffaec2..6cc0be5 100644 (file)
 
 #include <string.h>
 
-static gboolean  test_relation (void);
-
 static gboolean
 test_relation (void)
 {
   AtkRelationType type1, type2;
-  G_CONST_RETURN gchar *name;
+  const gchar *name;
+  AtkObject *obj;
+  gboolean ret_value;
+  AtkRelationSet *set;
+  AtkRelation *relation;
+  gint n_relations;
+  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)
+  if (strcmp (name, "label-for") != 0)
     {
       g_print ("Unexpected name for ATK_RELATION_LABEL_FOR %s\n", name);
       return FALSE;
@@ -39,37 +43,52 @@ test_relation (void)
 
   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)
+  if (strcmp (name, "node-child-of") != 0)
+    {
+      g_print ("Unexpected name for ATK_RELATION_NODE_CHILD_OF %s\n", name);
+      return FALSE;
+    }
+
+  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;
+    }
+
+  type1 = atk_relation_type_for_name ("embedded-by");
+  if (type1 != ATK_RELATION_EMBEDDED_BY)
     {
-      g_print ("Unexpected name for ATK_STATE_MODAL %s\n", name);
+      g_print ("Unexpected role for ATK_RELATION_EMBEDDED_BY\n");
       return FALSE;
     }
 
-  type1 = atk_relation_type_for_name ("controlled_by");
+  type1 = atk_relation_type_for_name ("controlled-by");
   if (type1 != ATK_RELATION_CONTROLLED_BY)
     {
-      g_print ("Unexpected type for focused\n");
+      g_print ("Unexpected name for ATK_RELATION_CONTROLLED_BY\n");
       return FALSE;
     }
 
-  type1 = atk_relation_type_register ("test_state");
+  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)
+  if (strcmp (name, "test-state") != 0)
     {
-      g_print ("Unexpected name for test_state %s\n", name);
+      g_print ("Unexpected name for test-state %s\n", name);
       return FALSE;
     }
-  type2 = atk_relation_type_for_name ("test_state");
+  type2 = atk_relation_type_for_name ("test-state");
   if (type1 != type2)
   {
-    g_print ("Unexpected type for test_state\n");
+    g_print ("Unexpected type for test-state\n");
     return FALSE;
   }
-  type2 = atk_relation_type_for_name ("TEST-STATE");
+  type2 = atk_relation_type_for_name ("TEST_STATE");
   if (type2 != 0)
     {
-      g_print ("Unexpected type for TEST-STATE\n");
+      g_print ("Unexpected type for TEST_STATE\n");
       return FALSE;
     }
   /*
@@ -78,24 +97,151 @@ test_relation (void)
   name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
   if (name)
     {
-      g_print ("Unexpected name for undefined type\n");
+      g_print ("Unexpected name for undefined type %s\n", name);
+      return FALSE;
+    }
+
+  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;
+    }
+  set = atk_object_ref_relation_set (obj);
+  if (!set)
+    {
+      g_print ("Unexpected return value for atk_object_ref_relation_set\n");
+      return FALSE;
+    }
+  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;
+    }
+  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;
+    }
+  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;
+    }
+  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_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;
+    }
+  set = atk_object_ref_relation_set (obj);
+  if (!set)
+    {
+      g_print ("Unexpected return value for atk_object_ref_relation_set\n");
+      return FALSE;
+    }
+  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_object_unref (set);
+  g_object_unref (obj);
+  return TRUE;
+}
+
+static gboolean
+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;
+    }
+
+  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;
+    }
+
+  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;
+    }
+
+  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;
+    }
+  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;
+    }
+  /*
+   * 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;
 }
 
 int
-gtk_module_init (gint  argc, 
-                 char* argv[])
+main (gint  argc,
+      char* argv[])
 {
   gboolean b_ret;
 
-  g_print("Relation test module loaded\n");
+  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;
 }