| 38 | import junit.framework.TestCase; |
| 39 | |
| 40 | public class LibraryLoadTest extends TestCase implements Paths { |
| 41 | |
| 42 | private class TestLoader extends URLClassLoader { |
| 43 | public TestLoader(File path) throws MalformedURLException { |
| 44 | super(new URL[] { path.toURI().toURL(), }, |
| 45 | new CloverLoader()); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | public void testLoadJNALibrary() { |
| 50 | assertTrue("Pointer size should never be zero", Native.POINTER_SIZE > 0); |
| 51 | } |
| 52 | |
| 53 | public void testLoadJAWT() { |
| 54 | if (!Platform.HAS_AWT || !Platform.HAS_JAWT) return; |
| 55 | |
| 56 | if (GraphicsEnvironment.isHeadless()) return; |
| 57 | |
| 58 | // Encapsulate in a separate class to avoid class loading issues where |
| 59 | // AWT is unavailable |
| 60 | AWT.loadJAWT(getName()); |
| 61 | } |
| 62 | |
| 63 | public void testLoadAWTAfterJNA() { |
| 64 | if (!Platform.HAS_AWT) return; |
| 65 | |
| 66 | if (GraphicsEnvironment.isHeadless()) return; |
| 67 | |
| 68 | if (Native.POINTER_SIZE > 0) { |
| 69 | Toolkit.getDefaultToolkit(); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | public void testExtractFromResourcePath() throws Exception { |
| 74 | // doesn't actually load the resource |
| 75 | assertNotNull(Native.extractFromResourcePath("testlib-path", new TestLoader(new File(TESTPATH)))); |
| 76 | } |
| 77 | |
| 78 | public void testExtractFromResourcePathWithNullClassLoader() throws Exception { |
| 79 | // doesn't actually load the resource |
| 80 | assertNotNull(Native.extractFromResourcePath("/com/sun/jna/LibraryLoadTest.class", null)); |
| 81 | } |
| 82 | |
| 83 | public void testLoadFromJNALibraryPath() { |
| 84 | // Tests are already configured to load from this path |
| 85 | NativeLibrary.getInstance("testlib"); |
| 86 | } |
| 87 | |
| 88 | public void testLoadFromCustomPath() throws MalformedURLException { |
| 89 | NativeLibrary.addSearchPath("testlib-path", TESTPATH); |
| 90 | NativeLibrary.getInstance("testlib-path", new TestLoader(new File("."))); |
| 91 | } |
| 92 | |
| 93 | public void testLoadFromClasspath() throws MalformedURLException { |
| 94 | NativeLibrary.getInstance("testlib-path", new TestLoader(new File(TESTPATH))); |
| 95 | } |
| 96 | |
| 97 | public void testLoadFromClasspathAbsolute() throws MalformedURLException { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…