From: Emmanuel Rodriguez Date: Sat, 28 Mar 2009 16:55:35 +0000 (+0100) Subject: Simplified the unit tests. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23b0c087db0fd69a28432373f76778168fb6d4ca;p=libchamplain Simplified the unit tests. There's no need to test a staged view and an unstaged view. Both behave now similarly. --- diff --git a/bindings/perl/Champlain/t/ChamplainView.t b/bindings/perl/Champlain/t/ChamplainView.t index 6391cbe..b0dc7c2 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 => 44; +use Clutter::TestHelper tests => 31; use Champlain ':coords'; @@ -12,19 +12,19 @@ exit tests(); sub tests { - test_generic_in_stage(); + test_generic(); test_zoom(); - test_zoom_in_stage(); test_event(); return 0; } # -# Test some default functionality when the view is in a stage +# Test some default functionality. # -sub test_generic_in_stage { - my $view = get_view(TRUE); +sub test_generic { + my $view = Champlain::View->new(); + isa_ok($view, 'Champlain::View'); # center_on() can be tested by checking the properties latitude and longitude. # And even then, the values set are not the ones returned @@ -35,8 +35,8 @@ sub test_generic_in_stage { ok($view->get('longitude') != $longitude, "center_on() changed longitude"); # set_size() can be tested by checking the properties width and height - is($view->get('width'), 800, "original width"); - is($view->get('height'), 600, "original height"); + is($view->get('width'), 0, "original width"); + is($view->get('height'), 0, "original height"); $view->set_size(600, 400); is($view->get('width'), 600, "set_size() changed width"); is($view->get('height'), 400, "set_size() changed height"); @@ -60,10 +60,11 @@ sub test_generic_in_stage { # -# Test the zoom functionality with a view that's in a stage. +# Test the zoom functionality. # -sub test_zoom_in_stage { - my $view = get_view(TRUE); +sub test_zoom { + my $view = Champlain::View->new(); + isa_ok($view, 'Champlain::View'); # Zoom in @@ -130,71 +131,6 @@ sub test_zoom_in_stage { } -# -# 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"); - $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->set("zoom-level", $min); - is($view->get('zoom-level'), 0, "set('zoom-level') 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->set("zoom-level", $max); - is($view->get('zoom-level'), 0, "set('zoom-level') 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"); - - # NOTE: This gives a warning because -1 out of range for property `zoom-level' - #$view->set("zoom-level", $min - 1); - #is($view->get('zoom-level'), 0, "set('zoom-level', 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"); -} - - # # Test getting the coordinates from an event. # @@ -205,44 +141,31 @@ sub test_zoom { # threshold will be accepted. # sub test_event { - my $view = get_view(); + my $view = Champlain::View->new(); + isa_ok($view, 'Champlain::View'); my $map_source = $view->get('map-source'); my $size = $map_source->get_tile_size; + ok($size > 0); # NOTE: At the moment this works only if the view is in a stage and if # show_all() was called my $stage = Clutter::Stage->get_default(); $stage->set_size($size, $size); $view->set_size($size, $size); + $view->center_on(0, 0); $stage->add($view); $stage->show_all(); # Create a fake event in the middle of the tile my $event = Clutter::Event->new('button_press'); - $event->x($size/2); - $event->y($size/2); - is($event->x, $size/2); - is($event->y, $size/2); - + my $middle = int($size/2); + $event->x($middle); + $event->y($middle); + is($event->x, $middle); + is($event->y, $middle); + my ($latitude, $longitude) = $view->get_coords_from_event($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; -}