Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 490118
Collapse All | Expand All

(-)a/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotExportTests.java (-20 / +5 lines)
Lines 1-12 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2015 Fabian Steeg and others.
2
 * Copyright (c) 2009, 2016 itemis AG and others.
3
 *
3
 * All rights reserved. This program and the accompanying materials
4
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 *
8
 * Contributors:
9
 * Contributors:
9
 *     Fabian Steeg - initial API and implementation (see bug #277380)
10
 *     Fabian Steeg    - initial API and implementation (see bug #277380)
11
 *     Tamas Miklossy  - use platform specific line separators
10
 *******************************************************************************/
12
 *******************************************************************************/
11
package org.eclipse.gef4.dot.tests;
13
package org.eclipse.gef4.dot.tests;
12
14
Lines 15-21 Link Here
15
import static org.junit.Assert.assertTrue;
17
import static org.junit.Assert.assertTrue;
16
18
17
import java.io.File;
19
import java.io.File;
18
import java.io.FileNotFoundException;
19
import java.util.Scanner;
20
import java.util.Scanner;
20
21
21
import org.eclipse.gef4.dot.internal.DotAttributes;
22
import org.eclipse.gef4.dot.internal.DotAttributes;
Lines 63-69 Link Here
63
				"Generated file " + new File(OUTPUT, fileName).getName() //$NON-NLS-1$
64
				"Generated file " + new File(OUTPUT, fileName).getName() //$NON-NLS-1$
64
						+ " must exist!",
65
						+ " must exist!",
65
				new File(OUTPUT, fileName).exists());
66
				new File(OUTPUT, fileName).exists());
66
		String dotRead = read(new File(OUTPUT, fileName));
67
		String dotRead = DotFileUtils.read(new File(OUTPUT, fileName));
67
		Assert.assertEquals("File output and String output should be equal;", //$NON-NLS-1$
68
		Assert.assertEquals("File output and String output should be equal;", //$NON-NLS-1$
68
				dot, dotRead);
69
				dot, dotRead);
69
	}
70
	}
Lines 121-140 Link Here
121
		}
122
		}
122
		scanner.close();
123
		scanner.close();
123
	}
124
	}
124
125
	private String read(final File file) {
126
		try {
127
			Scanner scanner = new Scanner(file);
128
			StringBuilder builder = new StringBuilder();
129
			while (scanner.hasNextLine()) {
130
				builder.append(scanner.nextLine() + "\n"); //$NON-NLS-1$
131
			}
132
			scanner.close();
133
			return builder.toString();
134
		} catch (FileNotFoundException e) {
135
			e.printStackTrace();
136
		}
137
		return null;
138
	}
139
140
}
125
}
(-)a/org.eclipse.gef4.dot.tests/src/org/eclipse/gef4/dot/tests/DotParserTests.java (-18 / +5 lines)
Lines 16-24 Link Here
16
import static org.junit.Assert.fail;
16
import static org.junit.Assert.fail;
17
17
18
import java.io.File;
18
import java.io.File;
19
import java.io.FileNotFoundException;
20
import java.util.Scanner;
21
19
20
import org.eclipse.gef4.dot.internal.DotFileUtils;
22
import org.eclipse.gef4.dot.internal.parser.DotInjectorProvider;
21
import org.eclipse.gef4.dot.internal.parser.DotInjectorProvider;
23
import org.eclipse.gef4.dot.internal.parser.dot.DotAst;
22
import org.eclipse.gef4.dot.internal.parser.dot.DotAst;
24
import org.eclipse.xtext.junit4.InjectWith;
23
import org.eclipse.xtext.junit4.InjectWith;
Lines 55-76 Link Here
55
		testFile("arrowshapes_deprecated.dot");
54
		testFile("arrowshapes_deprecated.dot");
56
	}
55
	}
57
56
58
	private void testFile(String path) {
57
	private void testFile(String fileName) {
59
		String newline = System.getProperty("line.separator");
58
		String fileContents = DotFileUtils
60
		String content = "";
59
				.read(new File(DotTestUtils.RESOURCES_TESTS + fileName));
61
		try {
60
		try {
62
			Scanner scanner = new Scanner(
61
			DotAst dotAst = parserHelper.parse(fileContents);
63
					new File(DotTestUtils.RESOURCES_TESTS + path));
64
			while (scanner.hasNextLine()) {
65
				content += scanner.nextLine() + newline;
66
			}
67
			scanner.close();
68
		} catch (FileNotFoundException e) {
69
			e.printStackTrace();
70
		}
71
72
		try {
73
			DotAst dotAst = parserHelper.parse(content);
74
			assertNotNull(dotAst);
62
			assertNotNull(dotAst);
75
			validationTestHelper.assertNoErrors(dotAst);
63
			validationTestHelper.assertNoErrors(dotAst);
76
		} catch (Exception e) {
64
		} catch (Exception e) {
Lines 78-82 Link Here
78
			fail();
66
			fail();
79
		}
67
		}
80
	}
68
	}
81
82
}
69
}
(-)a/org.eclipse.gef4.dot/src/org/eclipse/gef4/dot/internal/DotFileUtils.java (-6 / +11 lines)
Lines 1-10 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2015 Fabian Steeg. All rights reserved. This program and
2
 * Copyright (c) 2009, 2016 itemis AG and others.
3
 * the accompanying materials are made available under the terms of the Eclipse
3
 *
4
 * Public License v1.0 which accompanies this distribution, and is available at
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
5
 * http://www.eclipse.org/legal/epl-v10.html
7
 * http://www.eclipse.org/legal/epl-v10.html
6
 * <p/>
8
 *
7
 * Contributors: Fabian Steeg - initial API and implementation; see bug 277380
9
 * Contributors:
10
 *     Fabian Steeg    - initial API and implementation; see bug 277380
11
 *     Tamas Miklossy  - use platform specific line separators
8
 *******************************************************************************/
12
 *******************************************************************************/
9
13
10
package org.eclipse.gef4.dot.internal;
14
package org.eclipse.gef4.dot.internal;
Lines 94-104 Link Here
94
	 * @return The string containing the contents of the given file
98
	 * @return The string containing the contents of the given file
95
	 */
99
	 */
96
	public static String read(final File file) {
100
	public static String read(final File file) {
101
		String lineSeparator = System.lineSeparator();
97
		StringBuilder builder = new StringBuilder();
102
		StringBuilder builder = new StringBuilder();
98
		try {
103
		try {
99
			Scanner s = new Scanner(file);
104
			Scanner s = new Scanner(file);
100
			while (s.hasNextLine()) {
105
			while (s.hasNextLine()) {
101
				builder.append(s.nextLine()).append("\n"); //$NON-NLS-1$
106
				builder.append(s.nextLine()).append(lineSeparator);
102
			}
107
			}
103
			s.close();
108
			s.close();
104
		} catch (FileNotFoundException e) {
109
		} catch (FileNotFoundException e) {

Return to bug 490118