Add implementation of atk_attribute_register, atk_attribute_for_name Udate
[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  test_relation (void);
25 static gboolean  test_role (void);
26
27 static gboolean
28 test_relation (void)
29 {
30   AtkRelationType type1, type2;
31   G_CONST_RETURN gchar *name;
32
33   name = atk_relation_type_get_name (ATK_RELATION_LABEL_FOR);
34   g_return_val_if_fail (name, FALSE);
35   if (strcmp (name, "label-for") != 0)
36     {
37       g_print ("Unexpected name for ATK_RELATION_LABEL_FOR %s\n", name);
38       return FALSE;
39     }
40
41   name = atk_relation_type_get_name (ATK_RELATION_NODE_CHILD_OF);
42   g_return_val_if_fail (name, FALSE);
43   if (strcmp (name, "node-child-of") != 0)
44     {
45       g_print ("Unexpected name for ATK_RELATION_NODE_CHILD_OF %s\n", name);
46       return FALSE;
47     }
48
49   type1 = atk_relation_type_for_name ("controlled-by");
50   if (type1 != ATK_RELATION_CONTROLLED_BY)
51     {
52       g_print ("Unexpected type for focused\n");
53       return FALSE;
54     }
55
56   type1 = atk_relation_type_register ("test-state");
57   name = atk_relation_type_get_name (type1);
58   g_return_val_if_fail (name, FALSE);
59   if (strcmp (name, "test-state") != 0)
60     {
61       g_print ("Unexpected name for test-state %s\n", name);
62       return FALSE;
63     }
64   type2 = atk_relation_type_for_name ("test-state");
65   if (type1 != type2)
66   {
67     g_print ("Unexpected type for test-state\n");
68     return FALSE;
69   }
70   type2 = atk_relation_type_for_name ("TEST_STATE");
71   if (type2 != 0)
72     {
73       g_print ("Unexpected type for TEST_STATE\n");
74       return FALSE;
75     }
76   /*
77    * Check that a non-existent type returns NULL
78    */
79   name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
80   if (name)
81     {
82       g_print ("Unexpected name for undefined type %s\n", name);
83       return FALSE;
84     }
85   return TRUE;
86 }
87
88 static gboolean
89 test_role (void)
90 {
91   AtkRole role1, role2;
92   G_CONST_RETURN gchar *name;
93
94   name = atk_role_get_name (ATK_ROLE_PAGE_TAB);
95   g_return_val_if_fail (name, FALSE);
96   if (strcmp (name, "page-tab") != 0)
97     {
98       g_print ("Unexpected name for ATK_ROLE_PAGE_TAB %s\n", name);
99       return FALSE;
100     }
101
102   name = atk_role_get_name (ATK_ROLE_LAYERED_PANE);
103   g_return_val_if_fail (name, FALSE);
104   if (strcmp (name, "layered-pane") != 0)
105     {
106       g_print ("Unexpected name for ATK_ROLE_LAYERED_PANE %s\n", name);
107       return FALSE;
108     }
109
110   role1 = atk_role_for_name ("list-item");
111   if (role1 != ATK_ROLE_LIST_ITEM)
112     {
113       g_print ("Unexpected role for list-item\n");
114       return FALSE;
115     }
116
117   role1 = atk_role_register ("test-role");
118   name = atk_role_get_name (role1);
119   g_return_val_if_fail (name, FALSE);
120   if (strcmp (name, "test-role") != 0)
121     {
122       g_print ("Unexpected name for test-role %s\n", name);
123       return FALSE;
124     }
125   role2 = atk_role_for_name ("test-role");
126   if (role1 != role2)
127   {
128     g_print ("Unexpected role for test-role\n");
129     return FALSE;
130   }
131   role2 = atk_role_for_name ("TEST_ROLE");
132   if (role2 != 0)
133     {
134       g_print ("Unexpected role for TEST_ROLE\n");
135       return FALSE;
136     }
137   /*
138    * Check that a non-existent role returns NULL
139    */
140   name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
141   if (name)
142     {
143       g_print ("Unexpected name for undefined role %s\n", name);
144       return FALSE;
145     }
146   return TRUE;
147 }
148
149 static gboolean
150 test_text_attr (void)
151 {
152   AtkTextAttribute attr1, attr2;
153   G_CONST_RETURN gchar *name;
154
155   name = atk_attribute_get_name (ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
156   g_return_val_if_fail (name, FALSE);
157   if (strcmp (name, "pixels-inside-wrap") != 0)
158     {
159       g_print ("Unexpected name for ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP %s\n", name);
160       return FALSE;
161     }
162
163   name = atk_attribute_get_name (ATK_TEXT_ATTR_BG_STIPPLE);
164   g_return_val_if_fail (name, FALSE);
165   if (strcmp (name, "bg-stipple") != 0)
166     {
167       g_print ("Unexpected name for ATK_TEXT_ATTR_BG_STIPPLE %s\n", name);
168       return FALSE;
169     }
170
171   attr1 = atk_attribute_for_name ("left-margin");
172   if (attr1 != ATK_TEXT_ATTR_LEFT_MARGIN)
173     {
174       g_print ("Unexpected attribute for left-margin\n");
175       return FALSE;
176     }
177
178   attr1 = atk_attribute_register ("test-attribute");
179   name = atk_attribute_get_name (attr1);
180   g_return_val_if_fail (name, FALSE);
181   if (strcmp (name, "test-attribute") != 0)
182     {
183       g_print ("Unexpected name for test-attribute %s\n", name);
184       return FALSE;
185     }
186   attr2 = atk_attribute_for_name ("test-attribute");
187   if (attr1 != attr2)
188   {
189     g_print ("Unexpected attribute for test-attribute\n");
190     return FALSE;
191   }
192   attr2 = atk_attribute_for_name ("TEST_ATTR");
193   if (attr2 != 0)
194     {
195       g_print ("Unexpected attribute for TEST_ATTR\n");
196       return FALSE;
197     }
198   /*
199    * Check that a non-existent attribute returns NULL
200    */
201   name = atk_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
202   if (name)
203     {
204       g_print ("Unexpected name for undefined attribute %s\n", name);
205       return FALSE;
206     }
207   return TRUE;
208 }
209
210 int
211 gtk_module_init (gint  argc, 
212                  char* argv[])
213 {
214   gboolean b_ret;
215
216   g_print("Relation test module loaded\n");
217
218   b_ret = test_relation ();
219   if (b_ret)
220     g_print ("Relation tests succeeded\n");
221   else
222     g_print ("Relation tests failed\n");
223   b_ret = test_role ();
224   if (b_ret)
225     g_print ("Role tests succeeded\n");
226   else
227     g_print ("Role tests failed\n");
228   b_ret = test_text_attr ();
229   if (b_ret)
230     g_print ("Text Attribute tests succeeded\n");
231   else
232     g_print ("Text Attribute tests failed\n");
233   return 0;
234 }