use of uk.me.parabola.mkgmap.reader.osm.OsmConverter in project mkgmap by openstreetmap.
the class StyleTester method runTest.
private static void runTest(String stylefile, String mapfile) {
PrintingMapCollector collector = new PrintingMapCollector();
OsmConverter normal;
try {
normal = new StyleTester(stylefile, collector, reference);
} catch (FileNotFoundException e) {
System.err.println("Could not open style file " + stylefile);
return;
}
try {
InputStream is = Utils.openFile(mapfile);
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setXIncludeAware(true);
parserFactory.setNamespaceAware(true);
SAXParser parser = parserFactory.newSAXParser();
try {
EnhancedProperties props = new EnhancedProperties();
props.put("preserve-element-order", "1");
ElementSaver saver = new ElementSaver(props);
OsmXmlHandler handler = new OsmXmlHandler();
SaxHandler saxHandler = handler.new SaxHandler();
handler.setElementSaver(saver);
parser.parse(is, saxHandler);
saver.finishLoading();
saver.convert(normal);
System.err.println("Conversion time " + (System.currentTimeMillis() - collector.getStart()) + "ms");
} catch (IOException e) {
throw new FormatException("Error reading file", e);
}
} catch (SAXException e) {
throw new FormatException("Error parsing file", e);
} catch (ParserConfigurationException e) {
throw new FormatException("Internal error configuring xml parser", e);
} catch (FileNotFoundException e) {
System.err.println("Cannot open file " + mapfile);
}
}
use of uk.me.parabola.mkgmap.reader.osm.OsmConverter in project mkgmap by openstreetmap.
the class StyleTester method runSimpleTest.
/**
* Run a simple test with a combined test file.
* @param filename The test file contains text way definitions and a style
* file all in one.
*/
public static void runSimpleTest(String filename) {
try {
FileReader reader = new FileReader(filename);
BufferedReader br = new BufferedReader(reader);
List<Way> ways = readSimpleTestFile(br);
List<String> givenList = readGivenResults();
boolean noStrict = false;
if (!givenList.isEmpty() && Objects.equals(givenList.get(0), "NO-STRICT")) {
givenList.remove(0);
noStrict = true;
}
List<MapElement> strictResults = new ArrayList<>();
List<MapElement> results = new ArrayList<>();
List<String> actual = new ArrayList<>();
List<String> expected = new ArrayList<>();
for (Way w : ways) {
OsmConverter normal = new StyleTester("styletester.style", new LocalMapCollector(results), false);
String prefix = "WAY " + w.getId() + ": ";
normal.convertWay(w.copy());
normal.end();
actual.addAll(formatResults(prefix, results));
results.clear();
if (!noStrict) {
OsmConverter strict = new StyleTester("styletester.style", new LocalMapCollector(strictResults), true);
strict.convertWay(w.copy());
strict.end();
expected.addAll(formatResults(prefix, strictResults));
strictResults.clear();
}
}
printResult("", actual);
if (!noStrict && !Objects.equals(actual, expected)) {
out.println("ERROR expected result is:");
printResult("|", expected);
}
if ((!givenList.isEmpty() || forceUseOfGiven) && !Objects.equals(actual, givenList)) {
out.println("ERROR given results were:");
printResult("", givenList);
}
} catch (FileNotFoundException e) {
System.err.println("Cannot open test file " + filename);
} catch (IOException e) {
System.err.println("Failure while reading test file " + filename);
}
}
Aggregations