2
* Copyright (C) 2008 Steve Ratcliffe
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
14
* Author: Steve Ratcliffe
15
* Create date: 02-Dec-2008
17
package uk.me.parabola.mkgmap.osmstyle;
19
import java.io.FileNotFoundException;
20
import java.util.ArrayList;
21
import java.util.List;
22
import java.util.Properties;
24
import uk.me.parabola.imgfmt.app.Coord;
25
import uk.me.parabola.mkgmap.general.MapCollector;
26
import uk.me.parabola.mkgmap.general.MapLine;
27
import uk.me.parabola.mkgmap.general.MapPoint;
28
import uk.me.parabola.mkgmap.general.MapRoad;
29
import uk.me.parabola.mkgmap.general.MapShape;
30
import uk.me.parabola.mkgmap.reader.osm.OsmConverter;
31
import uk.me.parabola.mkgmap.reader.osm.Style;
32
import uk.me.parabola.mkgmap.reader.osm.Way;
34
import static org.junit.Assert.*;
35
import org.junit.Before;
36
import org.junit.Test;
40
* High level tests of the complete converter chain, using an actual
43
public class StyledConverterTest {
44
private static final String LOC = "classpath:teststyles";
45
private OsmConverter converter;
46
private final List<MapLine> lines = new ArrayList<MapLine>();
49
public void testConvertWay() {
51
way.addTag("highway", "primary");
53
converter.convertWay(way);
55
assertEquals("line converted", 1, lines.size());
56
assertEquals("line from highway", 0x2, lines.get(0).getType());
60
public void testNullPointerFromSecondMatch() throws FileNotFoundException {
62
way.addTag("highway", "primary");
64
converter.convertWay(way);
66
assertEquals("line converted", 1, lines.size());
67
assertEquals("line from x=y", 0x3, lines.get(0).getType());
71
public void testModifyingTagsInUse() throws FileNotFoundException {
73
way.addTag("name", "bar");
74
way.addTag("highway", "other");
77
converter.convertWay(way);
79
assertEquals("line converted", 1, lines.size());
80
assertEquals("line", 0x12, lines.get(0).getType());
84
* Test the overlay feature, when one line is duplicated with different
88
public void testOverlay() {
90
way.addTag("highway", "overlay");
91
converter.convertWay(way);
93
assertEquals("lines produced", 3, lines.size());
94
assertEquals("first line is 1", 1, lines.get(0).getType());
95
assertEquals("second line is 2", 2, lines.get(1).getType());
96
assertEquals("third line is 3", 3, lines.get(2).getType());
100
* Test styles that are derived from others. Rules should behave as
101
* if they were combined in order with the base rule last.
104
public void testBaseStyle() throws FileNotFoundException {
105
converter = makeConverter("derived");
107
way.addTag("overridden", "xyz");
108
converter.convertWay(way);
110
assertEquals("lines converted", 1, lines.size());
111
assertEquals("derived type", 0x12, lines.get(0).getType());
113
// Now try a rule that is only in the base 'simple' file.
115
way.addTag("highway", "primary");
116
converter.convertWay(way);
117
assertEquals("new line converted from base", 2, lines.size());
118
assertEquals("from base style", 0x3, lines.get(1).getType());
121
private Way makeWay() {
122
Way way = new Way(1);
123
way.addPoint(new Coord(100, 100));
124
way.addPoint(new Coord(100, 102));
125
way.addPoint(new Coord(100, 103));
130
public void setUp() throws FileNotFoundException {
131
converter = makeConverter("simple");
134
private StyledConverter makeConverter(String name) throws FileNotFoundException {
135
Style style = new StyleImpl(LOC, name);
136
MapCollector coll = new MapCollector() {
137
public void addToBounds(Coord p) { }
139
// could save points in the same way as lines to test them
140
public void addPoint(MapPoint point) { }
142
public void addLine(MapLine line) {
143
// Save line so that it can be examined in the tests.
144
assertNotNull("points are not null", line.getPoints());
148
public void addShape(MapShape shape) { }
150
public void addRoad(MapRoad road) { }
153
return new StyledConverter(style, coll, new Properties());