Updated FSF's address
[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, see <http://www.gnu.org/licenses/>.
18  */
19 #include <atk/atk.h>
20 #include <string.h>
21
22 static gboolean
23 test_role (void)
24 {
25   AtkRole role1, role2;
26   const gchar *name;
27   gboolean result = TRUE;
28
29   name = atk_role_get_name (ATK_ROLE_PAGE_TAB);
30   if (!name || strcmp (name, "page tab") != 0)
31     {
32       g_print ("Unexpected name for ATK_ROLE_PAGE_TAB."
33                " Expected 'page tab', received '%s'\n", name);
34       result = FALSE;
35     }
36
37   name = atk_role_get_name (ATK_ROLE_LAYERED_PANE);
38   if (!name || strcmp (name, "layered pane") != 0)
39     {
40       g_print ("Unexpected name for ATK_ROLE_LAYERED_PANE."
41                " Expected 'layered pane', received '%s'\n", name);
42       result = FALSE;
43     }
44
45   role1 = atk_role_for_name ("list item");
46   if (role1 != ATK_ROLE_LIST_ITEM)
47     {
48       g_print ("Unexpected role for list item."
49                " Expected %i, received %i\n", ATK_ROLE_LIST_ITEM, role1);
50       result = FALSE;
51     }
52
53   role2 = atk_role_for_name ("TEST_ROLE");
54   if (role2 != ATK_ROLE_INVALID)
55     {
56       g_print ("Unexpected role for TEST_ROLE. Expected %i, received %i\n", ATK_ROLE_INVALID, role2);
57       result = FALSE;
58     }
59   /*
60    * Check that a non-existent role returns NULL
61    */
62   name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
63   if (name)
64     {
65       g_print ("Unexpected name for undefined role %s\n", name);
66       result = FALSE;
67     }
68
69   return result;
70 }
71
72 static void
73 print_roles()
74 {
75   AtkRole role;
76
77   g_print("(Role, name, localized name) defined by the ATK library:\n");
78
79   for (role = ATK_ROLE_INVALID; role < ATK_ROLE_LAST_DEFINED; role++)
80     g_print ("(%i, %s, %s)\n", role,
81              atk_role_get_name(role), atk_role_get_localized_name(role));
82
83   g_print("(Role, name, localized name) for the extra roles:\n");
84   for (;atk_role_get_name(role) != NULL; role++)
85     g_print ("(%i, %s, %s)\n", role,
86              atk_role_get_name(role), atk_role_get_localized_name(role));
87
88 }
89
90 int
91 main (int argc, char **argv)
92 {
93   gboolean b_ret;
94
95   g_print ("Starting Role test suite\n");
96
97   b_ret = test_role ();
98
99   print_roles();
100
101   if (b_ret)
102     g_print ("Role tests succeeded\n");
103   else
104     g_print ("Role tests failed\n");
105
106   return 0;
107 }