Jogamp
Bug 1290: Expand query whether BCM IV is being used, exclude '/dev/dri/card0'
[jogl.git] / src / test / com / jogamp / opengl / test / junit / jogl / demos / gl2 / awt / TestGearsAWT.java
CommitLineData
ea948abf
SG
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:
ebe980ad 6 *
ea948abf
SG
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
ebe980ad 9 *
ea948abf
SG
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.
ebe980ad 13 *
ea948abf
SG
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.
ebe980ad 23 *
ea948abf
SG
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.
1ad8c39d 27 */
ebe980ad 28
5b150ea8 29package com.jogamp.opengl.test.junit.jogl.demos.gl2.awt;
1ad8c39d 30
1ec82447 31import com.jogamp.opengl.*;
ea819ff7 32
1ad8c39d 33import com.jogamp.opengl.util.Animator;
ebe980ad 34
1ec82447 35import com.jogamp.opengl.awt.GLCanvas;
ebe980ad 36
6e273ec0 37import com.jogamp.newt.event.awt.AWTKeyAdapter;
d370be30 38import com.jogamp.newt.event.awt.AWTWindowAdapter;
6e273ec0 39import com.jogamp.newt.event.TraceKeyAdapter;
d370be30 40import com.jogamp.newt.event.TraceWindowAdapter;
5b150ea8 41import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
84a76425
SG
42import com.jogamp.opengl.test.junit.util.UITestCase;
43import com.jogamp.opengl.test.junit.util.QuitAdapter;
08e3f9bf
SG
44
45import java.awt.Dimension;
1ad8c39d 46import java.awt.Frame;
3ed49121
SG
47import java.io.BufferedReader;
48import java.io.IOException;
49import java.io.InputStreamReader;
65dc12ec 50import java.lang.reflect.InvocationTargetException;
1ad8c39d
SG
51
52import org.junit.Assert;
1ad8c39d
SG
53import org.junit.BeforeClass;
54import org.junit.AfterClass;
1ad8c39d 55import org.junit.Test;
43cc2ea7
SG
56import org.junit.FixMethodOrder;
57import org.junit.runners.MethodSorters;
1ad8c39d 58
43cc2ea7 59@FixMethodOrder(MethodSorters.NAME_ASCENDING)
3acabfe0 60public class TestGearsAWT extends UITestCase {
1ad8c39d
SG
61 static GLProfile glp;
62 static int width, height;
3ed49121 63 static boolean waitForKey = false;
9b5cee85 64 static int msaaCount = 0;
1ad8c39d
SG
65
66 @BeforeClass
67 public static void initClass() {
397665ff
SG
68 if(GLProfile.isAvailable(GLProfile.GL2)) {
69 glp = GLProfile.get(GLProfile.GL2);
70 Assert.assertNotNull(glp);
08e3f9bf
SG
71 width = 640;
72 height = 480;
397665ff
SG
73 } else {
74 setTestSupported(false);
75 }
3ed49121
SG
76 // Runtime.getRuntime().traceInstructions(true);
77 // Runtime.getRuntime().traceMethodCalls(true);
1ad8c39d
SG
78 }
79
80 @AfterClass
81 public static void releaseClass() {
82 }
83
556d92b6 84 protected void runTestGL(final GLCapabilities caps) throws InterruptedException, InvocationTargetException {
65dc12ec 85 final Frame frame = new Frame("Gears AWT Test");
1ad8c39d
SG
86 Assert.assertNotNull(frame);
87
65dc12ec 88 final GLCanvas glCanvas = new GLCanvas(caps);
1ad8c39d 89 Assert.assertNotNull(glCanvas);
556d92b6 90 final Dimension glc_sz = new Dimension(width, height);
08e3f9bf
SG
91 glCanvas.setMinimumSize(glc_sz);
92 glCanvas.setPreferredSize(glc_sz);
93 glCanvas.setSize(glc_sz);
1ad8c39d 94 frame.add(glCanvas);
1ad8c39d 95
0d7bcd24 96 glCanvas.addGLEventListener(new Gears(1));
1ad8c39d 97
ebe980ad
SG
98 final QuitAdapter quitAdapter = new QuitAdapter();
99 new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glCanvas).addTo(glCanvas);
100 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas).addTo(frame);
1ad8c39d 101
65dc12ec
SG
102 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
103 public void run() {
08e3f9bf 104 frame.pack();
65dc12ec
SG
105 frame.setVisible(true);
106 }});
ebe980ad
SG
107
108 final Animator animator = new Animator(glCanvas);
109 animator.setUpdateFPSFrames(60, System.err);
1ad8c39d
SG
110 animator.start();
111
ea819ff7 112 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
1ad8c39d
SG
113 Thread.sleep(100);
114 }
115
116 Assert.assertNotNull(frame);
117 Assert.assertNotNull(glCanvas);
118 Assert.assertNotNull(animator);
119
120 animator.stop();
6bbf70d2 121 Assert.assertEquals(false, animator.isAnimating());
9a5e03cc
SG
122 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
123 public void run() {
124 frame.setVisible(false);
125 }});
6bbf70d2 126 Assert.assertEquals(false, frame.isVisible());
65dc12ec
SG
127 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
128 public void run() {
129 frame.remove(glCanvas);
130 frame.dispose();
131 }});
1ad8c39d
SG
132 }
133
134 @Test
65dc12ec 135 public void test01() throws InterruptedException, InvocationTargetException {
556d92b6 136 final GLCapabilities caps = new GLCapabilities(glp);
9b5cee85
SG
137 if( msaaCount > 0 ) {
138 caps.setSampleBuffers(true);
139 caps.setNumSamples(msaaCount);
140 }
1ad8c39d
SG
141 runTestGL(caps);
142 }
143
144 static long duration = 500; // ms
145
556d92b6 146 public static void main(final String args[]) {
1ad8c39d
SG
147 for(int i=0; i<args.length; i++) {
148 if(args[i].equals("-time")) {
149 i++;
150 try {
151 duration = Integer.parseInt(args[i]);
556d92b6 152 } catch (final Exception ex) { ex.printStackTrace(); }
9b5cee85
SG
153 } else if(args[i].equals("-msaa")) {
154 i++;
155 try {
156 msaaCount = Integer.parseInt(args[i]);
556d92b6 157 } catch (final Exception ex) { ex.printStackTrace(); }
3ed49121
SG
158 } else if(args[i].equals("-wait")) {
159 waitForKey = true;
ebe980ad 160 }
1ad8c39d 161 }
3ed49121 162 if(waitForKey) {
556d92b6 163 final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
3ed49121
SG
164 System.err.println("Press enter to continue");
165 try {
166 System.err.println(stdin.readLine());
556d92b6 167 } catch (final IOException e) { }
3ed49121 168 }
1ad8c39d
SG
169 org.junit.runner.JUnitCore.main(TestGearsAWT.class.getName());
170 }
171}
http://JogAmp.org git info: FAQ, tutorial and man pages.