Change atk_relation_type_from_string to atk_relation_type_for_name Add
[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
26 static gboolean
27 test_relation (void)
28 {
29   AtkRelationType type1, type2;
30   G_CONST_RETURN gchar *name;
31
32   name = atk_relation_type_get_name (ATK_RELATION_LABEL_FOR);
33   g_return_val_if_fail (name, FALSE);
34   if (strcmp (name, "label_for") != 0)
35     {
36       g_print ("Unexpected name for ATK_RELATION_LABEL_FOR %s\n", name);
37       return FALSE;
38     }
39
40   name = atk_relation_type_get_name (ATK_RELATION_NODE_CHILD_OF);
41   g_return_val_if_fail (name, FALSE);
42   if (strcmp (name, "node_child_of") != 0)
43     {
44       g_print ("Unexpected name for ATK_STATE_MODAL %s\n", name);
45       return FALSE;
46     }
47
48   type1 = atk_relation_type_for_name ("controlled_by");
49   if (type1 != ATK_RELATION_CONTROLLED_BY)
50     {
51       g_print ("Unexpected type for focused\n");
52       return FALSE;
53     }
54
55   type1 = atk_relation_type_register ("test_state");
56   name = atk_relation_type_get_name (type1);
57   g_return_val_if_fail (name, FALSE);
58   if (strcmp (name, "test_state") != 0)
59     {
60       g_print ("Unexpected name for test_state %s\n", name);
61       return FALSE;
62     }
63   type2 = atk_relation_type_for_name ("test_state");
64   if (type1 != type2)
65   {
66     g_print ("Unexpected type for test_state\n");
67     return FALSE;
68   }
69   type2 = atk_relation_type_for_name ("TEST-STATE");
70   if (type2 != 0)
71     {
72       g_print ("Unexpected type for TEST-STATE\n");
73       return FALSE;
74     }
75   /*
76    * Check that a non-existent type returns NULL
77    */
78   name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
79   if (name)
80     {
81       g_print ("Unexpected name for undefined type\n");
82       return FALSE;
83     }
84   return TRUE;
85 }
86
87 int
88 gtk_module_init (gint  argc, 
89                  char* argv[])
90 {
91   gboolean b_ret;
92
93   g_print("Relation test module loaded\n");
94
95   b_ret = test_relation ();
96   if (b_ret)
97     g_print ("Relation tests succeeded\n");
98   else
99     g_print ("Relation tests failed\n");
100   return 0;
101 }