]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph.compiler/tests/org/simantics/graph/compiler/tests/GraphCompilerTests.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graph.compiler / tests / org / simantics / graph / compiler / tests / GraphCompilerTests.java
1 package org.simantics.graph.compiler.tests;\r
2 \r
3 import java.io.FileNotFoundException;\r
4 import java.io.IOException;\r
5 import java.util.ArrayList;\r
6 \r
7 import junit.framework.Assert;\r
8 \r
9 import org.junit.Before;\r
10 import org.junit.Test;\r
11 import org.simantics.graph.compiler.CompilationResult;\r
12 import org.simantics.graph.compiler.ExternalFileLoader;\r
13 import org.simantics.graph.compiler.GraphCompiler;\r
14 import org.simantics.graph.compiler.GraphCompilerPreferences;\r
15 import org.simantics.graph.representation.TransferableGraph1;\r
16 import org.simantics.ltk.ISource;\r
17 import org.simantics.ltk.LocalResourceSource;\r
18 \r
19 public class GraphCompilerTests {\r
20     \r
21     @Before\r
22     public void initialize() {\r
23         \r
24     }\r
25     \r
26     public CompilationResult compile(String source) throws Exception {\r
27         ArrayList<ISource> sources = new ArrayList<ISource>();\r
28         sources.add(new LocalResourceSource(GraphCompilerTests.class, source));\r
29         ArrayList<TransferableGraph1> dependencies = new ArrayList<TransferableGraph1>();\r
30         dependencies.add(GraphCompiler.read(GraphCompilerTests.class.getResourceAsStream("graph.tg")));\r
31         ExternalFileLoader fileLoader = new ExternalFileLoader() {                  \r
32             @Override\r
33             public byte[] load(String fileName) throws IOException {\r
34                 throw new FileNotFoundException();\r
35             }\r
36         };\r
37         GraphCompilerPreferences preferences = new GraphCompilerPreferences();\r
38         preferences.validate = true;\r
39         return GraphCompiler.compile(\r
40                 "1.0",\r
41                 sources, \r
42                 dependencies, \r
43                 fileLoader,\r
44                 preferences);\r
45     }\r
46     \r
47     @Test\r
48     public void testUndefinedVariable() throws Exception {\r
49         CompilationResult result = compile("graphs/UndefinedVariable.pgraph");\r
50         Assert.assertEquals(1, result.getErrors().size());\r
51     }\r
52     \r
53     @Test\r
54     public void testUndefinedConcept() throws Exception {\r
55         CompilationResult result = compile("graphs/UndefinedConcept.pgraph");\r
56         Assert.assertEquals(1, result.getErrors().size());\r
57     }\r
58     \r
59     @Test\r
60     public void testDomainAndRangeSyntax() throws Exception {\r
61         CompilationResult result = compile("graphs/DomainAndRangeSyntax.pgraph");\r
62         Assert.assertEquals(0, result.getErrors().size());\r
63     }\r
64     \r
65     @Test\r
66     public void testLists() throws Exception {\r
67         CompilationResult result = compile("graphs/Lists.pgraph");\r
68         Assert.assertEquals(0, result.getErrors().size());\r
69         Assert.assertEquals(3 /*InstanceOf*/ + 2 /*Element*/ + 3 /*Next*/, \r
70                 result.getGraph().statements.length/4);\r
71         result.getGraph().print();\r
72     }\r
73 }\r