lwjgl2-arm64/src/java/org/lwjgl/test/SysTest.java

180 lines
5.1 KiB
Java
Raw Normal View History

2004-06-12 22:28:34 +02:00
/*
* Copyright (c) 2002-2004 LWJGL Project
2004-01-29 20:57:47 +01:00
* All rights reserved.
2004-06-12 22:28:34 +02:00
*
2004-01-29 20:57:47 +01:00
* Redistribution and use in source and binary forms, with or without
2004-06-12 22:28:34 +02:00
* modification, are permitted provided that the following conditions are
2004-01-29 20:57:47 +01:00
* met:
2004-06-12 22:28:34 +02:00
*
* * Redistributions of source code must retain the above copyright
2004-01-29 20:57:47 +01:00
* 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.
*
2004-06-12 22:28:34 +02:00
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
2004-01-29 20:57:47 +01:00
* from this software without specific prior written permission.
2004-06-12 22:28:34 +02:00
*
2004-01-29 20:57:47 +01:00
* 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
2004-06-12 22:28:34 +02:00
* 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
2004-01-29 20:57:47 +01:00
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2004-06-12 22:28:34 +02:00
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2004-01-29 20:57:47 +01:00
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.test;
2004-07-03 15:48:52 +02:00
import org.lwjgl.opengl.Display;
import org.lwjgl.LWJGLUtil;
2004-01-29 20:57:47 +01:00
import org.lwjgl.Sys;
import org.lwjgl.LWJGLException;
2004-01-29 20:57:47 +01:00
/**
* $Id$
* <br>
* Test class for Sys
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public class SysTest {
/**
* Creates a new SysTest
*/
public SysTest() {
}
/**
* Runs the tests
*/
public void executeTest() {
testAlert();
testDebug();
2004-01-29 20:57:47 +01:00
testTimer();
testUrl();
2004-08-12 16:54:39 +02:00
testClipboard();
2004-01-29 20:57:47 +01:00
}
/**
* Tests debug mode
*/
private void testDebug() {
System.out.println("==== Test Debug ====");
if (LWJGLUtil.DEBUG) {
LWJGLUtil.log("Debug is enabled, you should now see output from LWJGL during the following tests.");
2004-01-29 20:57:47 +01:00
} else {
System.out.println("Debug is not enabled. Please set the org.lwjgl.Sys.debug property to true to enable debugging");
System.out.println("Example:\n java -Dorg.lwjgl.Sys.debug=true ...");
System.out.println("You will not see any debug output in the following tests.");
}
// get some display modes, to force some debug info
try {
Display.getAvailableDisplayModes();
} catch (LWJGLException e) {
throw new RuntimeException(e);
}
2004-01-29 20:57:47 +01:00
System.out.println("---- Test Debug ----\n");
}
/**
* Tests the timer
*/
private void testTimer() {
long resolution = Sys.getTimerResolution();
long time = Sys.getTime();
System.out.println("==== Test Timer ====");
System.out.println("Resolution of timer (ticks per second): " + resolution);
System.out.println("Current time: " + time);
System.out.println("Sleeping for 2 seconds, using Thread.sleep()");
pause(2000);
time = Sys.getTime();
System.out.println("Current time: " + time);
System.out.println("Actually slept for: " + (time / (float) resolution) + " seconds");
System.out.println("---- Test Timer ----\n");
}
/**
* Tests the alert
*/
private void testAlert() {
System.out.println("==== Test Alert ====");
System.out.println("Opening native alert window");
Sys.alert("SysTest", "Hello World!");
System.out.println("---- Test Alert ----\n");
}
/**
* Tests the openUrl
*/
private void testUrl() {
System.out.println("==== Test URL ====");
System.out.println("Opening a browser window to http://www.lwjgl.org");
Sys.openURL("http://www.lwjgl.org");
System.out.println("---- Test URL ----\n");
}
/**
* Busy waits for a specified number of seconds
*
* @param priority Priority to busy wait in
* @param seconds Number of seconds to busy wait
* @param message Message to print to user
*/
private void busyWait(int priority, int seconds, String message) {
long future = Sys.getTime() + (Sys.getTimerResolution() * seconds);
System.out.print(message);
// waste some cycles
while (Sys.getTime() < future) {
}
System.out.println("done");
}
/**
* Pause current thread for a specified time
*
* @param time milliseconds to sleep
*/
private void pause(long time) {
try {
Thread.sleep(time);
} catch (InterruptedException inte) {
}
}
2004-08-12 16:54:39 +02:00
/**
* Tests the clipboard. Helps to have something in it first...
*/
private void testClipboard() {
System.out.println("Contents of clipboard: '"+Sys.getClipboard()+"'");
}
2004-01-29 20:57:47 +01:00
/**
* Tests the Sys class, and serves as basic usage test
*
* @param args ignored
*/
public static void main(String[] args) {
new SysTest().executeTest();
}
}