Debian Codegraph @

test/func/style/ScriptedStyleTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2010.
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 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13 package func.style;
14
15 import java.io.ByteArrayOutputStream;
16 import java.io.File;
17 import java.io.FilenameFilter;
18 import java.io.IOException;
19 import java.io.OutputStream;
20 import java.io.PrintStream;
21
22 import uk.me.parabola.mkgmap.main.StyleTester;
23
24 import func.lib.TestUtils;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 import static org.junit.Assert.*;
29
30 /**
31 * A set of tests written as files, using the StyleTester.
32 */
33 public class ScriptedStyleTest {
34 private OutputStream output;
35
36 /**
37 * This is to check that the tests are working. Run a test that fails
38 * on purpose to check that we can detect this.
39 */
40 @Test
41 public void failureTest() {
42 TestUtils.registerFile("styletester.style");
43 StyleTester.runSimpleTest("test/resources/rules/fails-on-purpose.fail");
44 String result = output.toString();
45 assertTrue("failure check", result.contains("ERROR"));
46 }
47
48 /**
49 * This is really a whole bunch of tests as we find test files in a
50 * directory and run each one in turn.
51 */
52 @Test
53 public void testAllRuleFiles() throws IOException {
54 File d = new File("test/resources/rules/");
55 assertTrue(d.isDirectory());
56
57 // Only run files ending in .test
58 FilenameFilter filter = (dir, name) -> {
59 if (name.endsWith(".test"))
60 return true;
61 return false;
62 };
63
64 int count = 0;
65 File[] files = d.listFiles(filter);
66 assert files != null;
67 for (File file : files) {
68 setup();
69 String name = file.getCanonicalPath();
70 try {
71 StyleTester.runSimpleTest(name);
72 } catch (Exception e) {
73 assertFalse(name, true);
74 }
75 String result = output.toString();
76
77 // Make sure that the result does not contain an error
78 if (result.contains("ERROR")) {
79 System.out.println(result);
80 assertFalse(name, true);
81 }
82
83 // make sure that the output was reasonable (and not 'cannot open
84 // file', for example).
85 assertTrue(name, result.contains("WAY 1:"));
86
87 count++;
88 }
89
90 // Check that some tests were run (ie. it will fail if you just delete
91 // them all).
92 assertTrue("tests run", count >= 3);
93 }
94
95 @Before
96 public void setup() {
97 output = new ByteArrayOutputStream();
98 PrintStream ps = new PrintStream(output);
99 StyleTester.setOut(ps);
100
101 // Make sure that there is a given result set
102 StyleTester.forceUseOfGiven();
103 }
104 }