Skip to content

Commit

Permalink
Merge pull request #172 from mcorino/fix-tests
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
mcorino committed Sep 6, 2023
2 parents 7ff77d0 + ad37f3e commit 157d88b
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 155 deletions.
2 changes: 1 addition & 1 deletion rakelib/lib/config/macosx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def init_platform
@ld.sub!(/-o\s*\Z/, '')

@extra_cflags.concat %w[-Wno-unused-function -Wno-conversion-null -Wno-sometimes-uninitialized
-Wno-overloaded-virtual -Wno-deprecated-copy -Wno-unused-but-set-variable]
-Wno-overloaded-virtual -Wno-deprecated-copy]
@extra_cflags << ' -Wno-deprecated-declarations' unless @no_deprecated

# create a .dylib binary
Expand Down
2 changes: 1 addition & 1 deletion rakelib/lib/director/mouse_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MouseState < Director
def setup
super
spec.ignore 'wxMouseState::GetPosition(int*,int*)'
spec.do_not_generate(:variables, :enums, :defines, :functions)
spec.do_not_generate(:variables, :defines, :functions)
end
end # class MouseState

Expand Down
80 changes: 77 additions & 3 deletions tests/lib/wxframe_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ def on_assert_failure(file, line, func, condition, message)

class GUITests < ::Test::Unit::TestCase

def test_frame
setup
def base_setup
10.times { Wx.get_app.yield }
end

cleanup
def base_cleanup
10.times { Wx.get_app.yield }
end

def frame_win
Wx.get_app.frame
end

Expand All @@ -83,14 +93,14 @@ def inc
@count +=1
end

def wait_event(msec)
def wait_event(msec, reset=true)
start = Time.now
msec /= 1000.0
while (Time.now - start) < msec
Wx.get_app.yield
if @count > 0
raise StandardError.new("Too many events. Expected a single one.") unless @count == 1
@count = 0
@count = 0 if reset
return true
end
sleep(50.0/1000.0)
Expand All @@ -99,6 +109,65 @@ def wait_event(msec)
end
end

class UISimulator < Wx::UIActionSimulator

def mouse_move(*args)
super
Wx::get_app.yield
end

def mouse_down(button = Wx::MouseButton::MOUSE_BTN_LEFT)
super
Wx::get_app.yield
end

def mouse_up(button = Wx::MouseButton::MOUSE_BTN_LEFT)
super
Wx::get_app.yield
end

def mouse_click(button = Wx::MouseButton::MOUSE_BTN_LEFT)
super
Wx::get_app.yield
end

def mouse_dbl_click(button = Wx::MouseButton::MOUSE_BTN_LEFT)
super
Wx::get_app.yield
end

def mouse_drag_drop(x1, y1, x2, y2, button = Wx::MouseButton::MOUSE_BTN_LEFT)
super
Wx::get_app.yield
end

def key_down(keycode, modifiers = Wx::KeyModifier::MOD_NONE)
super
Wx::get_app.yield
end

def key_up(keycode, modifiers = Wx::KeyModifier::MOD_NONE)
super
Wx::get_app.yield
end

def char(keycode, modifiers = Wx::KeyModifier::MOD_NONE)
super
Wx::get_app.yield
end

def select(text)
super
Wx::get_app.yield
end

def text(text)
super
Wx::get_app.yield
end

end

def self.has_ui_simulator?
Wx.has_feature?(:USE_UIACTIONSIMULATOR) && (Wx::PLATFORM != 'WXOSX' || Wx::WXWIDGETS_VERSION >= '3.3')
end
Expand All @@ -107,6 +176,11 @@ def has_ui_simulator?
GUITests.has_ui_simulator?
end

def get_ui_simulator
raise 'Wx::UIActionSimulator is NOT supported on this platform!' unless has_ui_simulator?
@ui_sim ||= UISimulator.new
end

def count_events(win, evt, id1=Wx::ID_ANY, id2=nil)
return 0 unless block_given?
evt_count = EventCounter.new
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setup

def test_aui_frame
GC.start
aui_frame = AUIFrame.new(test_frame)
aui_frame = AUIFrame.new(frame_win)
aui_frame.show
GC.start
aui_frame.destroy
Expand Down
4 changes: 2 additions & 2 deletions tests/test_box_sizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ class BoxSizerTests < WxRuby::Test::GUITests

