From: Emmanuel Rodriguez Date: Thu, 9 Jul 2009 20:04:24 +0000 (+0200) Subject: Complete tests for multiple selection mode X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b87cfe2eb5423a0b5f131a2823861706ecc3148;p=libchamplain Complete tests for multiple selection mode --- diff --git a/bindings/perl/Champlain/t/ChamplainSelectionLayer.t b/bindings/perl/Champlain/t/ChamplainSelectionLayer.t index 5726c54..e4944da 100644 --- a/bindings/perl/Champlain/t/ChamplainSelectionLayer.t +++ b/bindings/perl/Champlain/t/ChamplainSelectionLayer.t @@ -3,15 +3,18 @@ use strict; use warnings; -use Clutter::TestHelper tests => 5; +use Clutter::TestHelper tests => 25; use Champlain; +use Data::Dumper; exit tests(); sub tests { test_empty(); - test_markers(); +# test_markers_single(); + + test_markers_multiple(); return 0; } @@ -19,20 +22,24 @@ sub tests { sub test_empty { my $layer = Champlain::SelectionLayer->new(); isa_ok($layer, 'Champlain::Layer'); - - is($layer->get_selected, undef, "No selection on an empty layer"); - + + my $count; my @markers; + + is($layer->get_selected, undef, "[empty] get_selected()"); + + # In single mode get_selected_markers doesn't work @markers = $layer->get_selected_markers; - is_deeply(\@markers, [], "No selected markers on an empty layer"); - - my $count = $layer->count_selected_markers; - is($count, 0, "Empty marker count on a empty layer"); + is_deeply(\@markers, [], "[empty] get_selected_markers() list context"); + $count = $layer->get_selected_markers; + is($count, 0, "[empty] get_selected_markers() scalar context"); + + $count = $layer->count_selected_markers; + is($count, 0, "[empty] count_selected_markers()"); my $marker = Champlain::BaseMarker->new(); - - ok(!$layer->marker_is_selected($marker), "Marker is unselected on an empty layer"); - + ok(!$layer->marker_is_selected($marker), "[empty] marker_is_selected()"); + # Can't be tested but at least they are invoked $layer->select($marker); $layer->unselect($marker); @@ -43,28 +50,90 @@ sub test_empty { } -sub test_markers { +sub test_markers_multiple { my $layer = Champlain::SelectionLayer->new(); isa_ok($layer, 'Champlain::Layer'); - - is($layer->get_selected, undef, "No selection on an empty layer"); - + + + my @layer_markers = ( + Champlain::BaseMarker->new(), + Champlain::BaseMarker->new(), + Champlain::BaseMarker->new(), + Champlain::BaseMarker->new(), + ); + + # Add the markers and select a few markers + foreach my $marker (@layer_markers) { + $layer->add($marker); + } + $layer->select($layer_markers[1]); + $layer->select($layer_markers[3]); + + + # This doesn't work in multiple mode + is($layer->get_selected, undef, "[multiple] get_selected()"); + + my @markers; @markers = $layer->get_selected_markers; - is_deeply(\@markers, [], "No selected markers on an empty layer"); - + is_deeply(\@markers, [$layer_markers[1], $layer_markers[3]], "[multiple] get_selected_markers() list context"); + my $count = $layer->count_selected_markers; - is($count, 0, "Empty marker count on a empty layer"); + is($count, 2, "[multiple] count_selected_markers()"); my $marker = Champlain::BaseMarker->new(); - - ok(!$layer->marker_is_selected($marker), "Marker is unselected on an empty layer"); - - # Can't be tested but at least they are invoked + + # Check wich markers are selected + ok(!$layer->marker_is_selected($marker), "[multiple] marker_is_selected() maker not in set"); + ok(!$layer->marker_is_selected($layer_markers[0]), "[multiple] marker_is_selected() maker not selected"); + ok(!$layer->marker_is_selected($layer_markers[2]), "[multiple] marker_is_selected() maker not selected"); + ok($layer->marker_is_selected($layer_markers[1]), "[multiple] marker_is_selected() selected"); + ok($layer->marker_is_selected($layer_markers[3]), "[multiple] marker_is_selected() selected"); + + + # Select a new marker $layer->select($marker); - $layer->unselect($marker); -# $layer->select_all(); + ok($layer->marker_is_selected($marker), "[multiple] select() maker not in set"); + $count = $layer->count_selected_markers; + is($count, 3, "[multiple] count_selected_markers() with a new marker"); + is_deeply( + [ $layer->get_selected_markers ], + [$layer_markers[1], $layer_markers[3], $marker], + "[multiple] get_selected_markers() list context" + ); + + + # Select again one of the selected markers, this unselects it + $layer->select($marker); + ok(!$layer->marker_is_selected($marker), "[multiple] select() deselects an already selected marker"); + $count = $layer->count_selected_markers; + is($count, 2, "[multiple] count_selected_markers() with a deselected marker"); + is_deeply( + [ $layer->get_selected_markers ], + [$layer_markers[1], $layer_markers[3]], + "[multiple] get_selected_markers() list context" + ); + + + # Remove a marker + $layer->unselect($layer_markers[1]); + $count = $layer->count_selected_markers; + is($count, 1, "[multiple] count_selected_markers() after unselect()"); + is_deeply( + [ $layer->get_selected_markers ], + [$layer_markers[3]], + "[multiple] get_selected_markers() list context" + ); + + # Remove all markers $layer->unselect_all(); + $count = $layer->count_selected_markers; + is($count, 0, "[multiple] count_selected_markers() after count_selected_markers()"); + is_deeply( + [ $layer->get_selected_markers ], + [], + "[multiple] get_selected_markers() list context" + ); return 0; }