Debian Codegraph @

test/func/SimpleTest.java

raw symbols SCIP
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: 10-Jan-2009
16 */
17 package func;
18
19 import java.io.File;
20 import java.io.FileNotFoundException;
21 import java.util.List;
22
23 import uk.me.parabola.imgfmt.app.Area;
24 import uk.me.parabola.imgfmt.app.map.MapReader;
25 import uk.me.parabola.imgfmt.app.trergn.Point;
26 import uk.me.parabola.imgfmt.app.trergn.Polyline;
27 import uk.me.parabola.imgfmt.fs.DirectoryEntry;
28 import uk.me.parabola.imgfmt.fs.FileSystem;
29 import uk.me.parabola.mkgmap.main.Main;
30
31 import func.lib.Args;
32 import func.lib.RangeMatcher;
33 import func.lib.TestUtils;
34 import org.junit.Test;
35
36 import static org.junit.Assert.*;
37
38 /**
39 * Very simple checks. May go away as more detailed checks are developed.
40 *
41 * @author Steve Ratcliffe
42 */
43 public class SimpleTest extends Base {
44
45 /**
46 * A very basic check that the size of all the sections has not changed.
47 * This can be used to make sure that a change that is not expected to
48 * change the output does not do so.
49 *
50 * The sizes will have to be always changed when the output does change
51 * though.
52 */
53 @Test
54 public void testBasic() throws FileNotFoundException {
55
56 Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--preserve-element-order",
57 Args.TEST_RESOURCE_OSM + "uk-test-1.osm.gz");
58
59 MapReader mr = new MapReader(Args.DEF_MAP_ID + ".img");
60 TestUtils.registerFile(mr);
61 //FileSystem fs = ImgFS.openFs(Args.DEF_MAP_ID + ".img");
62 assertNotNull("file exists", mr);
63
64 Area bounds = mr.getTreBounds();
65 Area expBox = new Area(2402404, -11185, 2407064, -6524);
66 assertEquals("bounds of map", expBox, bounds);
67
68 List<Point> list = mr.pointsForLevel(0, MapReader.WITH_EXT_TYPE_DATA);
69 assertEquals("number of points at level 0", 204, list.size());
70
71 List<Polyline> list1 = mr.linesForLevel(0);
72 assertEquals("number of lines at level 0", 3289, list1.size());
73 }
74
75 @Test
76 public void testNoSuchFile() {
77 Main.mainNoSystemExit("no-such-file-xyz.osm");
78 assertFalse("no file generated", new File(Args.DEF_MAP_FILENAME).exists());
79 }
80
81 @Test
82 public void testPolish() throws FileNotFoundException {
83 Main.mainNoSystemExit(Args.TEST_STYLE_ARG, Args.TEST_RESOURCE_MP + "test1.mp");
84
85 FileSystem fs = openFs(Args.DEF_MAP_FILENAME);
86 assertNotNull("file exists", fs);
87
88 List<DirectoryEntry> entries = fs.list();
89 int count = 0;
90 for (DirectoryEntry ent : entries) {
91 String ext = ent.getExt();
92
93 int size = ent.getSize();
94 switch (ext) {
95 case "RGN":
96 count++;
97 System.out.println("RGN size " + size);
98 assertThat("RGN size", size, new RangeMatcher(2630,3));
99 break;
100 case "TRE":
101 count++;
102 System.out.println("TRE size " + size);
103 // Size varies depending on svn modified status
104 assertThat("TRE size", size, new RangeMatcher(770, 2));
105 break;
106 case "LBL":
107 count++;
108 assertEquals("LBL size", 999, size);
109 break;
110 }
111 }
112 assertTrue("enough checks run", count >= 3);
113
114 }
115 }