]> err.no Git - libchamplain/commitdiff
Complete tests for multiple selection mode
authorEmmanuel Rodriguez <emmanuel.rodriguez@gmail.com>
Thu, 9 Jul 2009 20:04:24 +0000 (22:04 +0200)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Tue, 28 Jul 2009 21:25:36 +0000 (17:25 -0400)
bindings/perl/Champlain/t/ChamplainSelectionLayer.t

index 5726c54ec18160e27f8d65389c5f35459d9822d1..e4944da0635a8b17613545025bc1c411859b1b33 100644 (file)
@@ -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;
 }