remove XXX HACK from native library loader
also add additional integration tests for AppSettings, Application, and NativeLibraryLoader
This commit is contained in:
parent
f986043745
commit
908b37350d
@ -29,22 +29,7 @@
|
|||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
package com.jme3;
|
||||||
|
|
||||||
import com.jme3.system.NativeLibraryLoader;
|
public interface IntegrationTest {
|
||||||
import java.io.File;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Kirill Vainer
|
|
||||||
*/
|
|
||||||
public class LibraryLoaderTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whatever() {
|
|
||||||
File[] nativeJars = NativeLibraryLoader.getJarsWithNatives();
|
|
||||||
System.out.println(Arrays.toString(nativeJars));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
60
jme3-core/src/test/java/com/jme3/app/AppSettingsIT.java
Normal file
60
jme3-core/src/test/java/com/jme3/app/AppSettingsIT.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package com.jme3.app;
|
||||||
|
|
||||||
|
import com.jme3.IntegrationTest;
|
||||||
|
import com.jme3.scene.Mesh;
|
||||||
|
import com.jme3.system.AppSettings;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.prefs.BackingStoreException;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
@Category(IntegrationTest.class)
|
||||||
|
public class AppSettingsIT {
|
||||||
|
|
||||||
|
private static final String APPSETTINGS_KEY = "JME_AppSettingsTest";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPreferencesSaveLoad() throws BackingStoreException {
|
||||||
|
AppSettings settings = new AppSettings(false);
|
||||||
|
settings.putBoolean("TestBool", true);
|
||||||
|
settings.putInteger("TestInt", 123);
|
||||||
|
settings.putString("TestStr", "HelloWorld");
|
||||||
|
settings.putFloat("TestFloat", 123.567f);
|
||||||
|
settings.put("TestObj", new Mesh()); // Objects not supported by preferences
|
||||||
|
settings.save(APPSETTINGS_KEY);
|
||||||
|
|
||||||
|
AppSettings loadedSettings = new AppSettings(false);
|
||||||
|
loadedSettings.load(APPSETTINGS_KEY);
|
||||||
|
|
||||||
|
assertEquals(true, loadedSettings.getBoolean("TestBool"));
|
||||||
|
assertEquals(123, loadedSettings.getInteger("TestInt"));
|
||||||
|
assertEquals("HelloWorld", loadedSettings.getString("TestStr"));
|
||||||
|
assertEquals(123.567f, loadedSettings.get("TestFloat"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStreamSaveLoad() throws IOException {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
AppSettings settings = new AppSettings(false);
|
||||||
|
settings.putBoolean("TestBool", true);
|
||||||
|
settings.putInteger("TestInt", 123);
|
||||||
|
settings.putString("TestStr", "HelloWorld");
|
||||||
|
settings.putFloat("TestFloat", 123.567f);
|
||||||
|
settings.put("TestObj", new Mesh()); // Objects not supported by file settings
|
||||||
|
settings.save(baos);
|
||||||
|
|
||||||
|
AppSettings loadedSettings = new AppSettings(false);
|
||||||
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
|
loadedSettings.load(bais);
|
||||||
|
|
||||||
|
assertEquals(true, loadedSettings.getBoolean("TestBool"));
|
||||||
|
assertEquals(123, loadedSettings.getInteger("TestInt"));
|
||||||
|
assertEquals("HelloWorld", loadedSettings.getString("TestStr"));
|
||||||
|
assertEquals(123.567f, loadedSettings.get("TestFloat"));
|
||||||
|
}
|
||||||
|
}
|
83
jme3-core/src/test/java/com/jme3/app/ApplicationTest.java
Normal file
83
jme3-core/src/test/java/com/jme3/app/ApplicationTest.java
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2015 jMonkeyEngine
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package com.jme3.app;
|
||||||
|
|
||||||
|
import com.jme3.system.AppSettings;
|
||||||
|
import com.jme3.system.JmeContext.Type;
|
||||||
|
import com.jme3.system.JmeSystem;
|
||||||
|
import com.jme3.system.JmeSystemDelegate;
|
||||||
|
import com.jme3.system.NullContext;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class ApplicationTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
Logger.getLogger("com.jme3").setLevel(Level.OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class NullDisplayContext extends NullContext {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type getType() {
|
||||||
|
return Type.Display;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExceptionInvokesHandleError() throws InterruptedException {
|
||||||
|
JmeSystemDelegate del = mock(JmeSystemDelegate.class);
|
||||||
|
JmeSystem.setSystemDelegate(del);
|
||||||
|
|
||||||
|
Application app = new Application() {
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
super.update();
|
||||||
|
throw new IllegalStateException("Some Error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
when(del.newContext((AppSettings) anyObject(), eq(Type.Display))).thenReturn(new NullDisplayContext());
|
||||||
|
|
||||||
|
app.start(true);
|
||||||
|
app.stop(true);
|
||||||
|
|
||||||
|
verify(del).showErrorDialog(anyString());
|
||||||
|
}
|
||||||
|
}
|
@ -4,4 +4,5 @@ if (!hasProperty('mainClass')) {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':jme3-core')
|
compile project(':jme3-core')
|
||||||
|
testCompile project(path: ':jme3-core', configuration: 'testOutput')
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ import java.io.*;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.nio.channels.FileLock;
|
||||||
|
import java.nio.channels.OverlappingFileLockException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -44,9 +46,9 @@ import java.util.logging.Logger;
|
|||||||
/**
|
/**
|
||||||
* Utility class to register, extract, and load native libraries.
|
* Utility class to register, extract, and load native libraries.
|
||||||
* <br>
|
* <br>
|
||||||
* Register your own libraries via the {@link #registerNativeLibrary(String, Platform, String, String)} method, for
|
* Register your own libraries via the
|
||||||
* each platform.
|
* {@link #registerNativeLibrary(String, Platform, String, String)} method, for
|
||||||
* You can then extract this library (depending on platform), by
|
* each platform. You can then extract this library (depending on platform), by
|
||||||
* using {@link #loadNativeLibrary(java.lang.String, boolean) }.
|
* using {@link #loadNativeLibrary(java.lang.String, boolean) }.
|
||||||
* <br>
|
* <br>
|
||||||
* Example:<br>
|
* Example:<br>
|
||||||
@ -62,8 +64,8 @@ import java.util.logging.Logger;
|
|||||||
* This will register the library. Load it via: <br>
|
* This will register the library. Load it via: <br>
|
||||||
* <code><pre>
|
* <code><pre>
|
||||||
* NativeLibraryLoader.loadNativeLibrary("mystuff", true);
|
* NativeLibraryLoader.loadNativeLibrary("mystuff", true);
|
||||||
* </pre></code>
|
* </pre></code> It will load the right library automatically based on the
|
||||||
* It will load the right library automatically based on the platform.
|
* platform.
|
||||||
*
|
*
|
||||||
* @author Kirill Vainer
|
* @author Kirill Vainer
|
||||||
*/
|
*/
|
||||||
@ -81,16 +83,17 @@ public final class NativeLibraryLoader {
|
|||||||
* Register a new known library.
|
* Register a new known library.
|
||||||
*
|
*
|
||||||
* This simply registers a known library, the actual extraction and loading
|
* This simply registers a known library, the actual extraction and loading
|
||||||
* is performed by calling {@link #loadNativeLibrary(java.lang.String, boolean) }.
|
* is performed by calling {@link #loadNativeLibrary(java.lang.String, boolean)
|
||||||
|
* }.
|
||||||
*
|
*
|
||||||
* @param name The name / ID of the library (not OS or architecture specific).
|
* @param name The name / ID of the library (not OS or architecture
|
||||||
* @param platform The platform for which the in-natives-jar path has
|
* specific).
|
||||||
* been specified for.
|
* @param platform The platform for which the in-natives-jar path has been
|
||||||
* @param path The path inside the natives-jar or classpath
|
* specified for.
|
||||||
* corresponding to this library. Must be compatible with the platform
|
* @param path The path inside the natives-jar or classpath corresponding to
|
||||||
* argument.
|
* this library. Must be compatible with the platform argument.
|
||||||
* @param extractAsName The filename that the library should be extracted as,
|
* @param extractAsName The filename that the library should be extracted
|
||||||
* if null, use the same name as in the path.
|
* as, if null, use the same name as in the path.
|
||||||
*/
|
*/
|
||||||
public static void registerNativeLibrary(String name, Platform platform,
|
public static void registerNativeLibrary(String name, Platform platform,
|
||||||
String path, String extractAsName) {
|
String path, String extractAsName) {
|
||||||
@ -102,17 +105,18 @@ public final class NativeLibraryLoader {
|
|||||||
* Register a new known JNI library.
|
* Register a new known JNI library.
|
||||||
*
|
*
|
||||||
* This simply registers a known library, the actual extraction and loading
|
* This simply registers a known library, the actual extraction and loading
|
||||||
* is performed by calling {@link #loadNativeLibrary(java.lang.String, boolean) }.
|
* is performed by calling {@link #loadNativeLibrary(java.lang.String, boolean)
|
||||||
|
* }.
|
||||||
*
|
*
|
||||||
* This method should be called several times for each library name,
|
* This method should be called several times for each library name, each
|
||||||
* each time specifying a different platform + path combination.
|
* time specifying a different platform + path combination.
|
||||||
*
|
*
|
||||||
* @param name The name / ID of the library (not OS or architecture specific).
|
* @param name The name / ID of the library (not OS or architecture
|
||||||
* @param platform The platform for which the in-natives-jar path has
|
* specific).
|
||||||
* been specified for.
|
* @param platform The platform for which the in-natives-jar path has been
|
||||||
* @param path The path inside the natives-jar or classpath
|
* specified for.
|
||||||
* corresponding to this library. Must be compatible with the platform
|
* @param path The path inside the natives-jar or classpath corresponding to
|
||||||
* argument.
|
* this library. Must be compatible with the platform argument.
|
||||||
*/
|
*/
|
||||||
public static void registerNativeLibrary(String name, Platform platform,
|
public static void registerNativeLibrary(String name, Platform platform,
|
||||||
String path) {
|
String path) {
|
||||||
@ -202,9 +206,9 @@ public final class NativeLibraryLoader {
|
|||||||
/**
|
/**
|
||||||
* Determine if native bullet is on the classpath.
|
* Determine if native bullet is on the classpath.
|
||||||
*
|
*
|
||||||
* Currently the context extracts the native bullet libraries, so
|
* Currently the context extracts the native bullet libraries, so this
|
||||||
* this method is needed to determine if it is needed.
|
* method is needed to determine if it is needed. Ideally, native bullet
|
||||||
* Ideally, native bullet should be responsible for its own natives.
|
* should be responsible for its own natives.
|
||||||
*
|
*
|
||||||
* @return True native bullet is on the classpath, false otherwise.
|
* @return True native bullet is on the classpath, false otherwise.
|
||||||
*/
|
*/
|
||||||
@ -218,32 +222,34 @@ public final class NativeLibraryLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify a custom location where native libraries should
|
* Specify a custom location where native libraries should be extracted to.
|
||||||
* be extracted to. Ensure this is a unique path not used
|
* Ensure this is a unique path not used by other applications to extract
|
||||||
* by other applications to extract their libraries.
|
* their libraries. Set to <code>null</code> to restore default
|
||||||
* Set to <code>null</code> to restore default
|
|
||||||
* functionality.
|
* functionality.
|
||||||
*
|
*
|
||||||
* @param path Path where to extract native libraries.
|
* @param path Path where to extract native libraries.
|
||||||
*/
|
*/
|
||||||
public static void setCustomExtractionFolder(String path) {
|
public static void setCustomExtractionFolder(String path) {
|
||||||
|
if (path != null) {
|
||||||
extractionFolderOverride = new File(path).getAbsoluteFile();
|
extractionFolderOverride = new File(path).getAbsoluteFile();
|
||||||
|
} else {
|
||||||
|
extractionFolderOverride = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the folder where native libraries will be extracted.
|
* Returns the folder where native libraries will be extracted. This is
|
||||||
* This is automatically determined at run-time based on the
|
* automatically determined at run-time based on the following criteria:<br>
|
||||||
* following criteria:<br>
|
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>If a {@link #setCustomExtractionFolder(java.lang.String) custom
|
* <li>If a {@link #setCustomExtractionFolder(java.lang.String) custom
|
||||||
* extraction folder} has been specified, it is returned.
|
* extraction folder} has been specified, it is returned.
|
||||||
* <li>If the user can write to the working folder, then it
|
* <li>If the user can write to the working folder, then it is
|
||||||
* is returned.</li>
|
* returned.</li>
|
||||||
* <li>Otherwise, the {@link JmeSystem#getStorageFolder() storage folder}
|
* <li>Otherwise, the {@link JmeSystem#getStorageFolder() storage folder} is
|
||||||
* is used, to prevent collisions, a special subfolder is used
|
* used, to prevent collisions, a special subfolder is used called
|
||||||
* called <code>natives_<hash></code> where <hash>
|
* <code>natives_<hash></code> where <hash> is computed
|
||||||
* is computed automatically as the XOR of the classpath hash code
|
* automatically as the XOR of the classpath hash code and the last modified
|
||||||
* and the last modified date of this class.
|
* date of this class.
|
||||||
*
|
*
|
||||||
* @return Path where natives will be extracted to.
|
* @return Path where natives will be extracted to.
|
||||||
*/
|
*/
|
||||||
@ -272,9 +278,9 @@ public final class NativeLibraryLoader {
|
|||||||
/**
|
/**
|
||||||
* Determine jME3's cache folder for the user account based on the OS.
|
* Determine jME3's cache folder for the user account based on the OS.
|
||||||
*
|
*
|
||||||
* If the OS cache folder is missing, the assumption is that this
|
* If the OS cache folder is missing, the assumption is that this particular
|
||||||
* particular version of the OS does not have a dedicated cache folder,
|
* version of the OS does not have a dedicated cache folder, hence, we use
|
||||||
* hence, we use the user's home folder instead as the root.
|
* the user's home folder instead as the root.
|
||||||
*
|
*
|
||||||
* The folder returned is as follows:<br>
|
* The folder returned is as follows:<br>
|
||||||
* <ul>
|
* <ul>
|
||||||
@ -360,7 +366,8 @@ public final class NativeLibraryLoader {
|
|||||||
try {
|
try {
|
||||||
conn.getInputStream().close();
|
conn.getInputStream().close();
|
||||||
conn.getOutputStream().close();
|
conn.getOutputStream().close();
|
||||||
} catch (IOException ex) { }
|
} catch (IOException ex) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -401,8 +408,8 @@ public final class NativeLibraryLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes platform-specific portions of a library file name so
|
* Removes platform-specific portions of a library file name so that it can
|
||||||
* that it can be accepted by {@link System#loadLibrary(java.lang.String) }.
|
* be accepted by {@link System#loadLibrary(java.lang.String) }.
|
||||||
* <p>
|
* <p>
|
||||||
* E.g.<br>
|
* E.g.<br>
|
||||||
* <ul>
|
* <ul>
|
||||||
@ -528,10 +535,24 @@ public final class NativeLibraryLoader {
|
|||||||
* First extracts the native library and then loads it.
|
* First extracts the native library and then loads it.
|
||||||
*
|
*
|
||||||
* @param name The name of the library to load.
|
* @param name The name of the library to load.
|
||||||
* @param isRequired If true and the library fails to load, throw exception. If
|
* @param isRequired If true and the library fails to load, throw exception.
|
||||||
* false, do nothing if it fails to load.
|
* If false, do nothing if it fails to load.
|
||||||
*/
|
*/
|
||||||
public static void loadNativeLibrary(String name, boolean isRequired) {
|
public static void loadNativeLibrary(String name, boolean isRequired) {
|
||||||
|
loadNativeLibrary(name, isRequired, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First extracts the native library and then (optionally) loads it.
|
||||||
|
*
|
||||||
|
* @param name The name of the library to load.
|
||||||
|
* @param isRequired If true and the library fails to load, throw exception.
|
||||||
|
* If false, do nothing if it fails to load.
|
||||||
|
* @param loadLibrary If true, call
|
||||||
|
* {@link System#loadLibrary(java.lang.String)} on the library, otherwise,
|
||||||
|
* do nothing after extraction.
|
||||||
|
*/
|
||||||
|
public static void loadNativeLibrary(String name, boolean isRequired, boolean loadLibrary) {
|
||||||
if (JmeSystem.isLowPermissions()) {
|
if (JmeSystem.isLowPermissions()) {
|
||||||
throw new UnsupportedOperationException("JVM is running under "
|
throw new UnsupportedOperationException("JVM is running under "
|
||||||
+ "reduced permissions. Cannot load native libraries.");
|
+ "reduced permissions. Cannot load native libraries.");
|
||||||
@ -547,8 +568,8 @@ public final class NativeLibraryLoader {
|
|||||||
"The required native library '" + name + "'"
|
"The required native library '" + name + "'"
|
||||||
+ " is not available for your OS: " + platform);
|
+ " is not available for your OS: " + platform);
|
||||||
} else {
|
} else {
|
||||||
logger.log(Level.FINE, "The optional native library ''{0}''" +
|
logger.log(Level.FINE, "The optional native library ''{0}''"
|
||||||
" is not available for your OS: {1}",
|
+ " is not available for your OS: {1}",
|
||||||
new Object[]{name, platform});
|
new Object[]{name, platform});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -578,15 +599,15 @@ public final class NativeLibraryLoader {
|
|||||||
|
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
// Attempt to load it as a system library.
|
// Attempt to load it as a system library.
|
||||||
|
// Need to unmap it from library specific parts.
|
||||||
String unmappedName = unmapLibraryName(fileNameInJar);
|
String unmappedName = unmapLibraryName(fileNameInJar);
|
||||||
try {
|
try {
|
||||||
// XXX: HACK. Vary loading method based on library name..
|
if (loadLibrary) {
|
||||||
// lwjgl and jinput handle loading by themselves.
|
|
||||||
if (!name.equals("lwjgl") && !name.equals("jinput")) {
|
|
||||||
// Need to unmap it from library specific parts.
|
|
||||||
System.loadLibrary(unmappedName);
|
System.loadLibrary(unmappedName);
|
||||||
logger.log(Level.FINE, "Loaded system installed "
|
logger.log(Level.FINE, "Loaded system installed "
|
||||||
+ "version of native library: {0}", unmappedName);
|
+ "version of native library: {0}", unmappedName);
|
||||||
|
} else {
|
||||||
|
throw new UnsatisfiedLinkError();
|
||||||
}
|
}
|
||||||
} catch (UnsatisfiedLinkError e) {
|
} catch (UnsatisfiedLinkError e) {
|
||||||
if (isRequired) {
|
if (isRequired) {
|
||||||
@ -595,9 +616,9 @@ public final class NativeLibraryLoader {
|
|||||||
+ " was not found in the classpath via '" + pathInJar
|
+ " was not found in the classpath via '" + pathInJar
|
||||||
+ "'. Error message: " + e.getMessage());
|
+ "'. Error message: " + e.getMessage());
|
||||||
} else {
|
} else {
|
||||||
logger.log(Level.FINE, "The optional native library ''{0}''" +
|
logger.log(Level.FINE, "The optional native library ''{0}''"
|
||||||
" was not found in the classpath via ''{1}''" +
|
+ " was not found in the classpath via ''{1}''"
|
||||||
". Error message: {2}",
|
+ ". Error message: {2}",
|
||||||
new Object[]{unmappedName, pathInJar, e.getMessage()});
|
new Object[]{unmappedName, pathInJar, e.getMessage()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -624,12 +645,12 @@ public final class NativeLibraryLoader {
|
|||||||
in = conn.getInputStream();
|
in = conn.getInputStream();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
// Maybe put more detail here? Not sure..
|
// Maybe put more detail here? Not sure..
|
||||||
throw new UnsatisfiedLinkError("Failed to open file: '" + url +
|
throw new UnsatisfiedLinkError("Failed to open file: '" + url
|
||||||
"'. Error: " + ex);
|
+ "'. Error: " + ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
File targetFile = new File(extactionDirectory, loadedAsFileName);
|
File targetFile = new File(extactionDirectory, loadedAsFileName);
|
||||||
OutputStream out = null;
|
FileOutputStream out = null;
|
||||||
try {
|
try {
|
||||||
if (targetFile.exists()) {
|
if (targetFile.exists()) {
|
||||||
// OK, compare last modified date of this file to
|
// OK, compare last modified date of this file to
|
||||||
@ -638,15 +659,17 @@ public final class NativeLibraryLoader {
|
|||||||
long sourceLastModified = conn.getLastModified();
|
long sourceLastModified = conn.getLastModified();
|
||||||
|
|
||||||
// Allow ~1 second range for OSes that only support low precision
|
// Allow ~1 second range for OSes that only support low precision
|
||||||
if (targetLastModified + 1000 > sourceLastModified) {
|
if (Math.abs(targetLastModified - sourceLastModified) < 1000) {
|
||||||
logger.log(Level.FINE, "Not copying library {0}. " +
|
logger.log(Level.FINE, "Not copying library {0}. "
|
||||||
"Latest already extracted.",
|
+ "Identical version already extracted.",
|
||||||
loadedAsFileName);
|
loadedAsFileName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out = new FileOutputStream(targetFile);
|
out = new FileOutputStream(targetFile);
|
||||||
|
FileLock lock = out.getChannel().lock();
|
||||||
|
|
||||||
int len;
|
int len;
|
||||||
while ((len = in.read(buf)) > 0) {
|
while ((len = in.read(buf)) > 0) {
|
||||||
out.write(buf, 0, len);
|
out.write(buf, 0, len);
|
||||||
@ -661,6 +684,8 @@ public final class NativeLibraryLoader {
|
|||||||
// this will cause the last modified date to be lower than
|
// this will cause the last modified date to be lower than
|
||||||
// date created which makes no sense
|
// date created which makes no sense
|
||||||
targetFile.setLastModified(conn.getLastModified());
|
targetFile.setLastModified(conn.getLastModified());
|
||||||
|
} catch (OverlappingFileLockException ex) {
|
||||||
|
// do nothing with ex
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
if (ex.getMessage().contains("used by another process")) {
|
if (ex.getMessage().contains("used by another process")) {
|
||||||
return;
|
return;
|
||||||
@ -669,25 +694,21 @@ public final class NativeLibraryLoader {
|
|||||||
+ "library to: " + targetFile);
|
+ "library to: " + targetFile);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// XXX: HACK. Vary loading method based on library name..
|
if (loadLibrary) {
|
||||||
// lwjgl and jinput handle loading by themselves.
|
|
||||||
if (name.equals("lwjgl") || name.equals("lwjgl3")) {
|
|
||||||
System.setProperty("org.lwjgl.librarypath",
|
|
||||||
extactionDirectory.getAbsolutePath());
|
|
||||||
} else if (name.equals("jinput")) {
|
|
||||||
System.setProperty("net.java.games.input.librarypath",
|
|
||||||
extactionDirectory.getAbsolutePath());
|
|
||||||
} else {
|
|
||||||
// all other libraries (openal, bulletjme, custom)
|
|
||||||
// will load directly in here.
|
|
||||||
System.load(targetFile.getAbsolutePath());
|
System.load(targetFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in != null){
|
if (in != null) {
|
||||||
try { in.close(); } catch (IOException ex) { }
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (out != null) {
|
||||||
|
try {
|
||||||
|
out.close();
|
||||||
|
} catch (IOException ex) {
|
||||||
}
|
}
|
||||||
if(out != null){
|
|
||||||
try { out.close(); } catch (IOException ex) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,201 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2015 jMonkeyEngine
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package com.jme3.system;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.channels.FileLock;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
import com.jme3.IntegrationTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration test for {@link NativeLibraryLoader}.
|
||||||
|
*
|
||||||
|
* Note that it uses the file system.
|
||||||
|
*
|
||||||
|
* @author Kirill Vainer
|
||||||
|
*/
|
||||||
|
@Category(IntegrationTest.class)
|
||||||
|
@FixMethodOrder
|
||||||
|
public class NativeLibraryLoaderIT {
|
||||||
|
|
||||||
|
private File extractFolder;
|
||||||
|
|
||||||
|
static {
|
||||||
|
NativeLibraryLoader.registerNativeLibrary("test", Platform.Linux64, "natives/linux64/libtest.so");
|
||||||
|
NativeLibraryLoader.registerNativeLibrary("notexist", Platform.Linux64, "natives/linux64/libnotexist.so");
|
||||||
|
NativeLibraryLoader.registerNativeLibrary("nativesfolder", Platform.Linux64, "natives/linux64/libnativesfolder.so");
|
||||||
|
NativeLibraryLoader.registerNativeLibrary("jarroot", Platform.Linux64, "natives/linux64/libjarroot.so");
|
||||||
|
NativeLibraryLoader.registerNativeLibrary("nullpath", Platform.Linux64, null);
|
||||||
|
NativeLibraryLoader.registerNativeLibrary("jawt", Platform.Linux64, "whatever/doesnt/matter/libjawt.so");
|
||||||
|
NativeLibraryLoader.registerNativeLibrary("asname", Platform.Linux64, "natives/linux64/libasname.so", "other.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
extractFolder = NativeLibraryLoader.getExtractionFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = UnsatisfiedLinkError.class)
|
||||||
|
public void testRequiredNonExistentFile() {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("notexist", true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOptionalNonExistentFile() throws Exception {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("notexist", false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = UnsatisfiedLinkError.class)
|
||||||
|
public void testRequiredUnregisteredLibrary() {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("unregistered", true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOptionalUnregisteredLibrary() {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("unregistered", false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLibraryNullPath() {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("nullpath", true, false);
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("nullpath", false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void fudgeLastModifiedTime(File file) {
|
||||||
|
// fudge last modified date to force extraction attempt
|
||||||
|
long yesterdayModifiedtime = file.lastModified() - 24 * 60 * 60 * 1000;
|
||||||
|
assertTrue(file.setLastModified(yesterdayModifiedtime));
|
||||||
|
assertTrue(Math.abs(file.lastModified() - yesterdayModifiedtime) < 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDifferentLastModifiedDates() throws IOException {
|
||||||
|
File libFile = new File(extractFolder, "libtest.so");
|
||||||
|
|
||||||
|
assertTrue(libFile.createNewFile());
|
||||||
|
assertTrue(libFile.exists() && libFile.length() == 0);
|
||||||
|
|
||||||
|
fudgeLastModifiedTime(libFile);
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("test", true, false);
|
||||||
|
assertTrue(libFile.length() == 12);
|
||||||
|
|
||||||
|
assertTrue(libFile.delete());
|
||||||
|
assertTrue(!libFile.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLibraryInUse() throws IOException {
|
||||||
|
File libFile = new File(extractFolder, "libtest.so");
|
||||||
|
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("test", true, false);
|
||||||
|
assertTrue(libFile.exists());
|
||||||
|
|
||||||
|
fudgeLastModifiedTime(libFile);
|
||||||
|
|
||||||
|
FileOutputStream out = null;
|
||||||
|
try {
|
||||||
|
out = new FileOutputStream(libFile);
|
||||||
|
FileLock lock = out.getChannel().lock();
|
||||||
|
assertTrue(lock.isValid());
|
||||||
|
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("test", true, false);
|
||||||
|
} finally {
|
||||||
|
if (out != null) {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
libFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadSystemLibrary() {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("jawt", true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExtractAsName() {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("asname", true, false);
|
||||||
|
assertTrue(new File(extractFolder, "other.name").exists());
|
||||||
|
assertTrue(new File(extractFolder, "other.name").delete());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCustomExtractFolder() {
|
||||||
|
File customExtractFolder = new File(System.getProperty("java.io.tmpdir"), "jme3_test_tmp");
|
||||||
|
if (!customExtractFolder.exists()) {
|
||||||
|
assertTrue(customExtractFolder.mkdir());
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeLibraryLoader.setCustomExtractionFolder(customExtractFolder.getAbsolutePath());
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("test", true, false);
|
||||||
|
|
||||||
|
assertTrue(new File(customExtractFolder, "libtest.so").exists());
|
||||||
|
assertTrue(new File(customExtractFolder, "libtest.so").delete());
|
||||||
|
assertTrue(!new File(customExtractFolder, "libtest.so").exists());
|
||||||
|
|
||||||
|
NativeLibraryLoader.setCustomExtractionFolder(null);
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("test", true, false);
|
||||||
|
|
||||||
|
assertTrue(new File(extractFolder, "libtest.so").exists());
|
||||||
|
new File(extractFolder, "libtest.so").delete();
|
||||||
|
customExtractFolder.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExtractFromNativesFolderInJar() {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("nativesfolder", true, false);
|
||||||
|
|
||||||
|
File libFile = new File(extractFolder, "libnativesfolder.so");
|
||||||
|
assertTrue(libFile.exists() && libFile.length() == 12);
|
||||||
|
|
||||||
|
libFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExtractFromJarRoot() {
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("jarroot", true, false);
|
||||||
|
|
||||||
|
File libFile = new File(extractFolder, "libjarroot.so");
|
||||||
|
assertTrue(libFile.exists() && libFile.length() == 12);
|
||||||
|
|
||||||
|
libFile.delete();
|
||||||
|
}
|
||||||
|
}
|
@ -1,88 +0,0 @@
|
|||||||
package jme3test.app;
|
|
||||||
|
|
||||||
import com.jme3.scene.Mesh;
|
|
||||||
import com.jme3.system.AppSettings;
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.prefs.BackingStoreException;
|
|
||||||
|
|
||||||
public class TestCustomAppSettings {
|
|
||||||
|
|
||||||
private static final String APPSETTINGS_KEY = "JME_AppSettingsTest";
|
|
||||||
|
|
||||||
private static void assertEqual(Object a, Object b) {
|
|
||||||
if (!a.equals(b)){
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests preference based AppSettings.
|
|
||||||
*/
|
|
||||||
private static void testPreferenceSettings() {
|
|
||||||
AppSettings settings = new AppSettings(false);
|
|
||||||
settings.putBoolean("TestBool", true);
|
|
||||||
settings.putInteger("TestInt", 123);
|
|
||||||
settings.putString("TestStr", "HelloWorld");
|
|
||||||
settings.putFloat("TestFloat", 123.567f);
|
|
||||||
settings.put("TestObj", new Mesh()); // Objects not supported by preferences
|
|
||||||
|
|
||||||
try {
|
|
||||||
settings.save(APPSETTINGS_KEY);
|
|
||||||
} catch (BackingStoreException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
AppSettings loadedSettings = new AppSettings(false);
|
|
||||||
try {
|
|
||||||
loadedSettings.load(APPSETTINGS_KEY);
|
|
||||||
} catch (BackingStoreException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEqual(loadedSettings.getBoolean("TestBool"), true);
|
|
||||||
assertEqual(loadedSettings.getInteger("TestInt"), 123);
|
|
||||||
assertEqual(loadedSettings.getString("TestStr"), "HelloWorld");
|
|
||||||
assertEqual(loadedSettings.get("TestFloat"), 123.567f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test Java properties file based AppSettings.
|
|
||||||
*/
|
|
||||||
private static void testFileSettings() {
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
|
|
||||||
AppSettings settings = new AppSettings(false);
|
|
||||||
settings.putBoolean("TestBool", true);
|
|
||||||
settings.putInteger("TestInt", 123);
|
|
||||||
settings.putString("TestStr", "HelloWorld");
|
|
||||||
settings.putFloat("TestFloat", 123.567f);
|
|
||||||
settings.put("TestObj", new Mesh()); // Objects not supported by file settings
|
|
||||||
|
|
||||||
try {
|
|
||||||
settings.save(baos);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
AppSettings loadedSettings = new AppSettings(false);
|
|
||||||
try {
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
|
||||||
loadedSettings.load(bais);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEqual(loadedSettings.getBoolean("TestBool"), true);
|
|
||||||
assertEqual(loadedSettings.getInteger("TestInt"), 123);
|
|
||||||
assertEqual(loadedSettings.getString("TestStr"), "HelloWorld");
|
|
||||||
assertEqual(loadedSettings.get("TestFloat"), 123.567f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
|
||||||
testPreferenceSettings();
|
|
||||||
testFileSettings();
|
|
||||||
System.out.println("All OK");
|
|
||||||
}
|
|
||||||
}
|
|
@ -52,6 +52,7 @@ import com.jme3.renderer.opengl.GLTiming;
|
|||||||
import com.jme3.renderer.opengl.GLTimingState;
|
import com.jme3.renderer.opengl.GLTimingState;
|
||||||
import com.jme3.renderer.opengl.GLTracer;
|
import com.jme3.renderer.opengl.GLTracer;
|
||||||
import com.jme3.system.*;
|
import com.jme3.system.*;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -166,17 +167,23 @@ public abstract class LwjglContext implements JmeContext {
|
|||||||
if (JmeSystem.isLowPermissions()) {
|
if (JmeSystem.isLowPermissions()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String extractPath = NativeLibraryLoader.getExtractionFolder().getAbsolutePath();
|
||||||
|
|
||||||
if ("LWJGL".equals(settings.getAudioRenderer())) {
|
if ("LWJGL".equals(settings.getAudioRenderer())) {
|
||||||
NativeLibraryLoader.loadNativeLibrary("openal", true);
|
NativeLibraryLoader.loadNativeLibrary("openal", true);
|
||||||
}
|
}
|
||||||
if (settings.useJoysticks()) {
|
if (settings.useJoysticks()) {
|
||||||
NativeLibraryLoader.loadNativeLibrary("jinput", true);
|
System.setProperty("net.java.games.input.librarypath", extractPath);
|
||||||
NativeLibraryLoader.loadNativeLibrary("jinput-dx8", true);
|
NativeLibraryLoader.loadNativeLibrary("jinput", true, false);
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("jinput-dx8", true, false);
|
||||||
}
|
}
|
||||||
if (NativeLibraryLoader.isUsingNativeBullet()) {
|
if (NativeLibraryLoader.isUsingNativeBullet()) {
|
||||||
NativeLibraryLoader.loadNativeLibrary("bulletjme", true);
|
NativeLibraryLoader.loadNativeLibrary("bulletjme", true);
|
||||||
}
|
}
|
||||||
NativeLibraryLoader.loadNativeLibrary("lwjgl", true);
|
|
||||||
|
System.setProperty("org.lwjgl.librarypath", extractPath);
|
||||||
|
NativeLibraryLoader.loadNativeLibrary("lwjgl", true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getNumSamplesToUse() {
|
protected int getNumSamplesToUse() {
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.app;
|
package com.jme3.app;
|
||||||
|
|
||||||
|
import com.jme3.IntegrationTest;
|
||||||
import com.jme3.renderer.RenderManager;
|
import com.jme3.renderer.RenderManager;
|
||||||
import com.jme3.system.JmeContext;
|
import com.jme3.system.JmeContext;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
@ -41,8 +42,10 @@ import static org.junit.Assert.*;
|
|||||||
import static org.junit.Assume.*;
|
import static org.junit.Assume.*;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
public class LwjglAppTest {
|
@Category(IntegrationTest.class)
|
||||||
|
public class LwjglAppIT {
|
||||||
|
|
||||||
private final AtomicInteger simpleInitAppInvocations = new AtomicInteger();
|
private final AtomicInteger simpleInitAppInvocations = new AtomicInteger();
|
||||||
private final AtomicInteger simpleUpdateInvocations = new AtomicInteger();
|
private final AtomicInteger simpleUpdateInvocations = new AtomicInteger();
|
||||||
@ -66,7 +69,7 @@ public class LwjglAppTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doStopStart(Application app, JmeContext.Type type) throws InterruptedException {
|
private void doStopStart(Application app, JmeContext.Type type) throws InterruptedException {
|
||||||
app.setLostFocusBehavior(LostFocusBehavior.Disabled);
|
app.setLostFocusBehavior(LostFocusBehavior.Disabled);
|
||||||
|
|
||||||
// start the application - simple init / update will be called once.
|
// start the application - simple init / update will be called once.
|
||||||
@ -96,19 +99,19 @@ public class LwjglAppTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisplayApp() throws InterruptedException {
|
public void testDisplayAppLifeCycle() throws InterruptedException {
|
||||||
assumeFalse(GraphicsEnvironment.isHeadless());
|
assumeFalse(GraphicsEnvironment.isHeadless());
|
||||||
doStopStart(new TestApp(), JmeContext.Type.Display);
|
doStopStart(new TestApp(), JmeContext.Type.Display);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOffscreenSurface() throws InterruptedException {
|
public void testOffscreenAppLifeCycle() throws InterruptedException {
|
||||||
assumeFalse(GraphicsEnvironment.isHeadless());
|
assumeFalse(GraphicsEnvironment.isHeadless());
|
||||||
doStopStart(new TestApp(), JmeContext.Type.OffscreenSurface);
|
doStopStart(new TestApp(), JmeContext.Type.OffscreenSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeadlessApp() throws InterruptedException {
|
public void testExceptionInvokesHandleError() throws InterruptedException {
|
||||||
doStopStart(new TestApp(), JmeContext.Type.Headless);
|
doStopStart(new TestApp(), JmeContext.Type.Headless);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user