g_test with mainloop integration and async signals
Submitted by Mikkel Kamstrup Erlandsen
Assigned to Tim Janik
Link to original bug (#508394)
Description
This is a followup on a thread on gtk-devel: http://mail.gnome.org/archives/gtk-devel-list/2008-January/msg00009.html
I often find it necessary to create tests that deal with asynchronous libraries. I suspect that I am not the only one (X, gio, libwnck, libbeagle, libdbus-glib, ad nauseum all use async communications in some way). It would be great to make this easy peasy to do with the g_test utilities.
I attach a patch based on Scott Asofyet's work integrating two new concepts to the gtestutils family:
-
g_test_add_with_main_loop() in gtestutils.h: similar to g_test_add but runs fixture_test() as an idle handler in a GMainLoop.
-
g_object_test_wait_for_signal() in the gobject module : runs a mainloop until a specific signal is emitted on an object or until a timeout is reached. It will give back signal arguments as well.
This makes it easy to support the following workflow:
setup(): bla bla test(): send request, block for response, validate resp. Rinse repeat ad lib. teardown() alb alb
Version: 2.15.x