1 /** 2 * Copyright 2010 JogAmp Community. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, are 5 * permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * 24 * The views and conclusions contained in the software and documentation are those of the 25 * authors and should not be interpreted as representing official policies, either expressed 26 * or implied, of JogAmp Community. 27 */ 28 29 package com.jogamp.opengl.test.junit.newt.mm; 30 31 import java.io.IOException; 32 import com.jogamp.nativewindow.NativeWindowFactory; 33 34 import org.junit.Assert; 35 import org.junit.BeforeClass; 36 import org.junit.Test; 37 import org.junit.FixMethodOrder; 38 import org.junit.runners.MethodSorters; 39 40 import com.jogamp.newt.Display; 41 import com.jogamp.newt.MonitorDevice; 42 import com.jogamp.newt.NewtFactory; 43 import com.jogamp.newt.Screen; 44 import com.jogamp.newt.MonitorMode; 45 import com.jogamp.newt.opengl.GLWindow; 46 import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; 47 import com.jogamp.opengl.test.junit.util.AWTRobotUtil; 48 import com.jogamp.opengl.test.junit.util.UITestCase; 49 import com.jogamp.opengl.util.Animator; 50 51 import java.util.Iterator; 52 import java.util.List; 53 import com.jogamp.opengl.GLCapabilities; 54 import com.jogamp.opengl.GLCapabilitiesImmutable; 55 56 /** 57 * Queries the current MonitorMode 50 times, 58 * stressing a possible race condition. 59 */ 60 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 61 public class TestScreenMode00bNEWT extends UITestCase { 62 static int width, height; 63 64 static int waitTimeShort = 4; //1 sec 65 static int waitTimeLong = 6; //6 sec 66 67 @BeforeClass initClass()68 public static void initClass() { 69 setResetXRandRIfX11AfterClass(); 70 NativeWindowFactory.initSingleton(); 71 width = 640; 72 height = 480; 73 } 74 75 @Test testScreenModeInfo01()76 public void testScreenModeInfo01() throws InterruptedException { 77 final Display display = NewtFactory.createDisplay(null); 78 final Screen screen = NewtFactory.createScreen(display, 0); 79 // screen.addReference(); 80 81 // put some load on the screen/display context .. 82 final GLCapabilitiesImmutable caps = new GLCapabilities(null); 83 final GLWindow window = GLWindow.create(screen, caps); 84 window.addGLEventListener(new GearsES2()); 85 window.setSize(256, 256); 86 window.setVisible(true); 87 final Animator anim = new Animator(window); 88 anim.start(); 89 90 Assert.assertEquals(true,window.isNativeValid()); 91 Assert.assertEquals(true,screen.isNativeValid()); 92 Assert.assertEquals(true,display.isNativeValid()); 93 94 final List<MonitorMode> screenModes = screen.getMonitorModes(); 95 Assert.assertTrue(screenModes.size()>0); 96 int i=0; 97 for(final Iterator<MonitorMode> iter=screenModes.iterator(); iter.hasNext(); i++) { 98 System.err.println(i+": "+iter.next()); 99 } 100 final MonitorDevice monitor = window.getMainMonitor(); 101 final MonitorMode mm_o = monitor.getOriginalMode(); 102 103 Assert.assertNotNull(mm_o); 104 MonitorMode mm_c = monitor.queryCurrentMode(); 105 Assert.assertNotNull(mm_c); 106 System.err.println("orig: "+mm_o); 107 System.err.println("curr: "+mm_c); 108 109 for(i=0; i<50; i++) { 110 mm_c = monitor.queryCurrentMode(); 111 Assert.assertNotNull(mm_c); 112 System.err.print("."+i); 113 } 114 System.err.println("!"); 115 116 // screen.removeReference(); 117 anim.stop(); 118 window.destroy(); 119 120 Assert.assertEquals(false,window.isVisible()); 121 Assert.assertEquals(false,window.isNativeValid()); 122 Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false)); 123 Assert.assertEquals(false,screen.isNativeValid()); 124 Assert.assertEquals(false,display.isNativeValid()); 125 } 126 main(final String args[])127 public static void main(final String args[]) throws IOException { 128 final String tstname = TestScreenMode00bNEWT.class.getName(); 129 org.junit.runner.JUnitCore.main(tstname); 130 } 131 } 132