3 import java.util.concurrent.Executors;
4 import java.util.concurrent.ScheduledExecutorService;
5 import java.util.concurrent.TimeUnit;
8 import vtk.vtkRenderWindow;
9 import vtk.vtkSettings;
10 import vtk.vtkTesting;
12 public class vtkJavaTesting {
13 public static final int FAILED = 0;
14 public static final int PASSED = 1;
15 public static final int NOT_RUN = 2;
16 public static final int DO_INTERACTOR = 3;
18 private static int LoadLib(String lib, boolean verbose) {
21 System.out.println("Try to load: " + lib);
23 Runtime.getRuntime().load(lib);
24 } catch (UnsatisfiedLinkError e) {
26 System.out.println("Failed to load: " + lib);
31 System.out.println("Successfully loaded: " + lib);
36 private static void LoadLibrary(String path, String library, boolean verbose) {
37 String lname = System.mapLibraryName(library);
38 String sep = System.getProperty("file.separator");
39 String libname = path + sep + lname;
40 String releaselibname = path + sep + "Release" + sep + lname;
41 String debuglibname = path + sep + "Debug" + sep + lname;
42 if (vtkJavaTesting.LoadLib(library, verbose) != 1 //
43 && vtkJavaTesting.LoadLib(libname, verbose) != 1
44 && vtkJavaTesting.LoadLib(releaselibname, verbose) != 1
45 && vtkJavaTesting.LoadLib(debuglibname, verbose) != 1) {
46 System.out.println("Problem loading apropriate library");
50 public static void Initialize(String[] args) {
51 vtkJavaTesting.Initialize(args, false);
54 public static void Initialize(String[] args, boolean verbose) {
55 String lpath = vtkSettings.GetVTKLibraryDir();
57 String path_separator = System.getProperty("path.separator");
58 String s = System.getProperty("java.library.path");
59 s = s + path_separator + lpath;
60 System.setProperty("java.library.path", s);
62 // String lname = System.mapLibraryName("vtkCommonJava");
63 String[] kits = vtkSettings.GetKits();
65 for (cc = 0; cc < kits.length; cc++) {
66 vtkJavaTesting.LoadLibrary(lpath, "vtk" + kits[cc] + "Java", verbose);
68 vtkJavaTesting.Tester = new vtk.vtkTesting();
69 for (cc = 0; cc < args.length; cc++) {
70 vtkJavaTesting.Tester.AddArgument(args[cc]);
74 public static boolean IsInteractive() {
75 if (vtkJavaTesting.Tester.IsInteractiveModeSpecified() == 0) {
81 public static void Exit(int retVal) {
82 vtkJavaTesting.Tester = null;
84 vtkObject.JAVA_OBJECT_MANAGER.gc(true);
86 if (retVal == vtkJavaTesting.FAILED || retVal == vtkJavaTesting.NOT_RUN) {
87 System.out.println("Test failed or was not run");
90 System.out.println("Test passed");
94 public static int RegressionTest(vtkRenderWindow renWin, int threshold) {
95 vtkJavaTesting.Tester.SetRenderWindow(renWin);
97 if (vtkJavaTesting.Tester.RegressionTest(threshold) == vtkJavaTesting.PASSED) {
98 return vtkJavaTesting.PASSED;
100 System.out.println("Image difference: " + vtkJavaTesting.Tester.GetImageDifference());
101 return vtkJavaTesting.FAILED;
104 public static void StartTimeoutExit(long time, TimeUnit unit) {
105 ScheduledExecutorService killerThread = Executors.newSingleThreadScheduledExecutor();
106 Runnable killer = new Runnable() {
111 killerThread.schedule(killer, time, unit);
114 public static vtkJavaGarbageCollector StartGCInEDT(long time, TimeUnit unit) {
115 vtkJavaGarbageCollector gc = vtkObject.JAVA_OBJECT_MANAGER.getAutoGarbageCollector();
116 gc.SetScheduleTime(time, unit);
117 gc.SetAutoGarbageCollection(true);
121 private static vtkTesting Tester = null;