[libchamplain] More unit tests.



commit 6536ce325c4c2bee659a73bf41b1f8fb7b1bb538
Author: Emmanuel Rodriguez <emmanuel rodriguez gmail com>
Date:   Sun Jun 14 18:00:05 2009 +0200

    More unit tests.
    
    Test the behaviour of a freshly created polygon and the setters.

 bindings/perl/Champlain/t/ChamplainPolygon.t |   85 +++++++++++++++++++++++++-
 1 files changed, 82 insertions(+), 3 deletions(-)
---
diff --git a/bindings/perl/Champlain/t/ChamplainPolygon.t b/bindings/perl/Champlain/t/ChamplainPolygon.t
index 950a4b2..48aac76 100644
--- a/bindings/perl/Champlain/t/ChamplainPolygon.t
+++ b/bindings/perl/Champlain/t/ChamplainPolygon.t
@@ -3,19 +3,98 @@
 use strict;
 use warnings;
 
-use Clutter::TestHelper tests => 1;
+use Clutter::TestHelper tests => 34;
 
 use Champlain;
 
+my $DEFAULT_FILL_COLOR = Champlain::Polygon->new()->get_fill_color;
+my $DEFAULT_STROKE_NAME = Champlain::Polygon->new()->get_stroke_color;
+
 exit tests();
 
 sub tests {
-	test_generic();
+	test_empty();
+	test_setters();
+#	test_points();
 	return 0;
 }
 
 
-sub test_generic {
+sub test_empty {
 	my $polygon = Champlain::Polygon->new();
 	isa_ok($polygon, 'Champlain::Polygon');
+	
+	my @points = $polygon->get_points();
+	is_deeply(\ points, [], "No points on a new polygon");
+	
+	$polygon->clear_points();
+	is_deeply(\ points, [], "No points on a cleared polygon");
+	
+	is_color($polygon->get_fill_color, $DEFAULT_FILL_COLOR, "fill_color is set on a new polygon");
+	is_color($polygon->get_stroke_color, $DEFAULT_STROKE_NAME, "stroke_color is set on a new polygon");
+	
+	ok(!$polygon->get_fill, "fill is set on a new polygon");
+	ok($polygon->get_stroke, "stroke is set on a new polygon");
+	is($polygon->get_stroke_width, 2, "stroke_width is set on a new polygon");
+	
+	# Call these methods hopping that they won't crash.
+	$polygon->show();
+	$polygon->hide();
+}
+
+
+sub test_setters {
+	my $polygon = Champlain::Polygon->new();
+	isa_ok($polygon, 'Champlain::Polygon');
+
+
+	my $color;
+	
+	$color = Clutter::Color->new(0xaa, 0xdd, 0x37, 0xbb);
+	$polygon->set_fill_color($color);
+	is_color($polygon->get_fill_color, $color, "set_fill_color");
+	
+	$color = Clutter::Color->new(0x44, 0x33, 0x23, 0x2b);
+	$polygon->set_stroke_color($color);
+	is_color($polygon->get_stroke_color, $color, "set_stroke_color");
+	
+	{
+		my $old_fill = $polygon->get_fill;
+		$polygon->set_fill(!$old_fill);
+		is($polygon->get_fill, !$old_fill, "set_fill()");
+	}
+	
+	{
+		my $old_stroke = $polygon->get_stroke;
+		$polygon->set_stroke(!$old_stroke);
+		is($polygon->get_stroke, !$old_stroke, "set_stroke()");
+	}
+
+	{	
+		my $old_stroke_width = $polygon->get_stroke_width;
+		$polygon->set_stroke_width($old_stroke_width + 2);
+		is($polygon->get_stroke_width, $old_stroke_width + 2, "set_stroke_width()");
+	}
+}
+
+
+#
+# Assert that two colors are identical.
+#
+sub is_color {
+	my ($got, $expected, $message) = @_;
+	my $tester = Test::Builder->new();
+	my $are_colors = 1;
+	$are_colors &= $tester->is_eq(ref($got), 'Clutter::Color', "$message, got is a Clutter::Color");
+	$are_colors &= $tester->is_eq(ref($expected), 'Clutter::Color', "$message, expected a Clutter::Color");
+
+	if (! $are_colors) {
+		$tester->ok(0, "$message, can't compare color components") for 1 .. 4;
+		return;
+	}
+
+	$tester->is_num($got->red, $expected->red, "$message, red matches");
+	$tester->is_num($got->green, $expected->green, "$message, green matches");
+	$tester->is_num($got->blue, $expected->blue, "$message, blue matches");
+	$tester->is_num($got->alpha, $expected->alpha, "$message, alpha matches");
 }



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