From aa5098642d7e55d5a9fa83998457d788b71798c0 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 6 Jun 2010 18:09:27 +0200 Subject: Detect non-itinerary efa.vrr.de output (i.e. upon invalid input data) --- bin/efa | 24 +- test/50-efa.t | 10 +- test/dump_invalid_input | 793 +++++++++++++++++++++++++++++++++++++++++++++++ test/parse_invalid_input | 1 + 4 files changed, 819 insertions(+), 9 deletions(-) create mode 100644 test/dump_invalid_input create mode 100644 test/parse_invalid_input diff --git a/bin/efa b/bin/efa index 3056c81..aa82864 100755 --- a/bin/efa +++ b/bin/efa @@ -223,7 +223,7 @@ sub opt_timeout { sub parse_tree { my ($full_tree) = @_; my $con_part = 0; - my $con_no = 0; + my $con_no; my $cons; my $xp_td = XML::LibXML::XPathExpression->new('//table//table/tr/td'); @@ -255,11 +255,22 @@ sub parse_tree { } } - if (not $td->exists($xp_img) and $td->textContent() !~ /^\s*$/) { + if ( + defined $con_no and not $td->exists($xp_img) + and $td->textContent() !~ /^\s*$/ + ) + { push(@{$cons->[$con_no]->[$con_part]}, $td->textContent()); } } - return $cons; + + if (defined $con_no) { + return $cons; + } + else { + say "efa.vrr.de returned no connections, check your input data."; + exit 3; + } } GetOptions( @@ -362,10 +373,6 @@ check_no_connections($tree); $connections = parse_tree($tree); -if (@{$connections} == 0) { - die("Got no connections, parse error?\n"); -} - for my $i (0 .. $#{$connections}) { display_connection($connections->[$i]); if ($i != $#{$connections}) { @@ -523,7 +530,8 @@ Print version information 0 Everything went well 1 Ambiguous input, re-run efa with different arguments - 2 efa.vrr.de error + 2 efa.vrr.de error (i.e. unable to find matching connections) + 3 efa.vrr.de error (usually invalid input data) 255 Any other kind of error =head1 CONFIGURATION diff --git a/test/50-efa.t b/test/50-efa.t index 067b70b..ef97fb9 100644 --- a/test/50-efa.t +++ b/test/50-efa.t @@ -3,7 +3,7 @@ use strict; use warnings; use 5.010; -use Test::Command tests => 82; +use Test::Command tests => 85; my $efa = 'bin/efa'; my $testarg = "E HBf MH HBf"; @@ -152,3 +152,11 @@ $cmd = Test::Command->new( $cmd->exit_is_num(2); $cmd->stdout_is_file('test/parse_no_connections'); $cmd->stderr_is_eq($EMPTY); + +$cmd = Test::Command->new( + cmd => "$efa $test_parse < test/dump_invalid_input" +); + +$cmd->exit_is_num(3); +$cmd->stdout_is_file('test/parse_invalid_input'); +$cmd->stderr_is_eq($EMPTY); diff --git a/test/dump_invalid_input b/test/dump_invalid_input new file mode 100644 index 0000000..fbdd3a1 --- /dev/null +++ b/test/dump_invalid_input @@ -0,0 +1,793 @@ + + + +Fahrplanauskunft + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Aushangfahrplan
Abfahrtsmonitor
Persönlicher Fahrplan
Verbundfahrplan Schnellverkehr
Linienplan Schnellverkehr
Stadtlinienpläne
Bedienungshinweise
Bildschirmschoner
Aktuelle Hinweise
Ihr Link zu uns
Impressum
Homepage
+
  + + + + + + + +
+
Fahrplanauskunft
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
*
* von:Stadt/Ort*Essen*
 
*
*Haltestelle*Hauptbahnhof
**
+
+ + + + + +
+ +
+
+
*
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
*
* nach:Stadt/Ort*Düsseldorf*
 
*
*Haltestelle*Hbf
**
+
+ + + + + +
+ +
+
+
*
+
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
*
* Linienauswahl
*
*alle Linien
*alle Linien ohne ICE
*nur Verbund-/Nahverkehrslinien
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
*
* Umsteigen / Fußwege
**
zeitkürzeste Verbindungen
Verbindungen mit wenig Umsteigen
Verbindungen mit kurzen Fußwegen
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
*
 Gehgeschwindigkeit 
**
normal
schnell
langsam
+
*
+ + + + + +
 Berücksichtigung von Nachbarhaltestellen bei Start und Ziel
+
*
+
*
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
*
* Zeit:
* Abfahrt*Uhr*Datum
* Ankunft     + + + + + + +
*Uhrzeit unbrauchbar
*
+
*
+ + + + + + + + + + + + + + + + +
*
***
*
+
+
+
*
+
+ +
+ +
+ +
+ +
+
+ + + +
**
+
+
+ + diff --git a/test/parse_invalid_input b/test/parse_invalid_input new file mode 100644 index 0000000..5686f5d --- /dev/null +++ b/test/parse_invalid_input @@ -0,0 +1 @@ +efa.vrr.de returned no connections, check your input data. -- cgit v1.2.3