[libchamplain/libchampain-0-4] Run the animations in an event loop



commit 2b309f6ec69102bafb656d9690bbaec84e1d28a5
Author: Emmanuel Rodriguez <emmanuel rodriguez gmail com>
Date:   Wed Sep 23 19:05:40 2009 +0200

    Run the animations in an event loop

 bindings/perl/Champlain/t/ChamplainBaseMarker.t |   42 +++++++++++++++++++---
 1 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/bindings/perl/Champlain/t/ChamplainBaseMarker.t b/bindings/perl/Champlain/t/ChamplainBaseMarker.t
index 1a212ee..4ed2292 100644
--- a/bindings/perl/Champlain/t/ChamplainBaseMarker.t
+++ b/bindings/perl/Champlain/t/ChamplainBaseMarker.t
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Clutter::TestHelper tests => 8;
+use Clutter::TestHelper tests => 13;
 
 use Champlain;
 
@@ -30,12 +30,42 @@ sub tests {
 	$marker->set_highlighted(FALSE);
 	is($marker->get_highlighted(), FALSE, "Changed highlighted to false");
 
-    # Can't be tested but at least we call them
-    $marker->animate_in();
-    $marker->animate_in_with_delay(200);
-    $marker->animate_out();
-    $marker->animate_out_with_delay(200);
+	# Test the animations by starting them and creating an event loop. The event
+	# loop will timeout after a while assuming that the animation is over.
+	ok($marker->get('opacity'));
+	$marker->animate_out();
+	run_event_loop();
+	is($marker->get('opacity'), 0, 'animate_out()');
+
+	$marker->animate_in();
+	run_event_loop();
+	is($marker->get('opacity'), 255, 'animate_in()');
+
+	$marker->animate_out_with_delay(200);
+	run_event_loop();
+	is($marker->get('opacity'), 0, 'animate_out_with_delay()');
+
+	$marker->animate_in_with_delay(200);
+	run_event_loop();
+	is($marker->get('opacity'), 255, 'animate_in_with_delay()');
 
 	return 0;
 }
 
+
+#
+# Runs a main loop for the purpose of executing one animation. The main loop is
+# timed in case where the test doesn't work.
+#
+sub run_event_loop {
+	my ($view) = @_;
+
+	# Give us a bit of time to get there since this is an animation and it
+	# requires an event loop. We add an idle timeout in order to make sure that we
+	# don't wait forever.
+	Glib::Timeout->add(2_000, sub {
+		Clutter->main_quit();
+		return FALSE;
+	});
+	Clutter->main();
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]