JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestWindowClosingProtocol02NEWT.java
Go to the documentation of this file.
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
29package com.jogamp.opengl.test.junit.newt;
30
31import java.lang.reflect.InvocationTargetException;
32
33import org.junit.Test;
34import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
36import org.junit.Assert;
37
38import com.jogamp.nativewindow.WindowClosingProtocol.WindowClosingMode;
39
40import com.jogamp.opengl.GLCapabilities;
41import com.jogamp.opengl.GLProfile;
42
43import com.jogamp.newt.opengl.GLWindow;
44
45import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
46
47import com.jogamp.opengl.test.junit.util.NewtTestUtil;
48import com.jogamp.opengl.test.junit.util.TestUtil;
49import com.jogamp.opengl.test.junit.util.UITestCase;
50
51@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53
54 @Test
55 public void testCloseGLWindow() throws InterruptedException, InvocationTargetException {
56 final GLProfile glp = GLProfile.getGL2ES2();
57 final GLCapabilities caps = new GLCapabilities(glp);
58 final GLWindow glWindow = GLWindow.create(caps);
59 final TestUtil.WindowClosingListener closingListener = NewtTestUtil.addClosingListener(glWindow);
60
61 glWindow.addGLEventListener(new GearsES2());
62 glWindow.setSize(512, 512);
63 glWindow.setVisible(true);
64 Assert.assertEquals(true, glWindow.isVisible());
65
66 // CHECK DEFAULT ..
68 Assert.assertEquals(WindowClosingMode.DISPOSE_ON_CLOSE, op);
69
70 //
71 // close with op: DO_NOTHING_ON_CLOSE -> NOP
72 //
74 op = glWindow.getDefaultCloseOperation();
75 Assert.assertEquals(WindowClosingMode.DO_NOTHING_ON_CLOSE, op);
76
77 Thread.sleep(300);
78
79 Assert.assertEquals(true, NewtTestUtil.closeWindow(glWindow, false, closingListener, null)); // nop
80 Assert.assertEquals(true, glWindow.isNativeValid());
81 Assert.assertEquals(true, closingListener.isWindowClosing());
82 closingListener.reset();
83
84 //
85 // close with op (GLCanvas): DISPOSE_ON_CLOSE -> dispose
86 //
88 op = glWindow.getDefaultCloseOperation();
89 Assert.assertEquals(WindowClosingMode.DISPOSE_ON_CLOSE, op);
90
91 Assert.assertEquals(true, NewtTestUtil.closeWindow(glWindow, true, closingListener, null));
92 Assert.assertEquals(false, glWindow.isNativeValid());
93 Assert.assertEquals(true, closingListener.isWindowClosing());
94 }
95
96 public static void main(final String[] args) {
97 final String tstname = TestWindowClosingProtocol02NEWT.class.getName();
98 org.junit.runner.JUnitCore.main(tstname);
99 }
100
101}
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
WindowClosingMode setDefaultCloseOperation(final WindowClosingMode op)
Definition: GLWindow.java:222
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
WindowClosingMode getDefaultCloseOperation()
Definition: GLWindow.java:217
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static TestUtil.WindowClosingListener addClosingListener(final Window win)
static boolean closeWindow(final Window win, final boolean willClose, final TestUtil.WindowClosingListener closingListener, final Runnable waitAction)
Programmatically issue windowClosing on AWT or NEWT.
Window closing mode if triggered by toolkit close operation.
DO_NOTHING_ON_CLOSE
Do nothing on native window close operation.
DISPOSE_ON_CLOSE
Dispose resources on native window close operation.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.