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



commit 56585857e1f22b7717db789bb93dd2ce995ce0fa
Author: Emmanuel Rodriguez <emmanuel rodriguez gmail com>
Date:   Wed Sep 23 18:34:19 2009 +0200

    Run the animations within an event loop

 bindings/perl/Champlain/t/ChamplainLayer.t |   34 ++++++++++++++++++++++++---
 1 files changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/bindings/perl/Champlain/t/ChamplainLayer.t b/bindings/perl/Champlain/t/ChamplainLayer.t
index c1ae40a..e6ab042 100644
--- a/bindings/perl/Champlain/t/ChamplainLayer.t
+++ b/bindings/perl/Champlain/t/ChamplainLayer.t
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Clutter::TestHelper tests => 9;
+use Clutter::TestHelper tests => 12;
 
 use Champlain;
 
@@ -32,17 +32,43 @@ sub tests {
 	$layer->hide();
 	ok(!$layer->get('visible'), "hide()");
 
-	# Too hard to test, but at least we call them
-	$layer->animate_in_all_markers();
+	# 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'));
 	$layer->animate_out_all_markers();
+	run_event_loop();
+	is($marker->get('opacity'), 0, 'animate_out_all_markers()');
+
+	$layer->animate_in_all_markers();
+	run_event_loop();
+	is($marker->get('opacity'), 255, 'animate_in_all_markers()');
 
 	# Show/Hide the markers
 	ok($marker->get('visible'), "marker is not visible");
 	$layer->hide_all_markers();
+	run_event_loop();
 	ok(!$marker->get('visible'), "hide_all_markers()");
 
-
 	$layer->show_all_markers();
+	run_event_loop();
 	ok($marker->get('visible'), "show_all_markers()");
+
 	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]