more tests

This commit is contained in:
Brian Matzon 2004-01-29 19:57:47 +00:00
parent 1dd06d2e3e
commit fa756c1619
2 changed files with 442 additions and 0 deletions

View File

@ -0,0 +1,257 @@
/*
* Copyright (c) 2004 Lightweight Java Game Library Project
* 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 'Lightweight Java Game Library' 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 org.lwjgl.test;
import org.lwjgl.Display;
import org.lwjgl.DisplayMode;
/**
* $Id$
* <br>
* Test class for Display & DisplayMode
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public class DisplayTest {
/**
* Creates a new DisplayTest
*/
public DisplayTest() {
}
/**
* Runs the tests
*/
public void executeTest() {
currentTest();
queryModesTest();
setDisplayModeTest();
setDisplayConfigurationTest();
}
/**
* Prints some info about the current mode
*/
private void currentTest() {
System.out.println("==== Test Current ====");
System.out.println("Info about current:");
System.out.println("Platform: " + getNameForPlatform());
System.out.println("Graphics card: " + Display.getAdapter() + ", version: " + Display.getVersion());
System.out.println("Resolution: " +
Display.getWidth() + "x" +
Display.getHeight() + "x" +
Display.getDepth() + "@" +
Display.getFrequency() + "Hz");
System.out.println("---- Test Current ----");
}
/**
* Tests querying for modes
*/
private void queryModesTest() {
DisplayMode[] modes = null;
System.out.println("==== Test query ====");
System.out.println("Retrieving available displaymodes");
modes = Display.getAvailableDisplayModes();
// no modes check
if (modes == null) {
System.out.println("FATAL: unable to find any modes!");
System.exit(-1);
}
// write some info
System.out.println("Found " + modes.length + " modes");
System.out.println("The first 5 are:");
for(int i=0;i<modes.length; i++) {
System.out.println(modes[i]);
if (i == 5) {
break;
}
}
System.out.println("---- Test query ----");
}
/**
* Tests setting display modes
*/
private void setDisplayModeTest() {
DisplayMode mode = null;
DisplayMode[] modes = null;
System.out.println("==== Test setDisplayMode ====");
System.out.println("Retrieving available displaymodes");
modes = Display.getAvailableDisplayModes();
// no modes check
if (modes == null) {
System.out.println("FATAL: unable to find any modes!");
System.exit(-1);
}
// find a mode
System.out.print("Looking for 640x480x16@60...");
for(int i=0; i<modes.length;i++) {
if (modes[i].width == 640 &&
modes[i].height == 480 &&
modes[i].bpp == 16 &&
modes[i].freq == 60) {
mode = modes[i];
System.out.println("found!");
break;
}
}
// no mode check
if (mode == null) {
System.out.println("error\nFATAL: Unable to find basic mode.");
System.exit(-1);
}
// change to mode, and wait a bit
System.out.print("Changing to mode...");
try {
Display.setDisplayMode(mode);
} catch (Exception e) {
System.out.println("error\nFATAL: Error setting mode");
System.exit(-1);
}
System.out.println("done");
System.out.println("Resolution: " +
Display.getWidth() + "x" +
Display.getHeight() + "x" +
Display.getDepth() + "@" +
Display.getFrequency() + "Hz");
pause(5000);
// reset
System.out.print("Resetting mode...");
Display.resetDisplayMode();
System.out.println("done");
System.out.println("---- Test setDisplayMode ----");
}
/**
* Tests the DisplayConfiguration
*/
private void setDisplayConfigurationTest() {
System.out.println("==== Test setDisplayConfigurationTest ====");
System.out.println("Testing normal setting");
changeConfig(1.0f, 0f, 1f);
System.out.println("Testing gamma settings");
changeConfig(5.0f, 0f, 1f);
changeConfig(0.5f, 0f, 1f);
System.out.println("Testing brightness settings");
changeConfig(1.0f, -1.0f, 1f);
changeConfig(1.0f, -0.5f, 1f);
changeConfig(1.0f, 0.5f, 1f);
changeConfig(1.0f, 1.0f, 1f);
System.out.println("Testing contrast settings");
changeConfig(1.0f, 0f, 0f);
changeConfig(1.0f, 0f, 0.5f);
changeConfig(1.0f, 0f, 10000.0f);
System.out.print("resetting...");
Display.resetDisplayMode();
System.out.println("done");
System.out.println("---- Test setDisplayConfigurationTest ----");
}
/**
* Changes the Displat configuration
*
* @param gamma gamma value to change to
* @param brightness brightness value to change to
* @param contrast contrast value to change to
*/
private void changeConfig(float gamma, float brightness, float contrast) {
try {
Display.setDisplayConfiguration(gamma, brightness, contrast);
System.out.println("Configuration changed, gamma = " + gamma + " brightness = " + brightness + " contrast = " + contrast);
} catch (Exception e) {
System.out.println("Failed on: gamma = " + gamma + " brightness = " + brightness + " contrast = " + contrast);
}
pause(3000);
}
/**
* Pause current thread for a specified time
*
* @param time milliseconds to sleep
*/
private void pause(long time) {
try {
Thread.sleep(time);
} catch (InterruptedException inte) {
}
}
/**
* Returns a String representation of the platform
*
* @return String representation of the platform
*/
private String getNameForPlatform() {
switch (Display.getPlatform()) {
case Display.PLATFORM_WGL:
return "WGL";
case Display.PLATFORM_GLX:
return "GLX";
case Display.PLATFORM_AGL:
return "AGL";
default:
return "Unknown platform";
}
}
/**
* Tests the Sys class, and serves as basic usage test
*
* @param args ignored
*/
public static void main(String[] args) {
new DisplayTest().executeTest();
}
}

View File

@ -0,0 +1,185 @@
/*
* Copyright (c) 2004 Lightweight Java Game Library Project
* 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 'Lightweight Java Game Library' 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 org.lwjgl.test;
import org.lwjgl.Display;
import org.lwjgl.Sys;
/**
* $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() {
testDebug();
testTimer();
testPriority();
testAlert();
testUrl();
}
/**
* Tests debug mode
*/
private void testDebug() {
System.out.println("==== Test Debug ====");
if (Sys.DEBUG) {
Sys.log("Debug is enabled, you should now see output from LWJGL during the following tests.");
} 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
Display.getAvailableDisplayModes();
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 priority
*/
private void testPriority() {
System.out.println("==== Test Priority ====");
busyWait(Sys.LOW_PRIORITY, 5, "Busy waiting in low priority...");
busyWait(Sys.NORMAL_PRIORITY, 5, "Busy waiting in normal priority...");
busyWait(Sys.HIGH_PRIORITY, 5, "Busy waiting in high priority...");
busyWait(Sys.REALTIME_PRIORITY, 5, "Busy waiting in realtime priority (may lag the computer!)...");
// reset
System.out.println("Resetting to normal");
Sys.setProcessPriority(Sys.NORMAL_PRIORITY);
System.out.println("---- Test Priority ----\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);
Sys.setProcessPriority(priority);
// 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) {
}
}
/**
* Tests the Sys class, and serves as basic usage test
*
* @param args ignored
*/
public static void main(String[] args) {
new SysTest().executeTest();
}
}