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