File: vtkJavaTesting.java

package info (click to toggle)
vtk7 7.1.1%2Bdfsg2-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 127,396 kB
  • sloc: cpp: 1,539,584; ansic: 124,382; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 126; objc: 83
file content (132 lines) | stat: -rw-r--r-- 4,146 bytes parent folder | download | duplicates (8)
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
package vtk;

import java.io.File;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import vtk.vtkObject;
import vtk.vtkRenderWindow;
import vtk.vtkSettings;
import vtk.vtkTesting;

public class vtkJavaTesting {
  public static final int FAILED = 0;
  public static final int PASSED = 1;
  public static final int NOT_RUN = 2;
  public static final int DO_INTERACTOR = 3;

  private static int LoadLib(String lib, boolean verbose) {
    try {
      if (verbose) {
        System.out.println("Try to load: " + lib);
      }

      if(!new File(lib).exists()) {
        if(verbose) {
          System.out.println("File does not exist: " + lib);
          return 0;
        }
      }

      Runtime.getRuntime().load(lib);
    } catch (UnsatisfiedLinkError e) {
      if (verbose) {
        System.out.println("Failed to load: " + lib);
        e.printStackTrace();
      }
      return 0;
    }
    if (verbose) {
      System.out.println("Successfully loaded: " + lib);
    }
    return 1;
  }

  private static void LoadLibrary(String path, String library, boolean verbose) {
    String lname = System.mapLibraryName(library);
    String sep = System.getProperty("file.separator");
    String libname = path + sep + lname;
    String releaselibname = path + sep + "Release" + sep + lname;
    String debuglibname = path + sep + "Debug" + sep + lname;
    if (vtkJavaTesting.LoadLib(library, verbose) != 1 //
        && vtkJavaTesting.LoadLib(libname, verbose) != 1
        && vtkJavaTesting.LoadLib(releaselibname, verbose) != 1
        && vtkJavaTesting.LoadLib(debuglibname, verbose) != 1) {
      System.out.println("Problem loading appropriate library");
    }
  }

  public static void Initialize(String[] args) {
    vtkJavaTesting.Initialize(args, false);
  }

  public static void Initialize(String[] args, boolean verbose) {
    String lpath = vtkSettings.GetVTKLibraryDir();
    if (lpath != null) {
      String path_separator = System.getProperty("path.separator");
      String s = System.getProperty("java.library.path");
      s = s + path_separator + lpath;
      System.setProperty("java.library.path", s);
    }
    // String lname = System.mapLibraryName("vtkCommonJava");
    String[] kits = vtkSettings.GetKits();
    int cc;
    for (cc = 0; cc < kits.length; cc++) {
      vtkJavaTesting.LoadLibrary(lpath, "vtk" + kits[cc] + "Java", verbose);
    }
    vtkJavaTesting.Tester = new vtk.vtkTesting();
    for (cc = 0; cc < args.length; cc++) {
      vtkJavaTesting.Tester.AddArgument(args[cc]);
    }
  }

  public static boolean IsInteractive() {
    if (vtkJavaTesting.Tester.IsInteractiveModeSpecified() == 0) {
      return false;
    }
    return true;
  }

  public static void Exit(int retVal) {
    vtkJavaTesting.Tester = null;
    System.gc();
    vtkObjectBase.JAVA_OBJECT_MANAGER.gc(true);

    if (retVal == vtkJavaTesting.FAILED || retVal == vtkJavaTesting.NOT_RUN) {
      System.out.println("Test failed or was not run");
      System.exit(1);
    }
    System.out.println("Test passed");
    System.exit(0);
  }

  public static int RegressionTest(vtkRenderWindow renWin, int threshold) {
    vtkJavaTesting.Tester.SetRenderWindow(renWin);

    if (vtkJavaTesting.Tester.RegressionTest(threshold) == vtkJavaTesting.PASSED) {
      return vtkJavaTesting.PASSED;
    }
    System.out.println("Image difference: " + vtkJavaTesting.Tester.GetImageDifference());
    return vtkJavaTesting.FAILED;
  }

  public static void StartTimeoutExit(long time, TimeUnit unit) {
    ScheduledExecutorService killerThread = Executors.newSingleThreadScheduledExecutor();
    Runnable killer = new Runnable() {
      public void run() {
        System.exit(0);
      }
    };
    killerThread.schedule(killer, time, unit);
  }

  public static vtkJavaGarbageCollector StartGCInEDT(long time, TimeUnit unit) {
    vtkJavaGarbageCollector gc = vtkObjectBase.JAVA_OBJECT_MANAGER.getAutoGarbageCollector();
    gc.SetScheduleTime(time, unit);
    gc.SetAutoGarbageCollection(true);
    return gc;
  }

  private static vtkTesting Tester = null;
}