]> gerrit.simantics Code Review - simantics/3d.git/blob - vtk/src/vtk/vtkJavaTesting.java
Mesh API to use Tuple3d instead of Vector3d
[simantics/3d.git] / vtk / src / vtk / vtkJavaTesting.java
1 package vtk;
2
3 import java.util.concurrent.Executors;
4 import java.util.concurrent.ScheduledExecutorService;
5 import java.util.concurrent.TimeUnit;
6
7 import vtk.vtkObject;
8 import vtk.vtkRenderWindow;
9 import vtk.vtkSettings;
10 import vtk.vtkTesting;
11
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;
17
18     private static int LoadLib(String lib, boolean verbose) {
19         try {
20             if (verbose) {
21                 System.out.println("Try to load: " + lib);
22             }
23             Runtime.getRuntime().load(lib);
24         } catch (UnsatisfiedLinkError e) {
25             if (verbose) {
26                 System.out.println("Failed to load: " + lib);
27             }
28             return 0;
29         }
30         if (verbose) {
31             System.out.println("Successfully loaded: " + lib);
32         }
33         return 1;
34     }
35
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");
47         }
48     }
49
50     public static void Initialize(String[] args) {
51         vtkJavaTesting.Initialize(args, false);
52     }
53
54     public static void Initialize(String[] args, boolean verbose) {
55         String lpath = vtkSettings.GetVTKLibraryDir();
56         if (lpath != null) {
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);
61         }
62         // String lname = System.mapLibraryName("vtkCommonJava");
63         String[] kits = vtkSettings.GetKits();
64         int cc;
65         for (cc = 0; cc < kits.length; cc++) {
66             vtkJavaTesting.LoadLibrary(lpath, "vtk" + kits[cc] + "Java", verbose);
67         }
68         vtkJavaTesting.Tester = new vtk.vtkTesting();
69         for (cc = 0; cc < args.length; cc++) {
70             vtkJavaTesting.Tester.AddArgument(args[cc]);
71         }
72     }
73
74     public static boolean IsInteractive() {
75         if (vtkJavaTesting.Tester.IsInteractiveModeSpecified() == 0) {
76             return false;
77         }
78         return true;
79     }
80
81     public static void Exit(int retVal) {
82         vtkJavaTesting.Tester = null;
83         System.gc();
84         vtkObject.JAVA_OBJECT_MANAGER.gc(true);
85
86         if (retVal == vtkJavaTesting.FAILED || retVal == vtkJavaTesting.NOT_RUN) {
87             System.out.println("Test failed or was not run");
88             System.exit(1);
89         }
90         System.out.println("Test passed");
91         System.exit(0);
92     }
93
94     public static int RegressionTest(vtkRenderWindow renWin, int threshold) {
95         vtkJavaTesting.Tester.SetRenderWindow(renWin);
96
97         if (vtkJavaTesting.Tester.RegressionTest(threshold) == vtkJavaTesting.PASSED) {
98             return vtkJavaTesting.PASSED;
99         }
100         System.out.println("Image difference: " + vtkJavaTesting.Tester.GetImageDifference());
101         return vtkJavaTesting.FAILED;
102     }
103
104     public static void StartTimeoutExit(long time, TimeUnit unit) {
105         ScheduledExecutorService killerThread = Executors.newSingleThreadScheduledExecutor();
106         Runnable killer = new Runnable() {
107             public void run() {
108                 System.exit(0);
109             }
110         };
111         killerThread.schedule(killer, time, unit);
112     }
113
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);
118         return gc;
119     }
120
121     private static vtkTesting Tester = null;
122 }