From: Mattia B. <mat...@li...> - 2006-08-05 08:51:54
|
On Fri, 04 Aug 2006 22:41:51 -0400 Ed Heil <ed...@do...> wrote: Hi, > We've been talking about trying to put together a "test scripting > language" for our big wxPerl application. > > We'd like to be able to write a file full of commands stated in some > very simplistic code like -- > > > text-enter name "Smith" > button-click update > check name equals "Smith" > > that sort of thing -- and have the program trigger the appropriate > series of events, and make sure the right things happen. > > I tried to put together a minimalist, "proof of concept" demo. I put > together in wxglade a tiny application with a couple buttons and other > controls on it. I made an event handler for the first button which > called the function $frame->fake_event(). fake_event looks like this: > > > sub fake_event { > my $self=shift; > my $entry = "Testing"; > my $event=Wx::CommandEvent->new(wxEVT_COMMAND_BUTTON_CLICKED); > $event->SetEventObject($self->{button2}); > } > $window->GetEventHandler()->ProcessEvent( $event ); > I'd only gotten that far -- I hadn't figured out any more than > generating the event and setting its EventObject -- and I ran that > and got this -- > > C:\src>EventTester.pl > > (I clicked on the button to trigger fake_event and...) > > Can't locate object method "SetEventObject" via package > "Wx::CommandEvent" at C: > \src\EventTester.pl line 169. > > C:\src> > > > Uh oh. SetEventObject is a method of Wx::Event, and Wx::CommandEvent is > a subclass of Wx::Event, so that should have been found. > > I've got two basic questions -- > > 1. For people who know wxWidgets better than I do -- does this seem like > a profitable direction to go? Is this a crazy, doomed idea or is it > supposed to be possible to do this sort of thing? I think this will work for many common cases, so it is a reasonable way to go; it does not cover 100% of the cases though. And while faking (say) button events is trivial, wxTreeCtrl events might be more difficult to fake. http://www.wefi.net/swWxGuiTesting/ uses the same approach. I wanted to experiment with it (it even has an event recorder) but I could not get it to compile. It would be probably be easier and cleaner to rewrite it in Perl (because Perl is much more dynamic than C++, which I think will help in this case). > 2. Was that error ("Can't locate object method") just missing its perl > wrapper, or was something deeper going wrong? Just missing a perl wrapper. void wxEvent::SetEventObject( object ) wxObject* object in Event.xs should suffice. Let me know if it works. HTH Mattia |