From: Lyle Johnson Date: 2002-03-27T06:47:50+09:00 Subject: Re: Using FxRuby and Test::Unit. > I've been trying to write some code Test First using Test::Unit and FxRuby > and I'm having some problems. > > > Loaded suite FoxProblemDemo > Started... > ..FoxProblemDemo.rb:6: [BUG] Segmentation fault > > abnormal program termination > ruby 1.6.6 (2001-12-26) [i586-mswin32] > >Exit code: 3 > > The problem doesn't show up until the second test method is added. I'm > guessing that when set_up is called a second time a second application > object is create and that this is not allowed in Fox. I tried to get round > this by re-using the application object but this didn't help. I'm trying to > test a FXMainWindow sub-class and I get similar problems when I try to > instantiate a second instance using the same FXApp object. > > Any have any pointers on how to use FXRuby and Test::Unit together would be > appreciated. I'm just starting to look into this myself and so I don't have a "cookbook" solution yet. But listed below is a test case I wrote for the FXButton class that may give you some ideas. Note that it doesn't ever call create() to actually create the server-side resources and display the GUI; it is strictly testing the client-side data. I'm still not exactly sure how to unit test GUI components like this, in an automated setting. Anyways... Hope this helps, Lyle require 'test/unit' require 'fox' include Fox class TC_FXButton < Test::Unit::TestCase def set_up if FXApp.instance.nil? @app = FXApp.new('TC_FXButton', 'FXRuby') @app.init([]) @mainwin = FXMainWindow.new(@app, 'TC_FXButton') else @app = FXApp.instance @mainwin = @app.mainWindow end @button = FXButton.new(@mainwin, "buttonText") end def testText assert_not_nil(@button.text) assert_instance_of(String, @button.text) assert_equal("buttonText", @button.text) assert_not_equal("googly-moogly", @button.text) @button.text = nil assert_not_nil(@button.text) assert_instance_of(String, @button.text) end def testStyle assert_not_nil(@button.buttonStyle) assert_instance_of(Fixnum, @button.buttonStyle) @button.buttonStyle |= BUTTON_AUTOGRAY assert((@button.buttonStyle & BUTTON_AUTOGRAY) != 0) @button.buttonStyle &= ~BUTTON_AUTOGRAY assert((@button.buttonStyle & BUTTON_AUTOGRAY) == 0) @button.buttonStyle |= BUTTON_AUTOHIDE assert((@button.buttonStyle & BUTTON_AUTOHIDE) != 0) @button.buttonStyle &= ~BUTTON_AUTOHIDE assert((@button.buttonStyle & BUTTON_AUTOHIDE) == 0) @button.buttonStyle |= BUTTON_TOOLBAR assert((@button.buttonStyle & BUTTON_TOOLBAR) != 0) @button.buttonStyle &= ~BUTTON_TOOLBAR assert((@button.buttonStyle & BUTTON_TOOLBAR) == 0) @button.buttonStyle |= BUTTON_DEFAULT assert((@button.buttonStyle & BUTTON_DEFAULT) != 0) @button.buttonStyle &= ~BUTTON_DEFAULT assert((@button.buttonStyle & BUTTON_DEFAULT) == 0) @button.buttonStyle |= BUTTON_INITIAL # unlike others, this should not work assert((@button.buttonStyle & BUTTON_INITIAL) == 0) end def testState assert_not_nil(@button.state) assert_kind_of(Fixnum, @button.state) @button.state = STATE_UP assert_equal(STATE_UP, @button.state) @button.state = STATE_DOWN assert_equal(STATE_DOWN, @button.state) @button.state = STATE_ENGAGED assert_equal(STATE_ENGAGED, @button.state) @button.state = STATE_CHECKED assert_equal(STATE_CHECKED, @button.state) @button.state = STATE_UNCHECKED assert_equal(STATE_UNCHECKED, @button.state) end end