forked from ruby-gnome/ruby-gnome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_gtk_list_store.rb
105 lines (92 loc) · 2.68 KB
/
test_gtk_list_store.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
# Copyright (C) 2013-2014 Ruby-GNOME2 Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
class TestGtkListStore < Test::Unit::TestCase
include GtkTestUtils
ID = 0
NAME = 1
COLUMNS = {
ID => Integer,
NAME => String,
}
def setup
columns = COLUMNS.keys.sort.collect do |key|
COLUMNS[key]
end
@store = Gtk::ListStore.new(*columns)
end
def test_set_values
iter = @store.append
assert_nothing_raised do
@store.set_values(iter, [0, '1'])
end
assert_equal([0, '1'], [iter[0], iter[1]])
iter = @store.append
assert_nothing_raised do
@store.set_values(iter, [2, '3'])
end
assert_equal([2, '3'], [iter[0], iter[1]])
assert_nothing_raised do
@store.set_values(iter, [])
end
assert_equal([2, '3'], [iter[0], iter[1]])
end
def test_set_values_with_hash
iter = @store.append
assert_nothing_raised do
@store.set_values(iter, {ID => 0, NAME => 'me'})
end
assert_equal([0, 'me'], [iter[ID], iter[NAME]])
iter = @store.append
assert_nothing_raised do
@store.set_values(iter, {NAME => 'you', ID => 2})
end
assert_equal([2, 'you'], [iter[ID], iter[NAME]])
assert_nothing_raised do
@store.set_values(iter, {NAME => "she"})
end
assert_equal([2, 'she'], [iter[ID], iter[NAME]])
assert_nothing_raised do
@store.set_values(iter, {})
end
assert_equal([2, 'she'], [iter[ID], iter[NAME]])
end
def test_iter_gc
GC.start
n_iterators = count_objects(Gtk::TreeIter)
50.times do |i|
iter = @store.append
iter[ID] = i
iter[NAME] = i.to_s
end
100.times do
@store.iter_first
end
iter = @store.iter_first
while @store.remove(iter); end
iter = nil
assert_equal(0, @store.to_enum(:each).to_a.size)
GC.start
assert_equal(n_iterators, count_objects(Gtk::TreeIter))
end
private
def count_objects(klass)
n_objects = ObjectSpace.each_object(Gtk::TreeIter) do
# do nothing
end
n_objects
end
end