Skip to content

Commit a2678ce

Browse files
committed
tests for osmrel2gpx
1 parent 37ba500 commit a2678ce

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

t/osmrel2gpx.t

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/perl -w
2+
# -*- cperl -*-
3+
4+
#
5+
# Author: Slaven Rezic
6+
#
7+
8+
use strict;
9+
use warnings;
10+
use FindBin;
11+
use lib $FindBin::RealBin, "$FindBin::RealBin/..";
12+
use utf8;
13+
14+
use Getopt::Long;
15+
use Test::More;
16+
17+
use BBBikeUtil qw(bbbike_root);
18+
use BBBikeTest qw(eq_or_diff gpxlint_string);
19+
use Strassen::Util ();
20+
21+
BEGIN {
22+
my $builder = Test::More->builder;
23+
binmode $builder->output, ":encoding(utf8)";
24+
binmode $builder->failure_output, ":encoding(utf8)";
25+
binmode $builder->todo_output, ":encoding(utf8)";
26+
}
27+
28+
BEGIN {
29+
if (!eval q{ use IPC::Run qw(run); 1 }) {
30+
plan skip_all => 'IPC::Run not available';
31+
}
32+
}
33+
34+
my $doit;
35+
my $keep;
36+
GetOptions(
37+
"doit" => \$doit,
38+
"keep" => \$keep,
39+
)
40+
or die "usage: $0 [--doit] [--keep]\n";
41+
42+
if (!$doit) {
43+
plan skip_all => "Skip expensive tests (may overwhelm overpass-api server, enable with --doit";
44+
}
45+
plan 'no_plan';
46+
47+
my $osmrel2gpx = bbbike_root . '/miscsrc/osmrel2gpx';
48+
49+
for my $test_case (
50+
[ 9030, undef, 'Berliner Mauerweg', '13.3114700,52.6275917', undef], # XXX incomplete track, relation member problems around Oberbaumbrücke
51+
[ 335268, undef, 'Spreeradweg [Beeskow-Berlin]', '14.2486957,52.1753471', undef], # XXX incomplete track, relation member problems around Oberbaumbrücke
52+
[ 27727, undef, 'Berlin-Usedom', '13.400738,52.516311', '13.772893,54.135781'],
53+
[2262839, undef, 'Oder-Neiße-Radweg [MV]', '14.1912112,53.9332517', '14.2619276,53.2766402'],
54+
[2262515, undef, 'Oder-Neiße-Radweg [BRB]', '14.2619276,53.2766402', '14.7317531,51.5873829'],
55+
[1069748, undef, 'Uckermärkischer Radrundweg', '13.9994783,53.0150285', '13.9994783,53.0150285'], # start/end in Angermünde
56+
[4784783, undef, 'Elberadweg [Tangermünde-Magdeburg]', '11.973961,52.542651', '11.642163,52.129183'],
57+
) {
58+
my($rel_id, $extra_args, $name, $exp_start_coord, $exp_end_coord) = @$test_case;
59+
my $cache_file = "/tmp/osmrel2gpx_response_${rel_id}.xml";
60+
my @cache_args = -r $cache_file ? ('--in-xml', $cache_file) : ('--cache');
61+
my @cmd = ($^X, $osmrel2gpx, @cache_args, '--id', $rel_id, $extra_args ? @$extra_args: ());
62+
my $success = run \@cmd, '>', \my $out, '2>', \my $err;
63+
ok $success, "Running '@cmd' for $name was successful"
64+
or diag "Stderr: $err";
65+
gpxlint_string $out, "Result for $name is valid gpx";
66+
if ($keep) {
67+
open my $ofh, ">", "/tmp/osmrel2gpx_${rel_id}.gpx" or die $!;
68+
print $ofh $out;
69+
close $ofh or die $!;
70+
}
71+
my($first_lat, $first_lon) = $out =~ m{<trkpt lat="([^"]+)" lon="([^"]+)"};
72+
my($last_lat, $last_lon) = $out =~ m{.*<trkpt lat="([^"]+)" lon="([^"]+)"}s;
73+
if (defined $exp_start_coord) {
74+
my $start_dist = Strassen::Util::strecke_s_polar($exp_start_coord, "$first_lon,$first_lat");
75+
cmp_ok $start_dist, "<=", 1000, "expected start coord within 1000m from $exp_start_coord, got $first_lon,$first_lat (dist is $start_dist)";
76+
}
77+
if (defined $exp_end_coord) {
78+
my $end_dist = Strassen::Util::strecke_s_polar($exp_end_coord, "$last_lon,$last_lat");
79+
cmp_ok $end_dist, "<=", 1000, "expected end coord within 1000m from $exp_end_coord, got $last_lon,$last_lat (dist is $end_dist)";
80+
}
81+
}
82+
83+
__END__

0 commit comments

Comments
 (0)