Use generated enum type for AtkRole to get the role name
[platform/upstream/atk.git] / tests / testrole.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright (C) 2013 Igalia, S.L.
3  *
4  * Author: Alejandro PiƱeiro Iglesias <apinheiro@igalia.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 #include <atk/atk.h>
22 #include <string.h>
23
24 static gboolean
25 test_role (void)
26 {
27   AtkRole role1, role2;
28   const gchar *name;
29   gboolean result = TRUE;
30
31   name = atk_role_get_name (ATK_ROLE_PAGE_TAB);
32   if (!name || strcmp (name, "page tab") != 0)
33     {
34       g_print ("Unexpected name for ATK_ROLE_PAGE_TAB."
35                " Expected 'page tab', received '%s'\n", name);
36       result = FALSE;
37     }
38
39   name = atk_role_get_name (ATK_ROLE_LAYERED_PANE);
40   if (!name || strcmp (name, "layered pane") != 0)
41     {
42       g_print ("Unexpected name for ATK_ROLE_LAYERED_PANE."
43                " Expected 'layered pane', received '%s'\n", name);
44       result = FALSE;
45     }
46
47   role1 = atk_role_for_name ("list item");
48   if (role1 != ATK_ROLE_LIST_ITEM)
49     {
50       g_print ("Unexpected role for list item."
51                " Expected %i, received %i\n", ATK_ROLE_LIST_ITEM, role1);
52       result = FALSE;
53     }
54
55   role1 = atk_role_register ("test-role");
56   name = atk_role_get_name (role1);
57   if (!name || strcmp (name, "test-role") != 0)
58     {
59       g_print ("Unexpected name for test-role. Expected 'test-role', received '%s'\n", name);
60       result = FALSE;
61     }
62   role2 = atk_role_for_name ("test-role");
63   if (role1 != role2)
64   {
65     g_print ("Unexpected role for test-role. Expected %i, received %i\n", role1, role2);
66     result = FALSE;
67   }
68   role2 = atk_role_for_name ("TEST_ROLE");
69   if (role2 != 0)
70     {
71       g_print ("Unexpected role for TEST_ROLE. Expected %i, received %i\n", 0, role2);
72       result = FALSE;
73     }
74   /*
75    * Check that a non-existent role returns NULL
76    */
77   name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
78   if (name)
79     {
80       g_print ("Unexpected name for undefined role %s\n", name);
81       result = FALSE;
82     }
83   return result;
84 }
85
86 static void
87 print_roles()
88 {
89   AtkRole role;
90
91   g_print("(Role, name, localized name) defined by the ATK library:\n");
92
93   for (role = ATK_ROLE_INVALID; role < ATK_ROLE_LAST_DEFINED; role++)
94     g_print ("(%i, %s, %s)\n", role,
95              atk_role_get_name(role), atk_role_get_localized_name(role));
96
97   g_print("(Role, name, localized name) for the extra roles:\n");
98   for (;atk_role_get_name(role) != NULL; role++)
99     g_print ("(%i, %s, %s)\n", role,
100              atk_role_get_name(role), atk_role_get_localized_name(role));
101
102 }
103
104 int
105 main (int argc, char **argv)
106 {
107   gboolean b_ret;
108
109   g_print ("Starting Role test suite\n");
110
111   b_ret = test_role ();
112
113   print_roles();
114
115   if (b_ret)
116     g_print ("Role tests succeeded\n");
117   else
118     g_print ("Role tests failed\n");
119
120   return 0;
121 }