diff --git a/OsmAnd-java/build.xml b/OsmAnd-java/build.xml index 2af488526d..8e50b2386f 100644 --- a/OsmAnd-java/build.xml +++ b/OsmAnd-java/build.xml @@ -9,6 +9,8 @@ + + @@ -18,6 +20,11 @@ + + + + + @@ -27,6 +34,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -90,7 +120,7 @@ - + @@ -111,6 +141,9 @@ + + + diff --git a/OsmAnd-java/test/java/net/osmand/router/RouteResultPreparationTest.java b/OsmAnd-java/test/java/net/osmand/router/RouteResultPreparationTest.java new file mode 100644 index 0000000000..1428836e82 --- /dev/null +++ b/OsmAnd-java/test/java/net/osmand/router/RouteResultPreparationTest.java @@ -0,0 +1,151 @@ +package net.osmand.router; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import net.osmand.PlatformUtil; +import net.osmand.binary.BinaryMapIndexReader; +import net.osmand.data.LatLon; +import org.apache.commons.logging.Log; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.*; +import java.util.*; + +/** + * Created by yurkiss on 04.03.16. + */ + +@RunWith(Parameterized.class) +public class RouteResultPreparationTest { + + private static RoutePlannerFrontEnd fe; + private static RoutingContext ctx; + + private String testName; + private LatLon startPoint; + private LatLon endPoint; + private Map expectedResults; + + private Log log = PlatformUtil.getLog(RouteResultPreparationTest.class); + + public RouteResultPreparationTest(String testName, LatLon startPoint, LatLon endPoint, Map expectedResults) { + this.testName = testName; + this.startPoint = startPoint; + this.endPoint = endPoint; + this.expectedResults = expectedResults; + } + + @BeforeClass + public static void setUp() throws Exception { + String fileName = "../../../osmand/Turn_lanes_test.obf"; + String fileName2 = "../../../osmand/World_basemap_2.obf"; + + File fl = new File(fileName); + File fl2 = new File(fileName2); + + RandomAccessFile raf = new RandomAccessFile(fl, "r"); + RandomAccessFile raf2 = new RandomAccessFile(fl2, "r"); + + fe = new RoutePlannerFrontEnd(false); + RoutingConfiguration.Builder builder = RoutingConfiguration.getDefault(); + Map params = new LinkedHashMap(); + params.put("car", "true"); + params.put("short_way", "true"); + RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3, params); + BinaryMapIndexReader[] binaryMapIndexReaders = {new BinaryMapIndexReader(raf2, fl2), new BinaryMapIndexReader(raf, fl)}; + ctx = fe.buildRoutingContext(config, null, binaryMapIndexReaders, + RoutePlannerFrontEnd.RouteCalculationMode.NORMAL); + ctx.leftSideNavigation = false; + RouteResultPreparation.PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST = true; + + } + + @Parameterized.Parameters(name = "{index}: {0}") + public static Collection data() throws IOException { + + InputStream inputStream = RouteResultPreparationTest.class.getResourceAsStream("test_routes.json"); + //InputStream inputStream = new FileInputStream("test_routes.json"); + Reader reader = new InputStreamReader(inputStream); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + TestEntry[] testEntries = gson.fromJson(reader, TestEntry[].class); + ArrayList twoDArray = new ArrayList(); + for (int i = 0; i < testEntries.length; ++i) { + Object[] arr = new Object[]{ + testEntries[i].getTestName(), + testEntries[i].getStartPoint(), + testEntries[i].getEndPoint(), + testEntries[i].getExpectedResults() + }; + twoDArray.add(arr); + } + reader.close(); + return twoDArray; + + } + + @Test + public void testLanes() throws Exception { + + List routeSegments = fe.searchRoute(ctx, startPoint, endPoint, null); + + int prevSegment = -1; + for (int i = 0; i <= routeSegments.size(); i++) { + if (i == routeSegments.size() || routeSegments.get(i).getTurnType() != null) { + if (prevSegment >= 0) { + String lanes = getLanesString(routeSegments.get(prevSegment)); + String name = routeSegments.get(prevSegment).getDescription(); + + long segmentId = routeSegments.get(prevSegment).getObject().getId(); + String expectedResult = expectedResults.get(segmentId); + if (expectedResult != null) { + Assert.assertEquals("Segment " + segmentId, expectedResult, lanes); + } else { + //TODO: action if needed when expectedResults is null + } + + //Assert.fail("FAILED!"); + System.out.println("segmentId: " + segmentId + " description: " + name); + + } + prevSegment = i; + } + } + + } + + + String getLanesString(RouteSegmentResult segment) { + String turn = segment.getTurnType().toString(); + final int[] lns = segment.getTurnType().getLanes(); + if (lns != null) { + String s = ""; + for (int h = 0; h < lns.length; h++) { + if (h > 0) { + s += ", "; + } + if (lns[h] % 2 == 1) { + s += "+"; + } + int pt = TurnType.getPrimaryTurn(lns[h]); + if (pt == 0) { + pt = 1; + } + s += TurnType.valueOf(pt, false).toXmlString(); + int st = TurnType.getSecondaryTurn(lns[h]); + if (st != 0) { + s += ";" + TurnType.valueOf(st, false).toXmlString(); + } + + } + s += ""; + turn += s; + return s; + } + return null; + } + +} diff --git a/OsmAnd-java/test/java/net/osmand/router/TestEntry.java b/OsmAnd-java/test/java/net/osmand/router/TestEntry.java new file mode 100644 index 0000000000..71a07800c2 --- /dev/null +++ b/OsmAnd-java/test/java/net/osmand/router/TestEntry.java @@ -0,0 +1,51 @@ +package net.osmand.router; + +import net.osmand.data.LatLon; + +import java.util.Map; + +/** + * Created by User on 07.03.2016. + */ +public class TestEntry { + + private String testName; + private LatLon startPoint; + private LatLon endPoint; + private Map expectedResults; + + public LatLon getStartPoint() { + return startPoint; + } + + public void setStartPoint(LatLon startPoint) { + this.startPoint = startPoint; + } + + public LatLon getEndPoint() { + return endPoint; + } + + public void setEndPoint(LatLon endPoint) { + this.endPoint = endPoint; + } + + public Map getExpectedResults() { + return expectedResults; + } + + public void setExpectedResults(Map expectedResults) { + this.expectedResults = expectedResults; + } + + public String getTestName() { + return testName; + } + + public TestEntry(String testName, LatLon startPoint, LatLon endPoint, Map expectedResults) { + this.testName = testName; + this.startPoint = startPoint; + this.endPoint = endPoint; + this.expectedResults = expectedResults; + } +} diff --git a/OsmAnd-java/test/java/net/osmand/router/test_routes.json b/OsmAnd-java/test/java/net/osmand/router/test_routes.json new file mode 100644 index 0000000000..0ec56dcccb --- /dev/null +++ b/OsmAnd-java/test/java/net/osmand/router/test_routes.json @@ -0,0 +1,34 @@ +[ + { + "testName": "Amstelveenseweg", + "startPoint": { + "longitude": 35.51630312204361, + "latitude": 45.6971206184178 + }, + "endPoint": { + "longitude": 35.51303619146347, + "latitude": 45.6952846638807 + }, + "expectedResults": { + "-94307": "+TL, +TL, +TL, C, TR, TR", + "-96062": "+TL, +TL, +TL, +C, TR, TR", + "-96063": "+TL, +TL, +TL, C, TR, TR" + } + }, + { + "testName": "Amstelveenseweg2", + "startPoint": { + "longitude": 35.51630312204361, + "latitude": 45.6971206184178 + }, + "endPoint": { + "longitude": 35.51303619146347, + "latitude": 45.6952846638807 + }, + "expectedResults": { + "-96061": "+TL, +TL, +TL, +C, TR, TR", + "-96062": "+TL, +TL, +TL, C, TR, TR", + "-96063": "+TL, +TL, +TL, +C, TR, TR" + } + } +] \ No newline at end of file