示例#1
0
 public void testUseSingleLibraryInstance() {
   TestLibrary lib = (TestLibrary) Native.loadLibrary("testlib", TestLibrary.class);
   int count = lib.callCount();
   TestLibrary lib2 = (TestLibrary) Native.loadLibrary("testlib", TestLibrary.class);
   int count2 = lib2.callCount();
   assertEquals("Interfaces should share a library instance", count + 1, count2);
 }
示例#2
0
 public void testAliasLibraryFilename() {
   TestLibrary lib = (TestLibrary) Native.loadLibrary("testlib", TestLibrary.class);
   int count = lib.callCount();
   NativeLibrary nl = NativeLibrary.getInstance("testlib");
   TestLibrary lib2 = (TestLibrary) Native.loadLibrary(nl.getFile().getName(), TestLibrary.class);
   int count2 = lib2.callCount();
   assertEquals("Simple filename load not aliased", count + 1, count2);
 }
示例#3
0
  public void testAvoidDuplicateLoads() {
    NativeLibrary.disposeAll();

    TestLibrary lib = (TestLibrary) Native.loadLibrary("testlib", TestLibrary.class);
    assertEquals("Library should be newly loaded after all others disposed", 1, lib.callCount());
    if (lib.callCount() <= 1) {
      fail("Library should not be reloaded");
    }
  }
示例#4
0
 public void testAliasSimpleLibraryName() throws Exception {
   NativeLibrary nl = NativeLibrary.getInstance("testlib");
   File file = nl.getFile();
   WeakReference ref = new WeakReference(nl);
   nl = null;
   System.gc();
   long start = System.currentTimeMillis();
   while (ref.get() != null) {
     Thread.sleep(10);
     if (System.currentTimeMillis() - start > 5000)
       fail("Timed out waiting for library to be GC'd");
   }
   TestLibrary lib = (TestLibrary) Native.loadLibrary(file.getAbsolutePath(), TestLibrary.class);
   int count = lib.callCount();
   TestLibrary lib2 = (TestLibrary) Native.loadLibrary("testlib", TestLibrary.class);
   int count2 = lib2.callCount();
   assertEquals("Simple library name not aliased", count + 1, count2);
 }