Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion saferalloc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def arch = System.getProperty('os.arch', '').toLowerCase()

def nativesProject
def nativeExt
if (osName.contains('win')) {
if (osName.startsWith('win')) {
if (arch == 'aarch64' || arch == 'arm64') {
nativesProject = project(':saferalloc-natives-windows-aarch64')
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private static String detectOs() {
return "android";
}
String n = System.getProperty("os.name", "").toLowerCase(Locale.ROOT);
if (n.contains("win")) return "windows";
if (n.startsWith("win")) return "windows";
if (n.contains("mac") || n.contains("darwin")) return "macos";
return "linux";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.ngengine.saferalloc;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.lang.reflect.Method;
import org.junit.jupiter.api.Test;

class NativeLibraryLoaderTest {
@Test
void detectsDesktopOperatingSystems() throws Exception {
String originalOs = System.getProperty("os.name");
String originalRuntime = System.getProperty("java.runtime.name");
String originalVm = System.getProperty("java.vm.name");
try {
System.setProperty("java.runtime.name", "OpenJDK Runtime Environment");
System.setProperty("java.vm.name", "OpenJDK 64-Bit Server VM");
Method detectOs = NativeLibraryLoader.class.getDeclaredMethod("detectOs");
detectOs.setAccessible(true);
String[][] cases = {
{"Linux", "linux"},
{"Windows 11", "windows"},
{"Mac OS X", "macos"},
{"Darwin", "macos"}
};
for (String[] testCase : cases) {
System.setProperty("os.name", testCase[0]);
assertEquals(testCase[1], detectOs.invoke(null), testCase[0]);
}
} finally {
restoreProperty("os.name", originalOs);
restoreProperty("java.runtime.name", originalRuntime);
restoreProperty("java.vm.name", originalVm);
}
}

private static void restoreProperty(String name, String value) {
if (value == null) {
System.clearProperty(name);
} else {
System.setProperty(name, value);
}
}
}
Loading