Skip to content

Commit 07769f7

Browse files
committed
Towards #1290 automate one core issue regression test
1 parent 9641aa7 commit 07769f7

File tree

3 files changed

+101
-103
lines changed

3 files changed

+101
-103
lines changed

jme3-core/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ sourceSets {
1414
java {
1515
srcDir 'src/test/java'
1616
}
17+
18+
System.setProperty "java.awt.headless", "true"
1719
}
1820
}
1921

2022
dependencies {
2123
testCompile project(':jme3-testdata')
24+
testRuntime project(':jme3-desktop')
2225
}
2326

2427
task updateVersionPropertiesFile {
@@ -44,4 +47,4 @@ task updateVersionPropertiesFile {
4447
}
4548
}
4649

47-
processResources.dependsOn updateVersionPropertiesFile
50+
processResources.dependsOn updateVersionPropertiesFile
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2019-2021 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package com.jme3.test;
33+
34+
import com.jme3.app.LegacyApplication;
35+
import com.jme3.app.SimpleApplication;
36+
import com.jme3.app.state.AppState;
37+
import com.jme3.app.state.ScreenshotAppState;
38+
import com.jme3.asset.DesktopAssetManager;
39+
import com.jme3.input.InputManager;
40+
import com.jme3.input.dummy.DummyKeyInput;
41+
import com.jme3.input.dummy.DummyMouseInput;
42+
import com.jme3.renderer.Camera;
43+
import com.jme3.renderer.RenderManager;
44+
import com.jme3.renderer.ViewPort;
45+
import com.jme3.system.NullRenderer;
46+
import org.junit.Assert;
47+
import org.junit.Test;
48+
49+
import java.lang.reflect.Field;
50+
import java.util.List;
51+
52+
/**
53+
* The Test Suite to prevent regressions from previously fixed Core issues
54+
* @author Stephen Gold <[email protected]>
55+
*/
56+
public class PreventCoreIssueRegressions {
57+
58+
/**
59+
* Test case for JME issue #1421: ScreenshotAppState never cleans up.
60+
*/
61+
@Test
62+
public void TestIssue1421() throws NoSuchFieldException, IllegalAccessException {
63+
ScreenshotAppState screenshotAppState = new ScreenshotAppState("./", "screen_shot");
64+
65+
SimpleApplication app = new SimpleApplication(new AppState[]{}) {
66+
@Override
67+
public void simpleInitApp() { }
68+
};
69+
70+
app.setAssetManager(new DesktopAssetManager(true));
71+
Field f1 = LegacyApplication.class.getDeclaredField("inputManager");
72+
f1.setAccessible(true);
73+
f1.set(app, new InputManager(new DummyMouseInput(), new DummyKeyInput(), null, null));
74+
75+
Field f2 = LegacyApplication.class.getDeclaredField("renderManager");
76+
f2.setAccessible(true);
77+
f2.set(app, new RenderManager(new NullRenderer()));
78+
79+
app.getRenderManager().createPostView("null", new Camera(1, 1));
80+
81+
Assert.assertTrue(app.getStateManager().attach(screenshotAppState));
82+
app.getStateManager().update(0f); // Causes SAS#initialize to be called
83+
84+
// Confirm that the SceneProcessor is attached.
85+
List<ViewPort> vps = app.getRenderManager().getPostViews();
86+
Assert.assertEquals(1, vps.size());
87+
Assert.assertEquals(1, vps.get(0).getProcessors().size());
88+
Assert.assertTrue(app.getInputManager().hasMapping("ScreenShot")); // Confirm that KEY_SYSRQ is mapped.
89+
Assert.assertTrue(app.getStateManager().detach(screenshotAppState));
90+
91+
app.getStateManager().update(0f); // Causes SAS#cleanup to be called
92+
93+
// Check whether the SceneProcessor is still attached.
94+
Assert.assertEquals(0, vps.get(0).getProcessors().size());
95+
Assert.assertFalse(app.getInputManager().hasMapping("ScreenShot")); // Confirm that KEY_SYSRQ is unmapped.
96+
}
97+
}

jme3-examples/src/main/java/jme3test/app/state/TestIssue1421.java

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)