2016-03-12 18:51:43 +01:00
|
|
|
package net.osmand.router;
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
2016-03-30 16:03:06 +02:00
|
|
|
|
2016-03-12 18:51:43 +01:00
|
|
|
import net.osmand.PlatformUtil;
|
2016-04-28 10:22:07 +02:00
|
|
|
import net.osmand.binary.BinaryInspector;
|
2016-03-12 18:51:43 +01:00
|
|
|
import net.osmand.binary.BinaryMapIndexReader;
|
|
|
|
import net.osmand.data.LatLon;
|
2016-04-09 14:11:09 +02:00
|
|
|
import net.osmand.util.Algorithms;
|
2016-03-30 16:03:06 +02:00
|
|
|
|
2016-03-12 18:51:43 +01:00
|
|
|
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<Long, String> expectedResults;
|
|
|
|
|
|
|
|
private Log log = PlatformUtil.getLog(RouteResultPreparationTest.class);
|
|
|
|
|
|
|
|
public RouteResultPreparationTest(String testName, LatLon startPoint, LatLon endPoint, Map<Long, String> expectedResults) {
|
|
|
|
this.testName = testName;
|
|
|
|
this.startPoint = startPoint;
|
|
|
|
this.endPoint = endPoint;
|
|
|
|
this.expectedResults = expectedResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUp() throws Exception {
|
2016-05-31 09:40:15 +02:00
|
|
|
String fileName = "../../resources/test-resources/Turn_lanes_test.obf";
|
2016-03-12 18:51:43 +01:00
|
|
|
|
|
|
|
File fl = new File(fileName);
|
|
|
|
|
|
|
|
RandomAccessFile raf = new RandomAccessFile(fl, "r");
|
|
|
|
|
|
|
|
fe = new RoutePlannerFrontEnd(false);
|
|
|
|
RoutingConfiguration.Builder builder = RoutingConfiguration.getDefault();
|
|
|
|
Map<String, String> params = new LinkedHashMap<String, String>();
|
|
|
|
params.put("car", "true");
|
|
|
|
params.put("short_way", "true");
|
|
|
|
RoutingConfiguration config = builder.build("car", RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3, params);
|
2016-03-12 22:14:15 +01:00
|
|
|
BinaryMapIndexReader[] binaryMapIndexReaders = {new BinaryMapIndexReader(raf, fl)};
|
2016-03-12 18:51:43 +01:00
|
|
|
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<Object[]> data() throws IOException {
|
2016-03-30 16:03:06 +02:00
|
|
|
String fileName = "/test_turn_lanes.json";
|
|
|
|
Reader reader = new InputStreamReader(RouteResultPreparationTest.class.getResourceAsStream(fileName));
|
2016-03-12 18:51:43 +01:00
|
|
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
|
|
TestEntry[] testEntries = gson.fromJson(reader, TestEntry[].class);
|
|
|
|
ArrayList<Object[]> twoDArray = new ArrayList<Object[]>();
|
|
|
|
for (int i = 0; i < testEntries.length; ++i) {
|
2016-04-13 00:47:05 +02:00
|
|
|
if (!testEntries[i].isIgnore()) {
|
|
|
|
Object[] arr = new Object[] { testEntries[i].getTestName(), testEntries[i].getStartPoint(),
|
|
|
|
testEntries[i].getEndPoint(), testEntries[i].getExpectedResults() };
|
|
|
|
twoDArray.add(arr);
|
|
|
|
}
|
2016-03-12 18:51:43 +01:00
|
|
|
}
|
|
|
|
reader.close();
|
|
|
|
return twoDArray;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testLanes() throws Exception {
|
|
|
|
List<RouteSegmentResult> routeSegments = fe.searchRoute(ctx, startPoint, endPoint, null);
|
2016-03-17 19:10:48 +01:00
|
|
|
Set<Long> reachedSegments = new TreeSet<Long>();
|
2016-04-09 14:17:20 +02:00
|
|
|
Assert.assertNotNull(routeSegments);
|
2016-03-12 18:51:43 +01:00
|
|
|
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));
|
2016-04-09 14:11:09 +02:00
|
|
|
String turn = routeSegments.get(prevSegment).getTurnType().toXmlString();
|
|
|
|
String turnLanes = turn +":" +lanes;
|
2016-03-12 18:51:43 +01:00
|
|
|
String name = routeSegments.get(prevSegment).getDescription();
|
|
|
|
|
2016-04-28 10:31:27 +02:00
|
|
|
long segmentId = routeSegments.get(prevSegment).getObject().getId() >> (BinaryInspector.SHIFT_ID );
|
2016-03-12 18:51:43 +01:00
|
|
|
String expectedResult = expectedResults.get(segmentId);
|
|
|
|
if (expectedResult != null) {
|
2016-04-09 14:11:09 +02:00
|
|
|
if(!Algorithms.objectEquals(expectedResult, turnLanes) &&
|
|
|
|
!Algorithms.objectEquals(expectedResult, lanes) &&
|
|
|
|
!Algorithms.objectEquals(expectedResult, turn)) {
|
|
|
|
Assert.assertEquals("Segment " + segmentId, expectedResult, turnLanes);
|
|
|
|
}
|
2016-03-12 18:51:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("segmentId: " + segmentId + " description: " + name);
|
|
|
|
|
|
|
|
}
|
|
|
|
prevSegment = i;
|
|
|
|
}
|
2016-03-17 19:10:48 +01:00
|
|
|
|
|
|
|
if (i < routeSegments.size()) {
|
2016-04-28 10:31:27 +02:00
|
|
|
reachedSegments.add(routeSegments.get(i).getObject().getId() >> (BinaryInspector.SHIFT_ID ));
|
2016-03-17 19:10:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<Long> expectedSegments = expectedResults.keySet();
|
|
|
|
for (Long expSegId : expectedSegments){
|
2016-04-28 10:31:27 +02:00
|
|
|
Assert.assertTrue("Expected segment " + (expSegId ) +
|
2016-04-28 10:22:07 +02:00
|
|
|
" weren't reached in route segments " + reachedSegments.toString(), reachedSegments.contains(expSegId));
|
2016-03-12 18:51:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-15 11:58:13 +01:00
|
|
|
private String getLanesString(RouteSegmentResult segment) {
|
2016-03-12 18:51:43 +01:00
|
|
|
final int[] lns = segment.getTurnType().getLanes();
|
|
|
|
if (lns != null) {
|
2016-06-01 19:46:04 +02:00
|
|
|
return TurnType.toString(lns);
|
2016-03-12 18:51:43 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|