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 void
25
1
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
1
  name = atk_relation_type_get_name (ATK_RELATION_LABEL_FOR);
37
1
  g_assert_cmpstr (name, ==, "label-for");
38

            
39
1
  name = atk_relation_type_get_name (ATK_RELATION_NODE_CHILD_OF);
40
1
  g_assert_cmpstr (name, ==, "node-child-of");
41

            
42
1
  name = atk_relation_type_get_name (ATK_RELATION_EMBEDS);
43
1
  g_assert_cmpstr (name, ==, "embeds");
44

            
45
1
  type1 = atk_relation_type_for_name ("embedded-by");
46
1
  g_assert_cmpint (type1, ==, ATK_RELATION_EMBEDDED_BY);
47

            
48
1
  type1 = atk_relation_type_for_name ("controlled-by");
49
1
  g_assert_cmpint (type1, ==, ATK_RELATION_CONTROLLED_BY);
50

            
51
1
  type1 = atk_relation_type_register ("test-state");
52
1
  name = atk_relation_type_get_name (type1);
53
1
  g_assert_cmpstr (name, ==, "test-state");
54
1
  type2 = atk_relation_type_for_name ("test-state");
55
1
  g_assert_cmpint (type1, ==, type2);
56
1
  type2 = atk_relation_type_for_name ("TEST_STATE");
57
1
  g_assert_cmpint (type2, ==, 0);
58
  /*
59
   * Check that a non-existent type returns NULL
60
   */
61
1
  g_assert_null (atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2));
62

            
63
1
  obj = g_object_new (ATK_TYPE_OBJECT, NULL);
64
1
  ret_value = atk_object_add_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
65
1
  g_assert_cmpint (ret_value, !=, 0);
66
1
  set = atk_object_ref_relation_set (obj);
67
1
  g_assert_nonnull (set);
68
1
  n_relations = atk_relation_set_get_n_relations (set);
69
1
  g_assert_cmpint (n_relations, ==, 1);
70
1
  relation = atk_relation_set_get_relation (set, 0);
71
1
  g_assert_nonnull (relation);
72
1
  type1 = atk_relation_get_relation_type (relation);
73
1
  g_assert_cmpint (type1, ==, ATK_RELATION_LABEL_FOR);
74
1
  array = atk_relation_get_target (relation);
75
1
  g_assert_true (obj == g_ptr_array_index (array, 0));
76
1
  g_object_unref (set);
77
1
  g_assert_true (atk_object_remove_relationship (obj, ATK_RELATION_LABEL_FOR, obj));
78
1
  set = atk_object_ref_relation_set (obj);
79
1
  g_assert_nonnull (set);
80
1
  n_relations = atk_relation_set_get_n_relations (set);
81
1
  g_assert_cmpint (n_relations, ==, 0);
82
1
  g_object_unref (set);
83
1
  g_object_unref (obj);
84
1
}
85

            
86
static void
87
1
test_text_attr (void)
88
{
89
  AtkTextAttribute attr1, attr2;
90
  const gchar *name;
91

            
92
1
  name = atk_text_attribute_get_name (ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
93
1
  g_assert_cmpstr (name, ==, "pixels-inside-wrap");
94

            
95
1
  name = atk_text_attribute_get_name (ATK_TEXT_ATTR_BG_STIPPLE);
96
1
  g_assert_cmpstr (name, ==, "bg-stipple");
97

            
98
1
  attr1 = atk_text_attribute_for_name ("left-margin");
99
1
  g_assert_cmpint (attr1, ==, ATK_TEXT_ATTR_LEFT_MARGIN);
100

            
101
1
  attr1 = atk_text_attribute_register ("test-attribute");
102
1
  name = atk_text_attribute_get_name (attr1);
103
1
  g_assert_cmpstr (name, ==, "test-attribute");
104
1
  attr2 = atk_text_attribute_for_name ("test-attribute");
105
1
  g_assert_cmpint (attr1, ==, attr2);
106
1
  g_assert_cmpint (atk_text_attribute_for_name ("TEST_ATTR"), ==, 0);
107
  /*
108
   * Check that a non-existent attribute returns NULL
109
   */
110
1
  g_assert_null (atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2));
111
1
}
112

            
113
int
114
1
main (gint argc,
115
      char *argv[])
116
{
117
1
  g_test_init (&argc, &argv, NULL);
118
1
  g_test_add_func ("/atk/relation/relation", test_relation);
119
1
  g_test_add_func ("/atk/relation/text_attr", test_text_attr);
120

            
121
1
  return g_test_run ();
122
}