wxruby3 0.9.0.pre.rc.2 → 0.9.0.pre.rc.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/INSTALL.md +30 -8
- data/README.md +3 -3
- data/ext/wxruby3/swig/wx.i +2 -0
- data/lib/wx/core/event_loop.rb +7 -0
- data/lib/wx/core/image.rb +33 -0
- data/lib/wx/core/listctrl.rb +17 -13
- data/lib/wx/core/log.rb +90 -0
- data/lib/wx/doc/bitmap.rb +11 -15
- data/lib/wx/doc/event_loop.rb +7 -0
- data/lib/wx/doc/extra/00_starting.md +6 -6
- data/lib/wx/doc/extra/02_lifecycles.md +9 -8
- data/lib/wx/doc/extra/09_exceptions.md +1 -1
- data/lib/wx/doc/extra/11_drawing_and_dc.md +4 -4
- data/lib/wx/doc/font.rb +1 -1
- data/lib/wx/doc/functions.rb +51 -23
- data/lib/wx/doc/gc_dc.rb +1 -1
- data/lib/wx/doc/image.rb +42 -12
- data/lib/wx/doc/list_ctrl.rb +32 -0
- data/lib/wx/doc/log.rb +28 -0
- data/lib/wx/doc/prt/printer_dc.rb +2 -2
- data/lib/wx/doc/scaled_dc.rb +1 -1
- data/lib/wx/doc/text_validator.rb +12 -0
- data/lib/wx/version.rb +1 -1
- data/rakelib/lib/core/mapping.rb +15 -10
- data/rakelib/lib/core/package.rb +3 -0
- data/rakelib/lib/core/spec.rb +21 -10
- data/rakelib/lib/core/spec_helper.rb +6 -0
- data/rakelib/lib/director/dialog.rb +25 -0
- data/rakelib/lib/director/event_loop.rb +26 -0
- data/rakelib/lib/director/functions.rb +44 -48
- data/rakelib/lib/director/image.rb +32 -0
- data/rakelib/lib/director/list_ctrl.rb +3 -2
- data/rakelib/lib/director/log.rb +64 -4
- data/rakelib/lib/director/text_entry.rb +25 -0
- data/rakelib/lib/director/text_validator.rb +8 -2
- data/rakelib/lib/director/variant.rb +17 -4
- data/rakelib/lib/extractor/function.rb +7 -7
- data/rakelib/lib/extractor/variable.rb +6 -6
- data/rakelib/lib/generate/doc/aui_manager.yaml +21 -0
- data/rakelib/lib/generate/doc/font.yaml +29 -0
- data/rakelib/lib/generate/doc/frame.yaml +23 -0
- data/rakelib/lib/generate/doc/fs_file.yaml +11 -0
- data/rakelib/lib/generate/doc/gdi_common.yaml +36 -0
- data/rakelib/lib/generate/doc/graphics_context.yaml +34 -0
- data/rakelib/lib/generate/doc/gui_event_loop.yaml +12 -0
- data/rakelib/lib/generate/doc/help_controller.yaml +24 -0
- data/rakelib/lib/generate/doc/icon.yaml +11 -0
- data/rakelib/lib/generate/doc/image.yaml +87 -0
- data/rakelib/lib/generate/doc/keyboard_state.yaml +19 -0
- data/rakelib/lib/generate/doc/list_ctrl.yaml +77 -0
- data/rakelib/lib/generate/doc/locale.yaml +12 -0
- data/rakelib/lib/generate/doc/log.yaml +86 -0
- data/rakelib/lib/generate/doc/mdi_frame.yaml +12 -0
- data/rakelib/lib/generate/doc/memory_dc.yaml +42 -0
- data/rakelib/lib/generate/doc/menu.yaml +17 -0
- data/rakelib/lib/generate/doc/menu_item.yaml +43 -0
- data/rakelib/lib/generate/doc/message_dialog.yaml +36 -0
- data/rakelib/lib/generate/doc/non_owned_window.yaml +14 -0
- data/rakelib/lib/generate/doc/notebook.yaml +18 -0
- data/rakelib/lib/generate/doc/pen.yaml +11 -0
- data/rakelib/lib/generate/doc/picker_base.yaml +19 -0
- data/rakelib/lib/generate/doc/platform_info.yaml +15 -0
- data/rakelib/lib/generate/doc/property_sheet_dialog.yaml +26 -0
- data/rakelib/lib/generate/doc/scroll_bar.yaml +11 -0
- data/rakelib/lib/generate/doc/scrolled_canvas.yaml +37 -0
- data/rakelib/lib/generate/doc/scrolled_control.yaml +37 -0
- data/rakelib/lib/generate/doc/scrolled_window.yaml +37 -0
- data/rakelib/lib/generate/doc/sizer.yaml +69 -0
- data/rakelib/lib/generate/doc/splash_screen.yaml +18 -0
- data/rakelib/lib/generate/doc/static_box.yaml +52 -0
- data/rakelib/lib/generate/doc/static_box_sizer.yaml +22 -0
- data/rakelib/lib/generate/doc/svg_file_dc.yaml +11 -0
- data/rakelib/lib/generate/doc/text_ctrl.yaml +19 -0
- data/rakelib/lib/generate/doc/text_entry.yaml +42 -0
- data/rakelib/lib/generate/doc/text_entry_dialog.yaml +17 -0
- data/rakelib/lib/generate/doc/timer_event.yaml +28 -0
- data/rakelib/lib/generate/doc/tool_bar.yaml +35 -0
- data/rakelib/lib/generate/doc/top_level_window.yaml +23 -0
- data/rakelib/lib/generate/doc/validator.yaml +12 -0
- data/rakelib/lib/generate/doc/variant.yaml +29 -0
- data/rakelib/lib/generate/doc/window.yaml +249 -0
- data/rakelib/lib/generate/doc/wizard_page_simple.yaml +14 -0
- data/rakelib/lib/generate/doc/xml_node.yaml +7 -0
- data/rakelib/lib/generate/doc/xml_resource.yaml +27 -0
- data/rakelib/lib/generate/doc.rb +35 -1
- data/rakelib/lib/specs/interfaces.rb +1 -0
- data/rakelib/lib/swig_runner.rb +37 -0
- data/tests/test_art.rb +9 -0
- data/tests/test_box_sizer.rb +161 -0
- data/tests/test_grid_sizer.rb +148 -0
- data/tests/test_list_ctrl.rb +53 -0
- data/tests/test_log.rb +163 -0
- data/tests/test_std_controls.rb +58 -0
- data/tests/test_timer.rb +95 -0
- metadata +59 -2
@@ -0,0 +1,161 @@
|
|
1
|
+
|
2
|
+
require_relative './lib/wxframe_runner'
|
3
|
+
|
4
|
+
class BoxSizerTests < WxRuby::Test::GUITests
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@win = Wx::Window.new(test_frame, Wx::ID_ANY)
|
9
|
+
@sizer = Wx::HBoxSizer.new
|
10
|
+
@win.set_client_size(127, 35)
|
11
|
+
@win.sizer = @sizer
|
12
|
+
end
|
13
|
+
|
14
|
+
def cleanup
|
15
|
+
test_frame.destroy_children
|
16
|
+
@win = nil
|
17
|
+
@sizer = nil
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :win, :sizer
|
22
|
+
|
23
|
+
def test_size
|
24
|
+
sizeTotal = win.get_client_size
|
25
|
+
sizeChild = sizeTotal / 2
|
26
|
+
|
27
|
+
child = Wx::Window.new(win, Wx::ID_ANY, Wx::DEFAULT_POSITION, sizeChild)
|
28
|
+
sizer.add(child)
|
29
|
+
win.layout
|
30
|
+
assert(child.size == sizeChild)
|
31
|
+
|
32
|
+
sizer.clear
|
33
|
+
sizer.add(child, Wx::SizerFlags.new(1))
|
34
|
+
win.layout
|
35
|
+
assert(child.size == [sizeTotal.x, sizeChild.y])
|
36
|
+
|
37
|
+
sizer.clear
|
38
|
+
sizer.add(child, Wx::SizerFlags.new(1).expand)
|
39
|
+
win.layout
|
40
|
+
assert(child.size == sizeTotal)
|
41
|
+
|
42
|
+
sizer.clear
|
43
|
+
sizer.add(child, Wx::SizerFlags.new)
|
44
|
+
sizer.set_item_min_size(child, sizeTotal*2)
|
45
|
+
win.layout
|
46
|
+
assert(child.size == sizeTotal)
|
47
|
+
|
48
|
+
sizer.clear
|
49
|
+
sizer.add(child, Wx::SizerFlags.new.expand)
|
50
|
+
sizer.set_item_min_size(child, sizeTotal*2)
|
51
|
+
win.layout
|
52
|
+
assert(child.size == sizeTotal)
|
53
|
+
end
|
54
|
+
|
55
|
+
class << self
|
56
|
+
|
57
|
+
def _ltd(*args)
|
58
|
+
@ltd_klass ||= Struct.new(:prop, :minsize, :x, :sizes, :dont_permute) do
|
59
|
+
def add_to_sizer(sizer, win, n)
|
60
|
+
sizer.add(win, Wx::SizerFlags.new(prop[n]))
|
61
|
+
sizer.set_item_min_size(win, Wx::Size.new(minsize[n], -1))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
@ltd_klass.new(*args)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
LayoutTestData = [
|
70
|
+
# some really simple cases (no need to permute those, they're
|
71
|
+
# symmetrical anyhow)
|
72
|
+
_ltd( [ 1, 1, 1, ], [ 50, 50, 50, ], 150, [ 50, 50, 50, ], true ),
|
73
|
+
_ltd( [ 2, 2, 2, ], [ 50, 50, 50, ], 600, [ 200, 200, 200, ], true ),
|
74
|
+
|
75
|
+
# items with different proportions and min sizes when there is enough
|
76
|
+
# space to lay them out
|
77
|
+
_ltd( [ 1, 2, 3, ], [ 0, 0, 0, ], 600, [ 100, 200, 300, ] ),
|
78
|
+
_ltd( [ 1, 2, 3, ], [ 100, 100, 100, ], 600, [ 100, 200, 300, ] ),
|
79
|
+
_ltd( [ 1, 2, 3, ], [ 100, 50, 50, ], 600, [ 100, 200, 300, ] ),
|
80
|
+
_ltd( [ 0, 1, 1, ], [ 200, 100, 100, ], 600, [ 200, 200, 200, ] ),
|
81
|
+
_ltd( [ 0, 1, 2, ], [ 300, 100, 100, ], 600, [ 300, 100, 200, ] ),
|
82
|
+
_ltd( [ 0, 1, 1, ], [ 100, 50, 50, ], 300, [ 100, 100, 100, ] ),
|
83
|
+
_ltd( [ 0, 1, 2, ], [ 100, 50, 50, ], 400, [ 100, 100, 200, ] ),
|
84
|
+
|
85
|
+
# cases when there is not enough space to lay out the items correctly
|
86
|
+
# while still respecting their min sizes
|
87
|
+
_ltd( [ 0, 1, 1, ], [ 100, 150, 50, ], 300, [ 100, 150, 50, ] ),
|
88
|
+
_ltd( [ 1, 2, 3, ], [ 100, 100, 100, ], 300, [ 100, 100, 100, ] ),
|
89
|
+
_ltd( [ 1, 2, 3, ], [ 100, 50, 50, ], 300, [ 100, 80, 120, ] ),
|
90
|
+
_ltd( [ 1, 2, 3, ], [ 100, 10, 10, ], 150, [ 100, 20, 30, ] ),
|
91
|
+
|
92
|
+
# cases when there is not enough space even for the min sizes (don't
|
93
|
+
# permute in these cases as the layout does depend on the item order
|
94
|
+
# because the first ones have priority)
|
95
|
+
_ltd( [ 1, 2, 3, ], [ 100, 50, 50, ], 150, [ 100, 50, 0, ], true ),
|
96
|
+
_ltd( [ 1, 2, 3, ], [ 100, 100, 100, ], 200, [ 100, 100, 0, ], true ),
|
97
|
+
_ltd( [ 1, 2, 3, ], [ 100, 100, 100, ], 150, [ 100, 50, 0, ], true ),
|
98
|
+
_ltd( [ 1, 2, 3, ], [ 100, 100, 100, ], 50, [ 50, 0, 0, ], true ),
|
99
|
+
_ltd( [ 1, 2, 3, ], [ 100, 100, 100, ], 0, [ 0, 0, 0, ], true ),
|
100
|
+
]
|
101
|
+
|
102
|
+
def test_size_3
|
103
|
+
child = [Wx::Window.new(win, Wx::ID_ANY),
|
104
|
+
Wx::Window.new(win, Wx::ID_ANY),
|
105
|
+
Wx::Window.new(win, Wx::ID_ANY)]
|
106
|
+
|
107
|
+
LayoutTestData.each_with_index do |ltd, i|
|
108
|
+
# the results shouldn't depend on the order of items except in the
|
109
|
+
# case when there is not enough space for even the fixed width items
|
110
|
+
# (in which case the first ones might get enough of it but not the
|
111
|
+
# last ones) so test a couple of permutations of test data unless
|
112
|
+
# specifically disabled for this test case
|
113
|
+
3.times do |p|
|
114
|
+
case p
|
115
|
+
when 0
|
116
|
+
# nothing, use original data
|
117
|
+
when 1
|
118
|
+
# exchange first and last elements
|
119
|
+
ltd.prop[0], ltd.prop[2] = ltd.prop[2], ltd.prop[0]
|
120
|
+
ltd.minsize[0], ltd.minsize[2] = ltd.minsize[2], ltd.minsize[0]
|
121
|
+
ltd.sizes[0], ltd.sizes[2] = ltd.sizes[2], ltd.sizes[0]
|
122
|
+
when 2
|
123
|
+
# exchange the original third and second elements
|
124
|
+
ltd.prop[0], ltd.prop[1] = ltd.prop[1], ltd.prop[0]
|
125
|
+
ltd.minsize[0], ltd.minsize[1] = ltd.minsize[1], ltd.minsize[0]
|
126
|
+
ltd.sizes[0], ltd.sizes[1] = ltd.sizes[1], ltd.sizes[0]
|
127
|
+
end
|
128
|
+
|
129
|
+
sizer.clear
|
130
|
+
|
131
|
+
child.each_with_index { |c, j| ltd.add_to_sizer(sizer, c, j) }
|
132
|
+
|
133
|
+
win.set_client_size(ltd.x, -1)
|
134
|
+
win.layout
|
135
|
+
|
136
|
+
child.each_with_index do |c, j|
|
137
|
+
assert_equal(ltd.sizes[j], c.size.x,
|
138
|
+
"test #{i}, permutation #{p}: wrong size for child #{j} for total size #{ltd.x}")
|
139
|
+
end
|
140
|
+
|
141
|
+
# don't try other permutations if explicitly disabled
|
142
|
+
break if ltd.dont_permute
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_min_size
|
148
|
+
child = Wx::Window.new(win, Wx::ID_ANY)
|
149
|
+
child.set_initial_size([10, -1])
|
150
|
+
sizer.add(child)
|
151
|
+
|
152
|
+
# Setting minimal size explicitly must make get_min_size() return at least
|
153
|
+
# this size even if it needs a much smaller one.
|
154
|
+
sizer.set_min_size(100, 0)
|
155
|
+
assert(sizer.get_min_size.x == 100)
|
156
|
+
|
157
|
+
sizer.layout
|
158
|
+
assert(sizer.min_size.x == 100)
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
|
2
|
+
require_relative './lib/wxframe_runner'
|
3
|
+
|
4
|
+
class GridSizerTests < WxRuby::Test::GUITests
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@win = Wx::Window.new(test_frame, Wx::ID_ANY)
|
9
|
+
@win.set_client_size(127, 35)
|
10
|
+
@sizer = Wx::GridSizer.new(2)
|
11
|
+
@win.set_sizer(@sizer)
|
12
|
+
end
|
13
|
+
|
14
|
+
def cleanup
|
15
|
+
test_frame.destroy_children
|
16
|
+
@win = nil
|
17
|
+
@sizer = nil
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :win, :sizer
|
22
|
+
|
23
|
+
def set_children(children, flags)
|
24
|
+
@sizer.clear
|
25
|
+
children.each { |c| @sizer.add(c, flags) }
|
26
|
+
@win.layout
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_layout
|
30
|
+
sizeTotal = win.get_client_size
|
31
|
+
sizeChild = Wx::Size.new(sizeTotal.x / 2, sizeTotal.y / 2)
|
32
|
+
|
33
|
+
children = [Wx::Window.new(win, Wx::ID_ANY),
|
34
|
+
Wx::Window.new(win, Wx::ID_ANY),
|
35
|
+
Wx::Window.new(win, Wx::ID_ANY)]
|
36
|
+
|
37
|
+
set_children(children, Wx::SizerFlags.new.expand)
|
38
|
+
assert(children[0].rect == Wx::Rect.new(Wx::Point.new(0, 0), sizeChild))
|
39
|
+
assert(children[1].rect == Wx::Rect.new(Wx::Point.new(sizeChild.x, 0), sizeChild))
|
40
|
+
assert(children[2].rect == Wx::Rect.new(Wx::Point.new(0, sizeChild.y), sizeChild))
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
class FlexGridSizerTests < WxRuby::Test::GUITests
|
46
|
+
|
47
|
+
def setup
|
48
|
+
super
|
49
|
+
@win = Wx::Window.new(test_frame, Wx::ID_ANY)
|
50
|
+
@win.set_client_size(127, 35)
|
51
|
+
@sizer = Wx::FlexGridSizer.new(2)
|
52
|
+
@win.set_sizer(@sizer)
|
53
|
+
end
|
54
|
+
|
55
|
+
def cleanup
|
56
|
+
test_frame.destroy_children
|
57
|
+
@win = nil
|
58
|
+
@sizer = nil
|
59
|
+
super
|
60
|
+
end
|
61
|
+
|
62
|
+
attr_reader :win, :sizer
|
63
|
+
|
64
|
+
def set_children(children, flags)
|
65
|
+
@sizer.clear
|
66
|
+
children.each { |c| @sizer.add(c, flags) }
|
67
|
+
@win.layout
|
68
|
+
end
|
69
|
+
|
70
|
+
def do_test_layout
|
71
|
+
sizeTotal = win.get_client_size
|
72
|
+
sizeChild = Wx::Size.new(sizeTotal.x / 4, sizeTotal.y / 4)
|
73
|
+
sizeRest = Wx::Size.new(sizeTotal.x - sizeTotal.x / 4,
|
74
|
+
sizeTotal.y - sizeTotal.y / 4)
|
75
|
+
|
76
|
+
children = [Wx::Window.new(win, Wx::ID_ANY, Wx::DEFAULT_POSITION, sizeChild),
|
77
|
+
Wx::Window.new(win, Wx::ID_ANY, Wx::DEFAULT_POSITION, sizeChild),
|
78
|
+
Wx::Window.new(win, Wx::ID_ANY, Wx::DEFAULT_POSITION, sizeChild),
|
79
|
+
Wx::Window.new(win, Wx::ID_ANY, Wx::DEFAULT_POSITION, sizeChild)]
|
80
|
+
|
81
|
+
sizer.add_growable_row(1)
|
82
|
+
sizer.add_growable_col(1)
|
83
|
+
|
84
|
+
yield(children, sizeTotal, sizeChild, sizeRest)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_layout
|
88
|
+
do_test_layout do |children, sizeTotal, sizeChild, sizeRest|
|
89
|
+
set_children(children, Wx::SizerFlags.new)
|
90
|
+
assert_equal( sizeChild, children[0].get_size)
|
91
|
+
assert_equal( sizeChild, children[1].get_size )
|
92
|
+
assert_equal( sizeChild, children[2].get_size )
|
93
|
+
assert_equal( sizeChild, children[3].get_size )
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_layout_expand
|
98
|
+
do_test_layout do |children, sizeTotal, sizeChild, sizeRest|
|
99
|
+
set_children(children, Wx::SizerFlags.new.expand)
|
100
|
+
assert_equal(sizeChild, children[0].get_size)
|
101
|
+
assert_equal(Wx::Size.new(sizeRest.x, sizeChild.y), children[1].get_size)
|
102
|
+
assert_equal(Wx::Size.new(sizeChild.x, sizeRest.y), children[2].get_size)
|
103
|
+
assert_equal(sizeRest, children[3].get_size )
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_layout_expand_centre_vertical
|
108
|
+
do_test_layout do |children, sizeTotal, sizeChild, sizeRest|
|
109
|
+
set_children(children, Wx::SizerFlags.new.expand.centre_vertical)
|
110
|
+
assert_equal(sizeChild, children[0].get_size)
|
111
|
+
assert_equal(Wx::Size.new(sizeRest.x, sizeChild.y), children[1].get_size)
|
112
|
+
assert_equal(sizeChild, children[2].get_size )
|
113
|
+
assert_equal(Wx::Size.new(sizeRest.x, sizeChild.y), children[3].get_size)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_layout_expand_centre_horizontal
|
118
|
+
do_test_layout do |children, sizeTotal, sizeChild, sizeRest|
|
119
|
+
set_children(children, Wx::SizerFlags.new.expand.centre_horizontal)
|
120
|
+
assert_equal(sizeChild, children[0].get_size)
|
121
|
+
assert_equal(sizeChild, children[1].get_size )
|
122
|
+
assert_equal(Wx::Size.new(sizeChild.x, sizeRest.y), children[2].get_size)
|
123
|
+
assert_equal(Wx::Size.new(sizeChild.x, sizeRest.y), children[3].get_size)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_layout_right
|
128
|
+
do_test_layout do |children, sizeTotal, sizeChild, sizeRest|
|
129
|
+
set_children(children, Wx::SizerFlags.new.right)
|
130
|
+
assert_equal( Wx::Point.new(0, 0), children[0].get_position)
|
131
|
+
assert_equal( Wx::Point.new(sizeRest.x, 0), children[1].get_position)
|
132
|
+
assert_equal( Wx::Point.new(0, sizeChild.y), children[2].get_position)
|
133
|
+
assert_equal( Wx::Point.new(sizeRest.x, sizeChild.y), children[3].get_position)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_layout_right_centre_vertical
|
138
|
+
do_test_layout do |children, sizeTotal, sizeChild, sizeRest|
|
139
|
+
set_children(children, Wx::SizerFlags.new.right.centre_vertical)
|
140
|
+
yMid = sizeChild.y + (sizeRest.y - sizeChild.y) / 2
|
141
|
+
assert_equal( Wx::Point.new(0, 0), children[0].get_position)
|
142
|
+
assert_equal( Wx::Point.new(sizeRest.x, 0), children[1].get_position)
|
143
|
+
assert_equal( Wx::Point.new(0, yMid), children[2].get_position)
|
144
|
+
assert_equal( Wx::Point.new(sizeRest.x, yMid), children[3].get_position)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
require_relative './lib/wxframe_runner'
|
3
|
+
|
4
|
+
class ButtonTests < WxRuby::Test::GUITests
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@list = Wx::ListCtrl.new(test_frame)
|
9
|
+
@list.set_window_style(Wx::LC_REPORT | Wx::LC_EDIT_LABELS)
|
10
|
+
@list.set_size([400, 200])
|
11
|
+
end
|
12
|
+
|
13
|
+
def cleanup
|
14
|
+
@list.destroy
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :list
|
19
|
+
|
20
|
+
def test_sort
|
21
|
+
list.insert_column(0, "Column 0")
|
22
|
+
|
23
|
+
list.insert_item(0, "Item 0")
|
24
|
+
list.set_item_data(0, 0)
|
25
|
+
list.insert_item(1, "Item 1")
|
26
|
+
list.set_item_data(1, 1)
|
27
|
+
|
28
|
+
list.sort_items { |i1, i2, _| i2 <=> i1 } # inverted compare
|
29
|
+
|
30
|
+
assert_equal("Item 1", list.get_item_text(0))
|
31
|
+
assert_equal("Item 0", list.get_item_text(1))
|
32
|
+
end
|
33
|
+
|
34
|
+
if Wx.has_feature?(:HAS_LISTCTRL_COLUMN_ORDER)
|
35
|
+
|
36
|
+
def test_columns_order
|
37
|
+
3.times { |i| list.insert_column(i, "Column #{i}") }
|
38
|
+
|
39
|
+
order = [2, 0, 1]
|
40
|
+
list.set_columns_order(order)
|
41
|
+
|
42
|
+
# now list.get_columns_order() will return order
|
43
|
+
assert_equal(order, list.get_columns_order)
|
44
|
+
# and list.get_column_index_from_order(n) will return order[n]
|
45
|
+
assert_equal(order[1], list.get_column_index_from_order(1))
|
46
|
+
# and list.get_column_order() will return 1, 2 and 0 for the column 0,
|
47
|
+
# 1 and 2 respectively
|
48
|
+
assert_equal(1, list.get_column_order(0))
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/tests/test_log.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
|
2
|
+
require_relative './lib/wxapp_runner'
|
3
|
+
|
4
|
+
class LogTests < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class TestLogBase < Wx::Log
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@logs = ::Array.new(Wx::LOG_Trace + 1)
|
11
|
+
@logsInfo = ::Array.new(Wx::LOG_Trace + 1)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_log(level)
|
15
|
+
@logs[level].to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_info(level)
|
19
|
+
@logsInfo[level]
|
20
|
+
end
|
21
|
+
|
22
|
+
def clear
|
23
|
+
@logs = ::Array.new(Wx::LOG_Trace + 1)
|
24
|
+
@logsInfo = ::Array.new(Wx::LOG_Trace + 1)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class TestLog < TestLogBase
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def do_log_record(level, msg, info)
|
34
|
+
@logs[level] = msg
|
35
|
+
# do not keep log info objects because these (and their state) are purely transient data
|
36
|
+
# that can only be reliably accessed (or passed on) within this call scope
|
37
|
+
@logsInfo[level] = { filename: info.filename, line: info.line, func: info.func, component: info.component }
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def setup
|
43
|
+
super
|
44
|
+
@logOld = Wx::Log.set_active_target(@log = TestLog.new)
|
45
|
+
@logWasEnabled = Wx::Log.enable_logging
|
46
|
+
end
|
47
|
+
|
48
|
+
def cleanup
|
49
|
+
Wx::Log.set_active_target(@logOld)
|
50
|
+
Wx::Log.enable_logging(@logWasEnabled)
|
51
|
+
super
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_functions
|
55
|
+
Wx.log_message("Message")
|
56
|
+
assert_equal("Message", @log.get_log(Wx::LOG_Message))
|
57
|
+
|
58
|
+
Wx.log_error("Error %d", 17)
|
59
|
+
assert_equal("Error 17", @log.get_log(Wx::LOG_Error))
|
60
|
+
|
61
|
+
Wx.log_debug("Debug")
|
62
|
+
if Wx::WXWIDGETS_DEBUG_LEVEL > 0
|
63
|
+
assert_equal( "Debug", @log.get_log(Wx::LOG_Debug))
|
64
|
+
else
|
65
|
+
assert_equal( "", @log.get_log(Wx::LOG_Debug))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_null
|
70
|
+
Wx::LogNull.no_log do
|
71
|
+
Wx.log_warning("%s warning", "Not important")
|
72
|
+
|
73
|
+
assert_equal("", @log.get_log(Wx::LOG_Warning))
|
74
|
+
end
|
75
|
+
|
76
|
+
Wx.log_warning("%s warning", "Important")
|
77
|
+
assert_equal("Important warning", @log.get_log(Wx::LOG_Warning))
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_component
|
81
|
+
Wx.log_message('Message')
|
82
|
+
assert_equal('wxapp',
|
83
|
+
@log.get_info(Wx::LOG_Message)[:component])
|
84
|
+
|
85
|
+
# completely disable logging for this component
|
86
|
+
Wx::Log.set_component_level('test/ignore', Wx::LOG_FatalError)
|
87
|
+
|
88
|
+
# but enable it for one of its subcomponents
|
89
|
+
Wx::Log.set_component_level('test/ignore/not', Wx::LOG_Max)
|
90
|
+
|
91
|
+
Wx::Log.for_component('test/ignore') do
|
92
|
+
# this shouldn't be output as this component is ignored
|
93
|
+
Wx::log_error('Error')
|
94
|
+
assert_equal('', @log.get_log(Wx::LOG_Error))
|
95
|
+
|
96
|
+
# and so are its subcomponents
|
97
|
+
Wx.log_error('Error', component: 'test/ignore/sub/subsub') # explicit component: overrules scoped setting
|
98
|
+
assert_equal('', @log.get_log(Wx::LOG_Error))
|
99
|
+
|
100
|
+
Wx.log_error('Error', component: 'test/ignore/not')
|
101
|
+
assert_equal('Error', @log.get_log(Wx::LOG_Error))
|
102
|
+
|
103
|
+
# restore the original component value
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_repetition_counting
|
108
|
+
Wx::Log.set_repetition_counting(true)
|
109
|
+
|
110
|
+
Wx.log_message('Message')
|
111
|
+
assert_equal('Message', @log.get_log(Wx::LOG_Message))
|
112
|
+
|
113
|
+
@log.clear
|
114
|
+
Wx.log_message('Message')
|
115
|
+
assert_equal('', @log.get_log(Wx::LOG_Message))
|
116
|
+
Wx.log_message('Message')
|
117
|
+
assert_equal('', @log.get_log(Wx::LOG_Message))
|
118
|
+
|
119
|
+
Wx.log_info('Another message')
|
120
|
+
if Wx.has_feature?(:USE_INTL)
|
121
|
+
# don't what language may come out so just test if not empty anymore
|
122
|
+
assert_not_empty(@log.get_log(Wx::LOG_Message))
|
123
|
+
else
|
124
|
+
assert_match(/The previous message.*repeated/, @log.get_log(Wx::LOG_Message))
|
125
|
+
end
|
126
|
+
assert_equal('Another message', @log.get_log(Wx::LOG_Info))
|
127
|
+
|
128
|
+
Wx::Log.set_repetition_counting(false)
|
129
|
+
end
|
130
|
+
|
131
|
+
class MyBufferInterposer < Wx::LogInterposer
|
132
|
+
|
133
|
+
def initialize
|
134
|
+
super
|
135
|
+
@buffer = []
|
136
|
+
end
|
137
|
+
|
138
|
+
attr_reader :buffer
|
139
|
+
|
140
|
+
def do_log_text(msg)
|
141
|
+
@buffer << msg
|
142
|
+
end
|
143
|
+
protected :do_log_text
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_log_interposer
|
148
|
+
buffer_log = MyBufferInterposer.new
|
149
|
+
assert_empty(buffer_log.buffer)
|
150
|
+
|
151
|
+
Wx.log_message('Message')
|
152
|
+
assert_equal("Message", @log.get_log(Wx::LOG_Message))
|
153
|
+
assert_equal(1, buffer_log.buffer.size)
|
154
|
+
assert_match(/Message/, buffer_log.buffer.first)
|
155
|
+
|
156
|
+
Wx.log_warning('Message')
|
157
|
+
assert_equal("Message", @log.get_log(Wx::LOG_Warning))
|
158
|
+
assert_equal(2, buffer_log.buffer.size)
|
159
|
+
assert_match(/Message/, buffer_log.buffer.last)
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
data/tests/test_std_controls.rb
CHANGED
@@ -371,3 +371,61 @@ class ChoiceTests < WxRuby::Test::GUITests
|
|
371
371
|
end
|
372
372
|
|
373
373
|
end
|
374
|
+
|
375
|
+
class GaugeTests < WxRuby::Test::GUITests
|
376
|
+
|
377
|
+
def setup
|
378
|
+
super
|
379
|
+
@gauge = Wx::Gauge.new(test_frame, range: 100)
|
380
|
+
end
|
381
|
+
|
382
|
+
def cleanup
|
383
|
+
test_frame.destroy_children
|
384
|
+
super
|
385
|
+
end
|
386
|
+
|
387
|
+
attr_reader :gauge
|
388
|
+
|
389
|
+
def test_direction
|
390
|
+
#We should default to a horizontal gauge
|
391
|
+
assert(!gauge.is_vertical)
|
392
|
+
|
393
|
+
gauge.destroy
|
394
|
+
@gauge = Wx::Gauge.new(test_frame, range: 100, style: Wx::GA_VERTICAL)
|
395
|
+
|
396
|
+
assert(gauge.vertical?)
|
397
|
+
|
398
|
+
gauge.destroy
|
399
|
+
@gauge = Wx::Gauge.new(test_frame, range: 100, style: Wx::GA_HORIZONTAL)
|
400
|
+
|
401
|
+
assert(!gauge.vertical?)
|
402
|
+
end
|
403
|
+
|
404
|
+
def test_range
|
405
|
+
assert_equal(100, gauge.get_range)
|
406
|
+
|
407
|
+
gauge.set_range(50)
|
408
|
+
|
409
|
+
assert_equal(50, gauge.get_range)
|
410
|
+
|
411
|
+
gauge.set_range(0)
|
412
|
+
|
413
|
+
assert_equal(0, gauge.range)
|
414
|
+
end
|
415
|
+
|
416
|
+
def test_value
|
417
|
+
assert_equal(0, gauge.get_value)
|
418
|
+
|
419
|
+
gauge.set_value(50)
|
420
|
+
|
421
|
+
assert_equal(50, gauge.value)
|
422
|
+
|
423
|
+
gauge.value = 0
|
424
|
+
|
425
|
+
assert_equal(0, gauge.get_value)
|
426
|
+
|
427
|
+
gauge.set_value(100)
|
428
|
+
|
429
|
+
assert_equal(100, gauge.value)
|
430
|
+
end
|
431
|
+
end
|
data/tests/test_timer.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
|
2
|
+
require_relative './lib/wxapp_runner'
|
3
|
+
|
4
|
+
class TimerTests < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class TimerCounterHandler < Wx::EvtHandler
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@count = 0
|
11
|
+
evt_timer Wx::ID_ANY, :on_timer
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :count
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def on_timer(_evt)
|
19
|
+
@count += 1
|
20
|
+
tick
|
21
|
+
end
|
22
|
+
|
23
|
+
def tick
|
24
|
+
# noop
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_one_shot
|
30
|
+
|
31
|
+
handler = Class.new(TimerCounterHandler) do
|
32
|
+
def initialize(loop)
|
33
|
+
super()
|
34
|
+
@loop = loop
|
35
|
+
end
|
36
|
+
|
37
|
+
def run
|
38
|
+
@timer = Wx::Timer.new(self)
|
39
|
+
@timer.start(200, true)
|
40
|
+
@loop.run
|
41
|
+
end
|
42
|
+
|
43
|
+
def tick
|
44
|
+
@timer.stop
|
45
|
+
@loop.exit
|
46
|
+
end
|
47
|
+
end.new(Wx::EventLoop.new)
|
48
|
+
|
49
|
+
handler.run
|
50
|
+
|
51
|
+
assert_equal(1, handler.count)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_multiple
|
55
|
+
|
56
|
+
|
57
|
+
handler = Class.new(TimerCounterHandler) do
|
58
|
+
def initialize(loop)
|
59
|
+
super()
|
60
|
+
@loop = loop
|
61
|
+
end
|
62
|
+
|
63
|
+
def run
|
64
|
+
@timer = Wx::Timer.new(self)
|
65
|
+
@timer.start(100)
|
66
|
+
# run for 2 seconds
|
67
|
+
@tm_end = Time.now + 2
|
68
|
+
@loop.run
|
69
|
+
end
|
70
|
+
|
71
|
+
def tick
|
72
|
+
# exit after 2 seconds
|
73
|
+
unless Time.now < @tm_end
|
74
|
+
@timer.stop
|
75
|
+
@loop.exit
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end.new(Wx::EventLoop.new)
|
79
|
+
|
80
|
+
|
81
|
+
handler.run
|
82
|
+
|
83
|
+
# we can't count on getting exactly 20 ticks but we shouldn't get more
|
84
|
+
# than this
|
85
|
+
num_ticks = handler.count
|
86
|
+
assert( num_ticks <= 20 )
|
87
|
+
|
88
|
+
# and we should get a decent number of them but if the system is very
|
89
|
+
# loaded (as happens with build bot slaves running a couple of builds in
|
90
|
+
# parallel actually) it may be much less than 20 so just check that we get
|
91
|
+
# more than one
|
92
|
+
assert( num_ticks > 1 )
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|