From: Emmanuel Rodriguez Date: Sat, 28 Mar 2009 09:21:47 +0000 (+0100) Subject: Zoom tests are done with a staged and unstaged view X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7dec84d35638d8f8e2180d500dd0e0809bc1603;p=libchamplain Zoom tests are done with a staged and unstaged view --- diff --git a/bindings/perl/Champlain/t/ChamplainView.t b/bindings/perl/Champlain/t/ChamplainView.t index 214e707..e04d44b 100644 --- a/bindings/perl/Champlain/t/ChamplainView.t +++ b/bindings/perl/Champlain/t/ChamplainView.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Clutter::TestHelper tests => 25; +use Clutter::TestHelper tests => 37; use Champlain ':coords'; @@ -12,24 +12,19 @@ exit tests(); sub tests { - test_generic(); + test_generic_in_stage(); test_zoom(); + test_zoom_in_stage(); test_event(); return 0; } # -# Test some default functionality +# Test some default functionality when the view is in a stage # -sub test_generic { - my $view = Champlain::View->new(); - isa_ok($view, 'Champlain::View'); - - my $stage = Clutter::Stage->get_default(); - $stage->set_size(800, 600); - $view->set_size(800, 600); - $stage->add($view); +sub test_generic_in_stage { + my $view = get_view(TRUE); # center_on() can be tested by checking the properties latitude and longitude. # And even then, the values set are not the ones returned @@ -65,11 +60,10 @@ sub test_generic { # -# Test the zoom functionality +# Test the zoom functionality with a view that's in a stage. # -sub test_zoom { - my $view = Champlain::View->new(); - isa_ok($view, 'Champlain::View'); +sub test_zoom_in_stage { + my $view = get_view(TRUE); # Zoom in @@ -102,14 +96,70 @@ sub test_zoom { $view->zoom_in(); is($view->get('zoom-level'), $max, "zoom-in past maximal level has no effect"); + # Go to the middle zoom level + my $middle = int( ($max - $min) / 2 ); + $view->set_zoom_level($middle); + is($view->get('zoom-level'), $middle, "set zoom to the middle level"); + # Try to set directly the zoom level to a value inferior to min level $view->set_zoom_level($min - 1); - is($view->get('zoom-level'), $min, "set zoom (min - 1)"); + is($view->get('zoom-level'), $middle, "set zoom (min - 1) has no effect"); # Try to set directly the zoom level to a valu superior to max level $view->set_zoom_level($max + 1); - is($view->get('zoom-level'), $max, "set zoom (max + 1)"); + is($view->get('zoom-level'), $middle, "set zoom (max + 1) has no effect"); +} + + +# +# Test the zoom functionality with a view that's not in a stage. If the view is +# not connected to a stage most operations will not work. +# +sub test_zoom { + my $view = get_view(); + + + # Zoom in + is($view->get('zoom-level'), 0, "original zoom-level"); + $view->zoom_in(); + is($view->get('zoom-level'), 0, "zoom-in has no effect"); + + # Zoom out + $view->zoom_out(); + is($view->get('zoom-level'), 0, "zoom-out has no effect"); + + + # Zoom to a random place + $view->set_zoom_level(1); + is($view->get('zoom-level'), 0, "set_zoom_level has no effect"); + + + my $map_source = $view->get('map-source'); + + # Zoom out past the min zoom level + my $min = $map_source->get_min_zoom_level; + $view->set_zoom_level($min); + is($view->get('zoom-level'), 0, "zoom-out to the minimal level has no effect"); + $view->zoom_out(); + is($view->get('zoom-level'), 0, "zoom-out past minimal level has no effect"); + + + # Zoom in after the max zoom level + my $max = $map_source->get_max_zoom_level; + $view->set_zoom_level($max); + is($view->get('zoom-level'), 0, "zoom-in to the maximal level has no effect"); + $view->zoom_in(); + is($view->get('zoom-level'), 0, "zoom-in past maximal level has no effect"); + + + # Try to set directly the zoom level to a value inferior to min level + $view->set_zoom_level($min - 1); + is($view->get('zoom-level'), 0, "set zoom (min - 1) has no effect"); + + # Try to set directly the zoom level to a valu superior to max level + $view->set_zoom_level($max + 1); + is($view->get('zoom-level'), 0, "set zoom (max + 1) has no effect"); } @@ -123,8 +173,7 @@ sub test_zoom { # threshold will be accepted. # sub test_event { - my $view = Champlain::View->new(); - isa_ok($view, 'Champlain::View'); + my $view = get_view(); my $map_source = $view->get('map-source'); my $size = $map_source->get_tile_size; @@ -148,3 +197,20 @@ sub test_event { ok($latitude >= -2.0 && $latitude <= 2.0, "get_coords_from_event() latitude"); ok($longitude >= -2.0 && $longitude <= 2.0, "get_coords_from_event() longitude"); } + + +sub get_view { + my ($in_stage) = @_; + + my $view = Champlain::View->new(); + isa_ok($view, 'Champlain::View'); + + return $view unless $in_stage; + + my $stage = Clutter::Stage->get_default(); + $stage->set_size(800, 600); + $view->set_size($stage->get_size); + $stage->add($view); + + return $view; +}