-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathTestEngine.java
More file actions
137 lines (108 loc) · 3.89 KB
/
Copy pathTestEngine.java
File metadata and controls
137 lines (108 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import app.f3d.F3D.*;
public class TestEngine {
// On Windows, try to load opengl32 from Java path
// It's only useful in order to force Mesa software OpenGL
static {
if (System.getProperty("os.name").startsWith("Windows"))
{
try {
System.loadLibrary("opengl32");
} catch (UnsatisfiedLinkError e) {
// Ignore if opengl32 is not available
}
}
}
public static void main(String[] args) {
Engine.autoloadPlugins();
Engine eng1 = Engine.create(true);
eng1.close();
Engine eng2 = Engine.create();
eng2.close();
Engine eng3 = Engine.createNone();
eng3.close();
Engine.loadPlugin("native");
Engine.getPluginsList(".");
Engine.getAllReaderOptionNames();
Engine.getLibInfo();
Engine.getReadersInfo();
Engine.getRenderingBackendList();
Engine engine = Engine.create(true);
engine.setCachePath("/tmp/f3d_test");
if (!engine.getCachePath().equals("/tmp/f3d_test")) {
throw new RuntimeException("getCachePath should return the path set with setCachePath");
}
engine.getOptions();
engine.getScene();
engine.getWindow();
engine.getInteractor();
engine.close();
// --- Exception handling tests ---
// Engine.createNone() has no interactor; calling getInteractor() must throw
// NoInteractorException and must NOT crash the JVM.
try (Engine noWinEngine = Engine.createNone()) {
noWinEngine.getInteractor();
throw new RuntimeException("Expected Engine.NoInteractorException was not thrown");
} catch (Engine.NoInteractorException e) {
}
// Loading a nonexistent plugin must throw PluginException.
try {
Engine.loadPlugin("__nonexistent_plugin_f3d_test__");
throw new RuntimeException("Expected Engine.PluginException was not thrown");
} catch (Engine.PluginException e) {
}
testStatefile(args);
}
// Set an option, add a file, save the state then restore it into a fresh engine and check both
// the option and the loaded scene are restored, through both the file and the string API
static void testStatefile(String[] args) {
String dataDir = args.length > 0 ? args[0] : "";
String tempDir = args.length > 1 ? args[1] : "";
String cow = dataDir + "data/cow.vtp";
String statefile = tempDir + "TestEngineJavaStatefile.json";
Engine src = Engine.createNone();
src.getOptions().setAsBool("ui.scalar_bar", true);
src.getScene().add(cow);
// File based round trip
try (Engine.State state = src.dump()) {
state.toFile(statefile);
}
Engine dst = Engine.createNone();
try (Engine.State state = Engine.State.fromFile(statefile)) {
dst.load(state);
}
if (!dst.getOptions().getAsBool("ui.scalar_bar")) {
throw new RuntimeException("options should be restored from the statefile");
}
if (dst.getScene().getAddedFiles().size() != 1) {
throw new RuntimeException("scene should be restored from the statefile");
}
dst.close();
// String based round trip
String content;
try (Engine.State state = src.dump()) {
content = state.toString();
}
Engine dstStr = Engine.createNone();
try (Engine.State state = Engine.State.fromString(content)) {
dstStr.load(state);
}
if (!dstStr.getOptions().getAsBool("ui.scalar_bar")) {
throw new RuntimeException("options should be restored from the statefile string");
}
if (dstStr.getScene().getAddedFiles().size() != 1) {
throw new RuntimeException("scene should be restored from the statefile string");
}
dstStr.close();
// Reading an invalid statefile should throw
boolean threw = false;
try {
Engine.State.fromFile("/does/not/exist/state.json");
} catch (RuntimeException e) {
threw = true;
}
if (!threw) {
throw new RuntimeException("State.fromFile should throw on a missing file");
}
src.close();
}
}