forked from ruby-gnome/ruby-gnome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_gtk_builder.rb
166 lines (146 loc) · 4 KB
/
test_gtk_builder.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
class TestGtkBuilder < Test::Unit::TestCase
include GtkTestUtils
def test_constants
assert_kind_of(Gtk::BuilderError, Gtk::BuilderError::INVALID_TAG)
end
def test_new
assert_nothing_raised do
Gtk::Builder.new
end
end
def test_add_from_file
builder = Gtk::Builder.new
assert_nothing_raised do
builder.add_from_file(ui_definition_file.path)
end
assert_kind_of(Gtk::Dialog, builder["dialog1"])
end
def test_add_from_string
builder = Gtk::Builder.new
assert_nothing_raised do
builder.add_from_string(ui_definition)
end
assert_kind_of(Gtk::Box, builder["vbox1"])
end
def test_add_with_file
builder = Gtk::Builder.new
assert_nothing_raised do
builder.add(ui_definition_file.path)
end
assert_kind_of(Gtk::ButtonBox, builder["hbuttonbox1"])
end
def test_add_with_string
builder = Gtk::Builder.new
assert_nothing_raised do
builder.add(ui_definition)
end
assert_kind_of(Gtk::Button, builder["ok_button"])
end
def test_add_chain
builder = Gtk::Builder.new
assert_nothing_raised do
builder << ui_definition_file.path << ui_definition_simple
end
assert_kind_of(Gtk::Dialog, builder["dialog1"])
assert_kind_of(Gtk::Window, builder["main-window"])
end
def test_objects
builder = Gtk::Builder.new
assert_nothing_raised do
builder << ui_definition_file.path << ui_definition_simple
end
assert_equal(["dialog1", "vbox1", "hbuttonbox1", "ok_button",
"main-window"].sort,
builder.objects.collect {|object| object.builder_name}.sort)
end
def test_translation_domain
builder = Gtk::Builder.new
assert_nil(builder.translation_domain)
builder.translation_domain = "ruby-gnome2"
assert_equal("ruby-gnome2", builder.translation_domain)
end
def test_connect_signals
handler_names = []
builder = Gtk::Builder.new
builder.connect_signals do |name|
handler_names << name
Proc.new {}
end
assert_equal([].sort, handler_names.sort)
builder << ui_definition
ok_button = builder["ok_button"]
builder.connect_signals do |name|
handler_names << name
Proc.new {}
end
assert_equal(["ok_button_clicked"].sort, handler_names.sort)
end
def test_connect_signals_with_no_signal_ui_definition
handler_names = []
builder = Gtk::Builder.new
builder.connect_signals do |name|
handler_names << name
Proc.new {}
end
assert_equal([].sort, handler_names.sort)
builder << ui_definition_simple
builder.connect_signals do |name|
handler_names << name
Proc.new {}
end
assert_equal([].sort, handler_names.sort)
end
def test_get_type_from_name
builder = Gtk::Builder.new
assert_nil(builder.get_type("XXX"))
assert_equal(Gtk::Box, builder.get_type("GtkBox"))
end
private
def ui_definition
<<-EOX
<interface>
<object class="GtkDialog" id="dialog1">
<child internal-child="vbox">
<object class="GtkVBox" id="vbox1">
<property name="border-width">10</property>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="hbuttonbox1">
<property name="border-width">20</property>
<child>
<object class="GtkButton" id="ok_button">
<property name="label">gtk-ok</property>
<property name="use-stock">TRUE</property>
<signal name="clicked" handler="ok_button_clicked"/>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
EOX
end
def ui_definition_simple
<<-EOX
<interface>
<object class="GtkWindow" id="main-window">
</object>
</interface>
EOX
end
def ui_definition_with_signal
<<-EOX
<interface>
<object class="GtkWindow" id="main-window">
</object>
</interface>
EOX
end
def ui_definition_file
xml = Tempfile.new("Gtk::Builder")
xml.print(ui_definition)
xml.close
xml
end
end