def setup
super
@win = Wx::Window.new(test_frame, Wx::ID_ANY)
@win = Wx::Window.new(frame_win, Wx::ID_ANY)
@sizer = Wx::HBoxSizer.new
@win.set_client_size(127, 35)
@win.sizer = @sizer
end

def cleanup
test_frame.destroy_children
frame_win.destroy_children
@win = nil
@sizer = nil
super
Expand Down
48 changes: 12 additions & 36 deletions tests/test_ext_controls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ class SearchCtrlTests < WxRuby::Test::GUITests

def setup
super
@search = Wx::SearchCtrl.new(test_frame, name: 'SearchCtrl')
Wx.get_app.yield
@search = Wx::SearchCtrl.new(frame_win, name: 'SearchCtrl')
end

def cleanup
@search.destroy
Wx.get_app.yield
super
end

Expand All @@ -31,13 +29,11 @@ class CalendarCtrlTests < WxRuby::Test::GUITests

def setup
super
@cal = Wx::CalendarCtrl.new(test_frame, name: 'Calendar')
Wx.get_app.yield
@cal = Wx::CalendarCtrl.new(frame_win, name: 'Calendar')
end

def cleanup
@cal.destroy
Wx.get_app.yield
super
end

Expand All @@ -63,13 +59,11 @@ class HyperlinkCtrlTests < WxRuby::Test::GUITests

def setup
super
@link = Wx::HyperlinkCtrl.new(test_frame, label: 'Hyperlink', url: 'https://mcorino.github.io/wxRuby3/Wx/HyperlinkCtrl.html', name: 'Hyperlink')
Wx.get_app.yield
@link = Wx::HyperlinkCtrl.new(frame_win, label: 'Hyperlink', url: 'https://mcorino.github.io/wxRuby3/Wx/HyperlinkCtrl.html', name: 'Hyperlink')
end

def cleanup
@link.destroy
Wx.get_app.yield
super
end

Expand All @@ -85,13 +79,11 @@ class BannerWindowTests < WxRuby::Test::GUITests

def setup
super
@banner = Wx::BannerWindow.new(test_frame, dir: Wx::Direction::TOP)
Wx.get_app.yield
@banner = Wx::BannerWindow.new(frame_win, dir: Wx::Direction::TOP)
end

def cleanup
@banner.destroy
Wx.get_app.yield
super
end

Expand All @@ -100,7 +92,6 @@ def cleanup
def test_link
assert_nothing_raised { banner.bitmap = Wx.Bitmap(:sample3) }
assert_nothing_raised { banner.set_text('BannerWindow Test', 'Welcome to the BannerWindow test.') }
Wx.get_app.yield
end

end
Expand All @@ -109,23 +100,19 @@ class InfoBarTests < WxRuby::Test::GUITests

def setup
super
@info = Wx::InfoBar.new(test_frame)
Wx.get_app.yield
@info = Wx::InfoBar.new(frame_win)
end

def cleanup
@info.destroy
Wx.get_app.yield
super
end

attr_reader :info

def test_link
assert_nothing_raised { info.show_message('Welcome to the InfoBar test.') }
Wx.get_app.yield
assert_nothing_raised { info.add_button(Wx::ID_HIGHEST+1000, 'Button1') }
Wx.get_app.yield
assert_equal(1, info.button_count)
assert_equal(Wx::ID_HIGHEST+1000, info.button_id(0))
assert_true(info.has_button_id?(Wx::ID_HIGHEST+1000))
Expand All @@ -137,8 +124,7 @@ class CommandLinkButtonTests < WxRuby::Test::GUITests

def setup
super
@button = Wx::CommandLinkButton.new(test_frame, mainLabel: 'CommandLinkButton', note: 'Testing CommandLinkButton')
Wx.get_app.yield
@button = Wx::CommandLinkButton.new(frame_win, mainLabel: 'CommandLinkButton', note: 'Testing CommandLinkButton')
end

def cleanup
Expand All @@ -159,15 +145,13 @@ def test_button

