From 7ed8819fbbf208e75d6df20da512ae96e0e1e62b Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Mon, 3 Sep 2012 21:21:46 +0200 Subject: [PATCH] sanity-check h2g sequence number --- .../schildbach/pte/AbstractHafasProvider.java | 3 +++ .../pte/live/RmvProviderLiveTest.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/enabler/src/de/schildbach/pte/AbstractHafasProvider.java b/enabler/src/de/schildbach/pte/AbstractHafasProvider.java index e9634ce9..47707457 100644 --- a/enabler/src/de/schildbach/pte/AbstractHafasProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractHafasProvider.java @@ -1579,6 +1579,9 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider is.skipBytes(extensionHeaderPtr + 0x8); final int seqNr = is.readShortReverse(); + if (seqNr <= 0) + throw new IllegalStateException("illegal sequence number: " + seqNr); + final String requestId = strings.read(is); final int connectionDetailsPtr = is.readIntReverse(); diff --git a/enabler/test/de/schildbach/pte/live/RmvProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/RmvProviderLiveTest.java index e1942503..26333162 100644 --- a/enabler/test/de/schildbach/pte/live/RmvProviderLiveTest.java +++ b/enabler/test/de/schildbach/pte/live/RmvProviderLiveTest.java @@ -17,6 +17,9 @@ package de.schildbach.pte.live; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.util.Date; import java.util.List; @@ -87,6 +90,8 @@ public class RmvProviderLiveTest extends AbstractProviderLiveTest final QueryConnectionsResult result = queryConnections(new Location(LocationType.STATION, 3000001, null, "Hauptwache"), null, new Location( LocationType.STATION, 3000912, null, "Südbahnhof"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL, Accessibility.NEUTRAL); System.out.println(result); + assertEquals(QueryConnectionsResult.Status.OK, result.status); + assertTrue(result.connections.size() > 0); if (!result.context.canQueryLater()) return; @@ -149,6 +154,24 @@ public class RmvProviderLiveTest extends AbstractProviderLiveTest System.out.println(earlier4Result); } + @Test + public void slowConnection() throws Exception + { + final QueryConnectionsResult result = queryConnections( + new Location(LocationType.STATION, 3029079, 50017679, 8229480, "Mainz", "An den Dünen"), null, new Location(LocationType.STATION, + 3013508, 50142890, 8895203, "Hanau", "Beethovenplatz"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL, + Accessibility.BARRIER_FREE); + System.out.println(result); + assertEquals(QueryConnectionsResult.Status.OK, result.status); + assertTrue(result.connections.size() > 0); + + if (!result.context.canQueryLater()) + return; + + final QueryConnectionsResult laterResult = queryMoreConnections(result.context, true); + System.out.println(laterResult); + } + @Test public void shortConnectionByName() throws Exception {