From 16685bdb749f2f3a00613cd2fa01723c68a3c289 Mon Sep 17 00:00:00 2001 From: Florian Kistner Date: Fri, 20 Nov 2020 09:24:16 +0100 Subject: [PATCH] Fix Library Load tests on Big Sur Big Sur uses a shared dylib cache to lookup system libraries and frameworks. Checking existence in the file system will fail, but loading them will succeed nevertheless. --- test/com/sun/jna/LibraryLoadTest.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/com/sun/jna/LibraryLoadTest.java b/test/com/sun/jna/LibraryLoadTest.java index d29007f91a..aa07a673a4 100644 --- a/test/com/sun/jna/LibraryLoadTest.java +++ b/test/com/sun/jna/LibraryLoadTest.java @@ -203,13 +203,12 @@ public void testLoadLibraryWithLongName() throws Exception { public void testLoadFrameworkLibrary() { if (Platform.isMac()) { final String PATH = "/System/Library/Frameworks/CoreServices.framework"; - assertTrue("CoreServices not present on this setup, expected at " + PATH, new File(PATH).exists()); try { NativeLibrary lib = NativeLibrary.getInstance("CoreServices"); assertNotNull("CoreServices not found", lib); } catch(UnsatisfiedLinkError e) { - fail("Should search /System/Library/Frameworks"); + failCoreServices("Should search /System/Library/Frameworks: ", e, PATH); } } } @@ -218,13 +217,12 @@ public void testLoadFrameworkLibraryAbsolute() { if (Platform.isMac()) { final String PATH = "/System/Library/Frameworks/CoreServices"; final String FRAMEWORK = PATH + ".framework"; - assertTrue("CoreServices not present on this setup, expected at " + FRAMEWORK, new File(FRAMEWORK).exists()); try { NativeLibrary lib = NativeLibrary.getInstance(PATH); assertNotNull("CoreServices not found", lib); } catch(UnsatisfiedLinkError e) { - fail("Should try FRAMEWORK.framework/FRAMEWORK if the absolute framework (truncated) path given exists: " + e); + failCoreServices("Should try FRAMEWORK.framework/FRAMEWORK if the absolute framework (truncated) path given exists: ", e, FRAMEWORK); } } } @@ -232,17 +230,23 @@ public void testLoadFrameworkLibraryAbsolute() { public void testLoadFrameworkLibraryAbsoluteFull() { if (Platform.isMac()) { final String PATH = "/System/Library/Frameworks/CoreServices.framework/CoreServices"; - assertTrue("CoreServices not present on this setup, expected at " + PATH, new File(PATH).exists()); try { NativeLibrary lib = NativeLibrary.getInstance(PATH); assertNotNull("CoreServices not found", lib); } catch(UnsatisfiedLinkError e) { - fail("Should try FRAMEWORK verbatim if the absolute path given exists: " + e); + failCoreServices("Should try FRAMEWORK verbatim if the absolute path given exists: ", e, PATH); } } } + private void failCoreServices(String message, UnsatisfiedLinkError e, String expectedPath) { + if (!new File(expectedPath).exists()) { + message = "CoreServices not present on this setup, expected at " + expectedPath + "\n" + message; + } + fail(message + e); + } + public void testHandleObjectMethods() { CLibrary lib = (CLibrary)load(); String method = "toString";