From: Phlip Date: 2001-12-17T00:55:30+09:00 Subject: [ruby-talk:28690] Re: GUI testing with GTK? Massimiliano Mirra sez: > On Sun, Dec 16, 2001 at 10:14:43AM +0900, Phlip wrote: >> Not really. I can post pseudo code. But I don't have an example of this >> technique anywhere on my current 'puters... > > Please bear with me and tell me whether I am understanding it correctly. > (It doesn't look like something one could apply to GTK, but sooner or > later it will be Tk time for me too, and a way to test the GUI without > looking at it will be a blessing to my eyes.) > > def test_GUIForm > tk = Tk() # create the root element frame = Frame(tk) > # create left side widget with parent in brackets editField = > Edit(frame) # as above > object = UIobject(frame) # as above > > # test that a widget holds a certain value. but where's the # > ``putting values into the interface'' part? assert editField.get() == > "interesting value" > > # mainloop() > tk.destroy() > > This way you can test the binding between the widgets and the underlying > model, but can you also test response to user actions? Because I do this all the time, and because you are trying to do it a different way, I guess I'm trying to head towards a "manifesto of testing without calling mainloop". You seemed from your initial post to be doing it a different way. That's okay, but it might have been because you assumed a window must be seen to be clicked on. The documentation for libraries written test-last often neglects issues like how to click on an unseen window, or how to destroy the window before showing it. Below my sig is an example of testing a Gtk UI by not calling Gtk.main. I didn't do the final commented item, clicking on the UI and summoning different values in the UI control, because I don't want to research into what others in this thread told you. Likewise, I did not research how to query a control back out of a window - I just made the tested function return the controls I needed. Shortcuts like these - extra tiny features in the tested code on behalf of the testors - are very common in all of engineering. Play with the $visible flag to see the results. -- Phlip phlip_cpp@yahoo.com http://flea.sourceforge.net -- Now collecting votes for a new group: news:alt.flame.moderated -- require 'gtk' $visible = false def assert bool throw "get a clue" if not bool end def testedFunction win cbitems = [ "item0", "item1 item1" ] win.border_width(0) box1 = Gtk::VBox::new(false, 0) win.add(box1) box1.show box2 = Gtk::VBox::new(false, 10) box2.border_width(10) box1.pack_start(box2, true, true, 0) box2.show entry = Gtk::Entry::new() entry.set_text("hello world") entry.select_region(0, 5) box2.pack_start(entry, true, true, 0) entry.show cb = Gtk::Combo::new() cb.set_popdown_strings(cbitems) cb.entry.set_text("hello world") box2.pack_start(cb, true, true, 0) cb.show return entry, cb end def test_entryThing win = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL) entry, cb = testedFunction (win) assert entry.get_text == "hello world" assert cb.entry.get_text == "hello world" # click on another cb line # assert cb.entry.get_text == "item0" if $visible then win.show Gtk.main else win.destroy end end test_entryThing