Debian Codegraph @

test/func/StructureTest.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
22 import uk.me.parabola.imgfmt.app.lbl.LBLFileReader;
23 import uk.me.parabola.imgfmt.app.trergn.RGNFileReader;
24 import uk.me.parabola.imgfmt.app.trergn.TREFileReader;
25 import uk.me.parabola.imgfmt.app.trergn.TREHeader;
26 import uk.me.parabola.imgfmt.fs.FileSystem;
27 import uk.me.parabola.imgfmt.fs.ImgChannel;
28 import uk.me.parabola.imgfmt.sys.ImgFS;
29 import uk.me.parabola.mkgmap.main.Main;
30
31 import func.lib.Args;
32 import func.lib.TestUtils;
33 import org.junit.AfterClass;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36
37 import static org.junit.Assert.*;
38
39 /**
40 * Creates a single img file and runs several tests on it to verify
41 * the basic structure of it.
42 *
43 * @author Steve Ratcliffe
44 */
45 public class StructureTest {
46 private static FileSystem fs;
47
48 private static LBLFileReader lblFile;
49 private static TREFileReader treFile;
50 private static RGNFileReader rgnFile;
51
52 /** Just test is exists. */
53 @Test
54 public void testExists() {
55 File f = new File(Args.DEF_MAP_FILENAME);
56 assertTrue("file exists", f.exists());
57 }
58
59 @Test
60 public void testTreHeader() {
61 TREHeader header = (TREHeader) treFile.getHeader();
62 assertEquals("header length", 188, header.getHeaderLength());
63
64 assertEquals("display priority", 25, header.getDisplayPriority());
65 }
66
67 /**
68 * Read in the file and open all the sections, leave references to them
69 * in fields so that the other tests can check things.
70 */
71 @BeforeClass
72 public static void init() throws FileNotFoundException {
73 TestUtils.deleteOutputFiles();
74
75 Main.mainNoSystemExit(Args.TEST_STYLE_ARG, Args.TEST_RESOURCE_OSM + "uk-test-1.osm.gz");
76
77 fs = ImgFS.openFs(Args.DEF_MAP_FILENAME);
78 ImgChannel tre = fs.open(Args.DEF_MAP_ID + ".TRE", "r");
79 treFile = new TREFileReader(tre);
80
81 ImgChannel lbl = fs.open(Args.DEF_MAP_ID + ".LBL", "r");
82 lblFile = new LBLFileReader(lbl);
83
84 ImgChannel rgn = fs.open(Args.DEF_MAP_ID + ".RGN", "r");
85 rgnFile = new RGNFileReader(rgn);
86 }
87
88 /**
89 * Close everything down.
90 */
91 @AfterClass
92 public static void cleanup() {
93 if (fs != null) {
94 fs.close();
95 treFile.close();
96 lblFile.close();
97 rgnFile.close();
98 }
99 TestUtils.deleteOutputFiles();
100 }
101 }