Skip to content

Commit

Permalink
Fix Library Load tests on Big Sur
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fkistner committed Nov 20, 2020
1 parent c155bac commit 16685bd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions test/com/sun/jna/LibraryLoadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -218,31 +217,36 @@ 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);
}
}
}

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";
Expand Down

0 comments on commit 16685bd

Please sign in to comment.