root/branches/new-install-process/t/28_wgs84_coords.t

Revision 1089, 2.9 kB (checked in by dom, 19 months ago)

Remove junk executable property

Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More;
6
7eval { require DBD::SQLite; };
8
9if ( $@ ) {
10    my ($error) = $@ =~ /^(.*?)\n/;
11    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
12}
13
14plan tests => 6;
15
16# Clear out the database from any previous runs.
17unlink "t/node.db";
18# And give us a new one
19Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
20
21# Now we can start testing
22my $config = OpenGuides::Test->make_basic_config;
23$config->force_wgs84 (1);
24
25my $guide = OpenGuides->new( config => $config );
26
27my ($longitude, $latitude) = (10, 12);
28
29my ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
30                                                    longitude => $longitude,
31                                                    latitude => $latitude,
32                                                    config => $config);
33
34is( $wgs_long, $longitude,
35    "get_wgs84_coords returns the original longitude when force_wgs84 is on");
36is( $wgs_lat, $latitude,
37    "get_wgs84_coords returns the original latitude when force_wgs84 is on");
38
39
40# Now claim to be in the UK
41eval{ require Geo::HelmertTransform; };
42my $have_helmert = $@ ? 0 : 1;
43SKIP : {
44    skip "Geo::HelmertTransform not installed - can't do transforms", 4
45        unless $have_helmert;
46
47    $config->force_wgs84(0);
48    $config->geo_handler(1);
49
50    # Set our location to be somewhere known
51       ($longitude,$latitude)  = (-1.258200,51.754349);
52    my ($wgs84_lon,$wgs84_lat) = (-1.259687,51.754813);
53
54    ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
55                                                     longitude => $longitude,
56                                                     latitude => $latitude,
57                                                     config => $config);
58
59    # Round to 5 dp
60    my $fivedp = 1 * 1000 * 100;
61    $wgs_long = int($wgs_long * $fivedp)/$fivedp;
62    $wgs_lat  = int($wgs_lat  * $fivedp)/$fivedp;
63    $wgs84_lon = int($wgs84_lon * $fivedp)/$fivedp;
64    $wgs84_lat = int($wgs84_lat * $fivedp)/$fivedp;
65
66    is( $wgs_long, $wgs84_lon,
67        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
68    is( $wgs_lat, $wgs84_lat,
69        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
70
71    # Call it again, check we get the same result
72    ($wgs_long, $wgs_lat) = OpenGuides::Utils->get_wgs84_coords(
73                                                     longitude => $longitude,
74                                                     latitude => $latitude,
75                                                     config => $config);
76    $wgs_long = int($wgs_long * $fivedp)/$fivedp;
77    $wgs_lat  = int($wgs_lat  * $fivedp)/$fivedp;
78    is( $wgs_long, $wgs84_lon,
79        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
80    is( $wgs_lat, $wgs84_lat,
81        "get_wgs84_coords does Airy1830 -> WGS84 convertion properly");
82}
Note: See TracBrowser for help on using the browser.