[libchamplain] Test the registration of a custom map source



commit 7181e2ffa02b1f1eb6688538bdf1cdbf9e96b832
Author: Emmanuel Rodriguez <emmanuel rodriguez gmail com>
Date:   Tue May 19 12:07:49 2009 +0200

    Test the registration of a custom map source

 .../perl/Champlain/t/ChamplainMapSourceFactory.t   |   57 ++++++++++++++++++-
 1 files changed, 54 insertions(+), 3 deletions(-)
---
diff --git a/bindings/perl/Champlain/t/ChamplainMapSourceFactory.t b/bindings/perl/Champlain/t/ChamplainMapSourceFactory.t
index 62a3e14..c6de5ca 100644
--- a/bindings/perl/Champlain/t/ChamplainMapSourceFactory.t
+++ b/bindings/perl/Champlain/t/ChamplainMapSourceFactory.t
@@ -3,9 +3,9 @@
 use strict;
 use warnings;
 
-use Clutter::TestHelper tests => 22;
+use Clutter::TestHelper tests => 35;
 
-use Champlain ':coords';
+use Champlain ':maps';
 
 my $OSM_LICENSE = "(CC) BY 2.0 OpenStreetMap contributors";
 
@@ -14,6 +14,7 @@ exit tests();
 sub tests {
 	test_map_source_names();
 	test_map_factory();
+	test_map_register();
 	return 0;
 }
 
@@ -28,7 +29,6 @@ sub test_map_source_names {
 }
 
 
-
 sub test_map_factory {
 	my $factory = Champlain::MapSourceFactory->dup_default();
 	isa_ok($factory, 'Champlain::MapSourceFactory');
@@ -65,6 +65,57 @@ sub test_map_factory {
 }
 
 
+sub test_map_register {
+	my $factory = Champlain::MapSourceFactory->get_default();
+	isa_ok($factory, 'Champlain::MapSourceFactory');
+	
+	# Get the maps available
+	my @maps = $factory->get_list();
+	ok(@maps >= 5, "Maps factory has the default maps");
+	
+	# Add a new map
+	my $description = {
+  	id => 'perl',
+		name => 'Perl Fake Map',
+		license => 'Artistic License',
+		license_uri => 'http://dev.perl.org/licenses/artistic.html',
+		min_zoom_level => 0,
+		max_zoom_level => 11,
+		projection => 'mercator',
+	};
+	
+	$factory->register($description, sub {
+		return Champlain::NetworkMapSource->new_full(
+			$description->{id},
+			$description->{name},
+			$description->{license},
+			$description->{license_uri},
+			$description->{min_zoom_level},
+			$description->{max_zoom_level},
+			256,
+			$description->{projection},
+			# This is a copy of OAM
+			"http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z#/#X#/#Y#.jpg";,
+		);
+	});
+
+	my @new_maps = $factory->get_list();
+	ok(@new_maps == @maps + 1, "Maps factory has an extra map");
+	
+	my $map = $factory->create('perl');
+	isa_ok($map, 'Champlain::MapSource');
+	is($map->get_id, $description->{id}, "Created map has the right id");
+	is($map->get_name, $description->{name}, "Created map has the right name");
+	is($map->get_license, $description->{license}, "Created map has the right license");
+	is($map->get_license_uri, $description->{license_uri}, "Created map has the right license_uri");
+	is($map->get_min_zoom_level, $description->{min_zoom_level}, "Created map has the right min_zoom_level");
+	is($map->get_max_zoom_level, $description->{max_zoom_level}, "Created map has the right max_zoom_level");
+	is($map->get_projection, $description->{projection}, "Created map has the right projection");
+	is($map->get_tile_size, 256, "Created map has the right tile_size");
+	is($map->get_tile_uri(1, 2, 3), "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/3/1/2.jpg";, "Created map has the right tile_uri");
+}
+
+
 sub generic_create {
 	my ($factory, $id, $name) = @_;
 	my $map = $factory->create($id);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]