win32/vsX: Fix 'make dist'
[platform/upstream/atk.git] / tests / testrelation.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <atk/atk.h>
21
22 #include <string.h>
23
24 static gboolean
25 test_relation (void)
26 {
27   AtkRelationType type1, type2;
28   const gchar *name;
29   AtkObject *obj;
30   gboolean ret_value;
31   AtkRelationSet *set;
32   AtkRelation *relation;
33   gint n_relations;
34   GPtrArray *array; 
35
36   name = atk_relation_type_get_name (ATK_RELATION_LABEL_FOR);
37   g_return_val_if_fail (name, FALSE);
38   if (strcmp (name, "label-for") != 0)
39     {
40       g_print ("Unexpected name for ATK_RELATION_LABEL_FOR %s\n", name);
41       return FALSE;
42     }
43
44   name = atk_relation_type_get_name (ATK_RELATION_NODE_CHILD_OF);
45   g_return_val_if_fail (name, FALSE);
46   if (strcmp (name, "node-child-of") != 0)
47     {
48       g_print ("Unexpected name for ATK_RELATION_NODE_CHILD_OF %s\n", name);
49       return FALSE;
50     }
51
52   name = atk_relation_type_get_name (ATK_RELATION_EMBEDS);
53   g_return_val_if_fail (name, FALSE);
54   if (strcmp (name, "embeds") != 0)
55     {
56       g_print ("Unexpected name for ATK_RELATION_EMBEDS %s\n", name);
57       return FALSE;
58     }
59
60   type1 = atk_relation_type_for_name ("embedded-by");
61   if (type1 != ATK_RELATION_EMBEDDED_BY)
62     {
63       g_print ("Unexpected role for ATK_RELATION_EMBEDDED_BY\n");
64       return FALSE;
65     }
66
67   type1 = atk_relation_type_for_name ("controlled-by");
68   if (type1 != ATK_RELATION_CONTROLLED_BY)
69     {
70       g_print ("Unexpected name for ATK_RELATION_CONTROLLED_BY\n");
71       return FALSE;
72     }
73
74   type1 = atk_relation_type_register ("test-state");
75   name = atk_relation_type_get_name (type1);
76   g_return_val_if_fail (name, FALSE);
77   if (strcmp (name, "test-state") != 0)
78     {
79       g_print ("Unexpected name for test-state %s\n", name);
80       return FALSE;
81     }
82   type2 = atk_relation_type_for_name ("test-state");
83   if (type1 != type2)
84   {
85     g_print ("Unexpected type for test-state\n");
86     return FALSE;
87   }
88   type2 = atk_relation_type_for_name ("TEST_STATE");
89   if (type2 != 0)
90     {
91       g_print ("Unexpected type for TEST_STATE\n");
92       return FALSE;
93     }
94   /*
95    * Check that a non-existent type returns NULL
96    */
97   name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
98   if (name)
99     {
100       g_print ("Unexpected name for undefined type %s\n", name);
101       return FALSE;
102     }
103
104   obj = g_object_new (ATK_TYPE_OBJECT, NULL);
105   ret_value = atk_object_add_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
106   if (!ret_value)
107     {
108       g_print ("Unexpected return value for atk_object_add_relationship\n");
109       return FALSE;
110     }
111   set = atk_object_ref_relation_set (obj);
112   if (!set)
113     {
114       g_print ("Unexpected return value for atk_object_ref_relation_set\n");
115       return FALSE;
116     }
117   n_relations = atk_relation_set_get_n_relations (set);
118   if (n_relations != 1)
119     {
120       g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", n_relations, 1);
121       return FALSE;
122     }
123   relation = atk_relation_set_get_relation (set, 0);  
124   if (!relation)
125     {
126       g_print ("Unexpected return value for atk_object_relation_set_get_relation\n");
127       return FALSE;
128     }
129   type1 = atk_relation_get_relation_type (relation);
130   if (type1 != ATK_RELATION_LABEL_FOR)
131     {
132       g_print ("Unexpected return value for atk_relation_get_relation_type\n");
133       return FALSE;
134     }
135   array = atk_relation_get_target (relation);
136   if (obj != g_ptr_array_index (array, 0))
137     {
138       g_print ("Unexpected return value for atk_relation_get_target\n");
139       return FALSE;
140     }
141   g_object_unref (set);
142   ret_value = atk_object_remove_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
143   if (!ret_value)
144     {
145       g_print ("Unexpected return value for atk_object_remove_relationship\n");
146       return FALSE;
147     }
148   set = atk_object_ref_relation_set (obj);
149   if (!set)
150     {
151       g_print ("Unexpected return value for atk_object_ref_relation_set\n");
152       return FALSE;
153     }
154   n_relations = atk_relation_set_get_n_relations (set);
155   if (n_relations != 0)
156     {
157       g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", n_relations, 0);
158       return FALSE;
159     }
160   g_object_unref (set);
161   g_object_unref (obj);
162   return TRUE;
163 }
164
165 static gboolean
166 test_text_attr (void)
167 {
168   AtkTextAttribute attr1, attr2;
169   const gchar *name;
170
171   name = atk_text_attribute_get_name (ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
172   g_return_val_if_fail (name, FALSE);
173   if (strcmp (name, "pixels-inside-wrap") != 0)
174     {
175       g_print ("Unexpected name for ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP %s\n", name);
176       return FALSE;
177     }
178
179   name = atk_text_attribute_get_name (ATK_TEXT_ATTR_BG_STIPPLE);
180   g_return_val_if_fail (name, FALSE);
181   if (strcmp (name, "bg-stipple") != 0)
182     {
183       g_print ("Unexpected name for ATK_TEXT_ATTR_BG_STIPPLE %s\n", name);
184       return FALSE;
185     }
186
187   attr1 = atk_text_attribute_for_name ("left-margin");
188   if (attr1 != ATK_TEXT_ATTR_LEFT_MARGIN)
189     {
190       g_print ("Unexpected attribute for left-margin\n");
191       return FALSE;
192     }
193
194   attr1 = atk_text_attribute_register ("test-attribute");
195   name = atk_text_attribute_get_name (attr1);
196   g_return_val_if_fail (name, FALSE);
197   if (strcmp (name, "test-attribute") != 0)
198     {
199       g_print ("Unexpected name for test-attribute %s\n", name);
200       return FALSE;
201     }
202   attr2 = atk_text_attribute_for_name ("test-attribute");
203   if (attr1 != attr2)
204   {
205     g_print ("Unexpected attribute for test-attribute\n");
206     return FALSE;
207   }
208   attr2 = atk_text_attribute_for_name ("TEST_ATTR");
209   if (attr2 != 0)
210     {
211       g_print ("Unexpected attribute for TEST_ATTR\n");
212       return FALSE;
213     }
214   /*
215    * Check that a non-existent attribute returns NULL
216    */
217   name = atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
218   if (name)
219     {
220       g_print ("Unexpected name for undefined attribute %s\n", name);
221       return FALSE;
222     }
223   return TRUE;
224 }
225
226 int
227 main (gint  argc,
228       char* argv[])
229 {
230   gboolean b_ret;
231
232   g_print("Starting Relation test suite\n");
233
234   b_ret = test_relation ();
235   if (b_ret)
236     g_print ("Relation tests succeeded\n");
237   else
238     g_print ("Relation tests failed\n");
239
240   b_ret = test_text_attr ();
241   if (b_ret)
242     g_print ("Text Attribute tests succeeded\n");
243   else
244     g_print ("Text Attribute tests failed\n");
245
246   return 0;
247 }