~ubuntu-branches/ubuntu/oneiric/mkgmap/oneiric

« back to all changes in this revision

Viewing changes to test/uk/me/parabola/mkgmap/osmstyle/StyledConverterTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine, Andreas Putzo, Francesco Paolo Lovergine
  • Date: 2009-07-16 11:10:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090716111016-yycxqya1f26xmti7
Tags: 0.0.0+svn1067-1
[ Andreas Putzo ]
* New upstream snapshot.
* Added ${misc:Depends} among dependencies to fix a lintian warning.
* Bumped debhelper compatibility level to 7.
* Updated long description.
* Updated Homepage in debian/control, debian/copyright, debian/watch.
* Added numerous files from /doc to debian/docs.
* Mentioned Bernhard Heibler in debian/copyright and updated copyright
  year of software and packaging.
* Bumped policy to 3.8.2, without changes.
* Added DM-Upload-Allowed to debian/control.

[ Francesco Paolo Lovergine ]
* Added me as Uploader to avoid possible inappropriate NMU notices.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Steve Ratcliffe
 
3
 * 
 
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.
 
7
 * 
 
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.
 
12
 * 
 
13
 * 
 
14
 * Author: Steve Ratcliffe
 
15
 * Create date: 02-Dec-2008
 
16
 */
 
17
package uk.me.parabola.mkgmap.osmstyle;
 
18
 
 
19
import java.io.FileNotFoundException;
 
20
import java.util.ArrayList;
 
21
import java.util.List;
 
22
import java.util.Properties;
 
23
 
 
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;
 
33
 
 
34
import static org.junit.Assert.*;
 
35
import org.junit.Before;
 
36
import org.junit.Test;
 
37
 
 
38
 
 
39
/**
 
40
 * High level tests of the complete converter chain, using an actual
 
41
 * rules file.
 
42
 */
 
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>();
 
47
 
 
48
        @Test
 
49
        public void testConvertWay() {
 
50
                Way way = makeWay();
 
51
                way.addTag("highway", "primary");
 
52
                way.addTag("x", "y");
 
53
                converter.convertWay(way);
 
54
 
 
55
                assertEquals("line converted", 1, lines.size());
 
56
                assertEquals("line from highway", 0x2, lines.get(0).getType());
 
57
        }
 
58
 
 
59
        @Test
 
60
        public void testNullPointerFromSecondMatch() throws FileNotFoundException {
 
61
                Way way = makeWay();
 
62
                way.addTag("highway", "primary");
 
63
                way.addTag("x", "z");
 
64
                converter.convertWay(way);
 
65
 
 
66
                assertEquals("line converted", 1, lines.size());
 
67
                assertEquals("line from x=y", 0x3, lines.get(0).getType());
 
68
        }
 
69
 
 
70
        @Test
 
71
        public void testModifyingTagsInUse() throws FileNotFoundException {
 
72
                Way way = makeWay();
 
73
                way.addTag("name", "bar");
 
74
                way.addTag("highway", "other");
 
75
                way.addTag("a", "z");
 
76
                way.addTag("z", "z");
 
77
                converter.convertWay(way);
 
78
 
 
79
                assertEquals("line converted", 1, lines.size());
 
80
                assertEquals("line", 0x12, lines.get(0).getType());
 
81
        }
 
82
 
 
83
        /**
 
84
         * Test the overlay feature, when one line is duplicated with different
 
85
         * types.
 
86
         */
 
87
        @Test
 
88
        public void testOverlay() {
 
89
                Way way = makeWay();
 
90
                way.addTag("highway", "overlay");
 
91
                converter.convertWay(way);
 
92
 
 
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());
 
97
        }
 
98
 
 
99
        /**
 
100
         * Test styles that are derived from others.  Rules should behave as
 
101
         * if they were combined in order with the base rule last.
 
102
         */
 
103
        @Test
 
104
        public void testBaseStyle() throws FileNotFoundException {
 
105
                converter = makeConverter("derived");
 
106
                Way way = makeWay();
 
107
                way.addTag("overridden", "xyz");
 
108
                converter.convertWay(way);
 
109
 
 
110
                assertEquals("lines converted", 1, lines.size());
 
111
                assertEquals("derived type", 0x12, lines.get(0).getType());
 
112
 
 
113
                // Now try a rule that is only in the base 'simple' file.
 
114
                way = makeWay();
 
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());
 
119
        }
 
120
 
 
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));
 
126
                return way;
 
127
        }
 
128
 
 
129
        @Before
 
130
        public void setUp() throws FileNotFoundException {
 
131
                converter = makeConverter("simple");
 
132
        }
 
133
 
 
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) { }
 
138
 
 
139
                        // could save points in the same way as lines to test them
 
140
                        public void addPoint(MapPoint point) { }
 
141
 
 
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());
 
145
                                lines.add(line);
 
146
                        }
 
147
 
 
148
                        public void addShape(MapShape shape) { }
 
149
 
 
150
                        public void addRoad(MapRoad road) { }
 
151
                };
 
152
 
 
153
                return new StyledConverter(style, coll, new Properties());
 
154
        }
 
155
}