Skip to content

Commit f499073

Browse files
author
jdf
committed
Found a better way to load prefs in UTs
1 parent f590997 commit f499073

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

app/ParserTests.launch

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
1717
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="test.processing.parsing.ParserTests"/>
1818
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="processing-app"/>
19-
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="C:\Documents and Settings\Administrator\Desktop\processing\svn\processing\build\windows\work"/>
2019
</launchConfiguration>

app/src/processing/app/Preferences.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ protected void showFrame(Editor editor) {
592592
// .................................................................
593593

594594

595-
static protected void load(InputStream input) throws IOException {
595+
static public void load(InputStream input) throws IOException {
596596
String[] lines = PApplet.loadStrings(input); // Reads as UTF-8
597597
for (String line : lines) {
598598
if ((line.length() == 0) ||

app/test/resources/preferences.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# unit test prefs
2+
3+
preproc.save_build_files=false
4+
5+
# preprocessor: pde.g
6+
preproc.color_datatype = true
7+
preproc.web_colors = true
8+
preproc.enhanced_casting = true
9+
10+
# preprocessor: PdeEmitter.java
11+
preproc.substitute_floats = true
12+
#preproc.substitute_image = false
13+
#preproc.substitute_font = false
14+
15+
# auto-convert non-ascii chars to unicode escape sequences
16+
preproc.substitute_unicode = true
17+
18+
# PdePreproc.java
19+
# writes out the parse tree as parseTree.xml, which can be usefully
20+
# viewed in (at least) Mozilla or IE. useful when debugging the preprocessor.
21+
preproc.output_parse_tree = false
22+
23+
# Changed after 1.0.9 to a new name, and also includes the specific entries
24+
preproc.imports.list = java.applet.*,java.awt.Dimension,java.awt.Frame,java.awt.event.MouseEvent,java.awt.event.KeyEvent,java.awt.event.FocusEvent,java.awt.Image,java.io.*,java.net.*,java.text.*,java.util.*,java.util.zip.*,java.util.regex.*

app/test/src/test/processing/parsing/ParserTests.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static org.junit.Assert.fail;
44
import java.io.File;
55
import java.io.FileInputStream;
6+
import java.io.FileNotFoundException;
7+
import java.io.IOException;
68
import java.io.InputStreamReader;
79
import java.io.StringWriter;
810
import org.junit.BeforeClass;
@@ -15,16 +17,21 @@
1517

1618
public class ParserTests {
1719

20+
private static final String RESOURCES = "test/resources/";
21+
22+
private static File res(final String resourceName)
23+
{
24+
return new File(RESOURCES,resourceName);
25+
}
26+
1827
@BeforeClass
19-
static public void initPrefs() {
20-
System.err.println("Initializing prefs");
21-
Base.initPlatform();
22-
Preferences.init(null);
28+
static public void initPrefs() throws Exception {
29+
Preferences.load(new FileInputStream(res("preferences.txt")));
2330
}
2431

25-
static String read(final String path) {
32+
static String read(final File f) {
2633
try {
27-
final FileInputStream fin = new FileInputStream(path);
34+
final FileInputStream fin = new FileInputStream(f);
2835
final InputStreamReader in = new InputStreamReader(fin, "UTF-8");
2936
try {
3037
final StringBuilder sb = new StringBuilder();
@@ -43,7 +50,7 @@ static String read(final String path) {
4350

4451
static String preprocess(final String resource) throws RunnerException,
4552
ANTLRException {
46-
final String program = read("../../../app/test/resources/" + resource);
53+
final String program = read(res(resource));
4754
final StringWriter out = new StringWriter();
4855
new PdePreprocessor(resource, 4).write(out, program);
4956
return out.toString();

0 commit comments

Comments
 (0)