From: Emmanuel Rodriguez Date: Sun, 12 Apr 2009 14:07:12 +0000 (+0200) Subject: Testing the new methods X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3875cbe7498ff0722ab99dfbd78ad430816a6e75;p=libchamplain Testing the new methods --- diff --git a/bindings/perl/Champlain/t/ChamplainMarker.t b/bindings/perl/Champlain/t/ChamplainMarker.t index 2c6d04b..2b8dd1a 100644 --- a/bindings/perl/Champlain/t/ChamplainMarker.t +++ b/bindings/perl/Champlain/t/ChamplainMarker.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Clutter::TestHelper tests => 28; +use Clutter::TestHelper tests => 158; use Test::Builder; use Champlain ':coords'; @@ -28,6 +28,7 @@ sub tests { sub test_new { my $marker = Champlain::Marker->new(); isa_ok($marker, 'Champlain::Marker'); + generic_test($marker); } @@ -44,6 +45,7 @@ sub test_new_with_text { ok($marker->get_font_name, "new_with_text(font = undef) sets 'font_name'"); isa_ok($marker->get_text_color, 'Clutter::Color', "new_with_text(text_color = undef) sets 'text_color'"); isa_ok($marker->get_color, 'Clutter::Color', "new_with_text(color = undef) sets 'color'"); + generic_test($marker); # Create a label by specifying the colors @@ -66,6 +68,7 @@ sub test_new_with_text { Clutter::Color->new(0xff, 0xff, 0xff, 0xff), "new_with_text() sets 'color'" ); + generic_test($marker); } @@ -73,6 +76,7 @@ sub test_new_with_image { my $marker = Champlain::Marker->new_with_image($FILENAME); isa_ok($marker, 'Champlain::Marker'); isa_ok($marker->get_image, 'Clutter::Actor'); + generic_test($marker); # Assert that using a file that doesn't exist throws an exception eval { @@ -90,6 +94,7 @@ sub test_new_full { isa_ok($marker, 'Champlain::Marker'); is($marker->get_text, 'hello', "new_full() sets 'text'"); isa_ok($marker->get_image, 'Clutter::Actor'); + generic_test($marker); # Assert that using a file that doesn't exist throws an exception $@ = undef; @@ -103,8 +108,67 @@ sub test_new_full { } +sub generic_test { + my ($marker) = @_; + + # Test that the normal properties have default values + ok(!$marker->get_use_markup, "use markup is false by default"); + is($marker->get_alignment, 'left', "alignment is 'left' by default"); + ok(!$marker->get_wrap, "wrap is false by default"); + is($marker->get_ellipsize, 'none', "ellipsize is 'none' by default"); + ok($marker->get_single_line_mode, "single_line_mode is true by default"); + + + # Test the setters + $marker->set_use_markup(TRUE); + ok($marker->get_use_markup, "set_use_markup()"); + + $marker->set_alignment('center'); + is($marker->get_alignment, 'center', "set_alignment()"); + + $marker->set_wrap(TRUE); + ok($marker->get_wrap, "set_wrap()"); + + $marker->set_ellipsize('start'); + is($marker->get_ellipsize, 'start', "set_ellipsize()"); + + $marker->set_single_line_mode(TRUE); + ok($marker->get_single_line_mode, "set_single_line_mode()"); + + + $marker->set_text("dummy test"); + is($marker->get_text, "dummy test", "set_text()"); +# $marker->set_text(undef); +# is($marker->get_text, undef, "set_text(undef)"); + + $marker->set_image(Clutter::Ex::DeadActor->new()); + isa_ok($marker->get_image, 'Clutter::Ex::DeadActor', "set_image()"); +# $marker->set_image(undef); +# is($marker->get_image, undef, "set_image(undef)"); + + my $color = Clutter::Color->new(0xca, 0xfe, 0xbe, 0xef); + $marker->set_color($color); + is_color($marker->get_color, $color, "set_color()"); +# $marker->set_color(undef); +# is($marker->get_color, undef, "set_color(undef)"); + + my $text_color = Clutter::Color->new(0xca, 0xfe, 0xbe, 0xef); + $marker->set_text_color($text_color); + is_color($marker->get_text_color, $text_color, "set_text_color()"); +# $marker->set_text_color(undef); +# is($marker->get_text_color, undef, "set_text_color(undef)"); + + $marker->set_font_name("Mono 14"); + is($marker->get_font_name, "Mono 14", "set_font_name()"); + $marker->set_font_name(undef); + is($marker->get_font_name, undef, "set_font_name(undef)"); + + # Can't be tested but at least we call it +# $marker->set_attributes('as'); +} + # -# Compare colors. +# Assert that two colors are unique. # sub is_color { my ($got, $expected, $message) = @_; @@ -124,3 +188,13 @@ sub is_color { $tester->is_num($got->alpha, $expected->alpha, "$message, alpha matches"); } + +# +# An empty actor. +# +package Clutter::Ex::DeadActor; +use Glib::Object::Subclass 'Clutter::Actor',; + +# This is a an empty actor. This class is needed because Clutter::Actor is an +# abstract class. +