def test_click
count = count_events(button, :evt_button) do
sim = Wx::UIActionSimulator.new
sim = get_ui_simulator

# We move in to the middle of the widget, we need to yield
# after every Wx::UIActionSimulator action to keep everything working in GTK
sim.mouse_move(button.get_screen_position + (button.size / 2))
Wx.get_app.yield

sim.mouse_click
Wx.get_app.yield
end

assert_equal(1, count)
Expand All @@ -176,15 +160,13 @@ def test_click
def test_disabled
button.disable
count = count_events(button, :evt_button) do
sim = Wx::UIActionSimulator.new
sim = get_ui_simulator

# We move in to the middle of the widget, we need to yield
# after every Wx::UIActionSimulator action to keep everything working in GTK
sim.mouse_move(button.get_screen_position + (button.size / 2))
Wx.get_app.yield

sim.mouse_click
Wx.get_app.yield
end

assert_equal(0, count)
Expand All @@ -198,8 +180,7 @@ class SpinCtrlTests < WxRuby::Test::GUITests

def setup
super
@spin = Wx::SpinCtrl.new(test_frame, name: 'SpinCtrl')
Wx.get_app.yield
@spin = Wx::SpinCtrl.new(frame_win, name: 'SpinCtrl')
end

def cleanup
Expand All @@ -221,12 +202,10 @@ def test_arrows
spin.set_focus
Wx.get_app.yield
count = count_events(spin, :evt_spinctrl) do
sim = Wx::UIActionSimulator.new
sim = get_ui_simulator

sim.key_down(Wx::KeyCode::K_UP)
Wx.get_app.yield
sim.key_up(Wx::KeyCode::K_UP)
Wx.get_app.yield
end
assert_equal(1, count)
assert_equal(1, spin.value)
Expand All @@ -240,8 +219,7 @@ class SpinCtrlDoubleTests < WxRuby::Test::GUITests

def setup
super
@spin = Wx::SpinCtrlDouble.new(test_frame, name: 'SpinCtrlDouble')
Wx.get_app.yield
@spin = Wx::SpinCtrlDouble.new(frame_win, name: 'SpinCtrlDouble')
end

def cleanup
Expand All @@ -266,12 +244,10 @@ def test_arrows
spin.set_focus
Wx.get_app.yield
count = count_events(spin, :evt_spinctrldouble) do
sim = Wx::UIActionSimulator.new
sim = get_ui_simulator

sim.key_down(Wx::KeyCode::K_UP)
Wx.get_app.yield
sim.key_up(Wx::KeyCode::K_UP)
Wx.get_app.yield
end
assert_equal(1, count)
assert_equal(1.0, spin.value)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_grid_sizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ class GridSizerTests < WxRuby::Test::GUITests

def setup
super
@win = Wx::Window.new(test_frame, Wx::ID_ANY)
@win = Wx::Window.new(frame_win, Wx::ID_ANY)
@win.set_client_size(127, 35)
@sizer = Wx::GridSizer.new(2)
@win.set_sizer(@sizer)
end

def cleanup
test_frame.destroy_children
frame_win.destroy_children
@win = nil
@sizer = nil
super
Expand Down Expand Up @@ -46,14 +46,14 @@ class FlexGridSizerTests < WxRuby::Test::GUITests

def setup
super
@win = Wx::Window.new(test_frame, Wx::ID_ANY)
@win = Wx::Window.new(frame_win, Wx::ID_ANY)
@win.set_client_size(127, 35)
@sizer = Wx::FlexGridSizer.new(2)
@win.set_sizer(@sizer)
end

def cleanup
test_frame.destroy_children
frame_win.destroy_children
@win = nil
@sizer = nil
super
Expand Down
2 changes: 1 addition & 1 deletion tests/test_list_ctrl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ButtonTests < WxRuby::Test::GUITests

def setup
super
@list = Wx::ListCtrl.new(test_frame)
@list = Wx::ListCtrl.new(frame_win)
@list.set_window_style(Wx::LC_REPORT | Wx::LC_EDIT_LABELS)
@list.set_size([400, 200])
end
Expand Down
Loading

0 comments on commit 157d88b

Please sign in to comment.