use strict;
use warnings;
-use Clutter::TestHelper tests => 25;
+use Clutter::TestHelper tests => 37;
use Champlain ':coords';
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
#
-# 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
$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");
}
# 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;
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;
+}