Skip to content

Commit 9d4327a

Browse files
committed
Towards #1290 Automate a few more tests/examples
1 parent 07769f7 commit 9d4327a

File tree

8 files changed

+129
-324
lines changed

8 files changed

+129
-324
lines changed

jme3-core/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ sourceSets {
2121

2222
dependencies {
2323
testCompile project(':jme3-testdata')
24-
testRuntime project(':jme3-desktop')
24+
testCompile project(':jme3-desktop')
25+
testRuntime project(':jme3-plugins')
2526
}
2627

2728
task updateVersionPropertiesFile {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.jme3.asset;
2+
3+
import com.jme3.asset.plugins.ClasspathLocator;
4+
import com.jme3.asset.plugins.HttpZipLocator;
5+
import com.jme3.asset.plugins.UrlLocator;
6+
import com.jme3.asset.plugins.ZipLocator;
7+
import com.jme3.audio.plugins.WAVLoader;
8+
import com.jme3.system.JmeSystem;
9+
import com.jme3.texture.plugins.AWTLoader;
10+
import org.junit.Assert;
11+
import org.junit.Test;
12+
13+
public class TestLocators {
14+
15+
@Test
16+
public void TestAbsoluteLocators() {
17+
AssetManager am = JmeSystem.newAssetManager(TestLocators.class.getResource("/com/jme3/asset/Desktop.cfg"));
18+
am.registerLocator("/", ClasspathLocator.class);
19+
am.registerLoader(WAVLoader.class, "wav");
20+
am.registerLoader(AWTLoader.class, "jpg");
21+
22+
Assert.assertNotNull(am.loadAudio("Sound/Effects/Gun.wav"));
23+
Assert.assertNotNull(am.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
24+
}
25+
26+
/**
27+
* Demonstrates loading a file from a custom {@link AssetLoader}
28+
*/
29+
@Test
30+
public void TestCustomLoader() {
31+
AssetManager am = new DesktopAssetManager(true);
32+
am.registerLocator("/", ClasspathLocator.class);
33+
am.registerLoader(TextLoader.class, "fnt");
34+
String result = (String)am.loadAsset("Interface/Fonts/Console.fnt");
35+
Assert.assertTrue(result.startsWith("info face=\"Lucida Console\" size=11 bold=0 italic=0 charset=\"\" unicode=1" +
36+
" stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1 outline=0"));
37+
}
38+
39+
@Test
40+
public void TestManyLocators() {
41+
AssetManager am = new DesktopAssetManager(true);
42+
am.registerLocator(
43+
"https://github.com/jMonkeyEngine/wiki/raw/master/docs/modules/tutorials/assets/images/beginner/",
44+
UrlLocator.class);
45+
46+
am.registerLocator("../jme3-examples/town.zip", ZipLocator.class);
47+
am.registerLocator(
48+
"https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip",
49+
HttpZipLocator.class);
50+
am.registerLocator("/", ClasspathLocator.class);
51+
52+
// Try loading from jme3-core resources using the ClasspathLocator.
53+
Assert.assertNotNull("Failed to load from classpath",
54+
am.locateAsset(new AssetKey<>("Interface/Fonts/Default.fnt")));
55+
56+
// Try loading from the "town.zip" file using the ZipLocator.
57+
Assert.assertNotNull("Failed to load from town.zip file",
58+
am.locateAsset(new ModelKey("casaamarela.jpg")));
59+
60+
// Try loading from the Google Code Archive website using the HttpZipLocator.
61+
Assert.assertNotNull("Failed to load from wildhouse.zip on googleapis.com",
62+
am.locateAsset(new ModelKey("glasstile2.png")));
63+
64+
// Try loading from the GitHub website using the UrlLocator.
65+
Assert.assertNotNull("Failed to load from HTTP",
66+
am.locateAsset(new TextureKey("beginner-physics.png")));
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
package jme3test.asset;
2-
3-
import com.jme3.asset.AssetInfo;
4-
import com.jme3.asset.AssetLoader;
5-
import java.io.IOException;
6-
import java.util.Scanner;
7-
8-
/**
9-
* An example implementation of {@link AssetLoader} to load text
10-
* files as strings.
11-
*/
12-
public class TextLoader implements AssetLoader {
13-
@Override
14-
public Object load(AssetInfo assetInfo) throws IOException {
15-
Scanner scan = new Scanner(assetInfo.openStream());
16-
StringBuilder sb = new StringBuilder();
17-
try {
18-
while (scan.hasNextLine()) {
19-
sb.append(scan.nextLine()).append('\n');
20-
}
21-
} finally {
22-
scan.close();
23-
}
24-
return sb.toString();
25-
}
26-
}
1+
package com.jme3.asset;
2+
3+
import java.util.Scanner;
4+
5+
/**
6+
* An example implementation of {@link AssetLoader} to load text
7+
* files as strings.
8+
*/
9+
public class TextLoader implements AssetLoader {
10+
@Override
11+
public Object load(AssetInfo assetInfo) {
12+
Scanner scan = new Scanner(assetInfo.openStream());
13+
StringBuilder sb = new StringBuilder();
14+
try {
15+
while (scan.hasNextLine()) {
16+
sb.append(scan.nextLine()).append('\n');
17+
}
18+
} finally {
19+
scan.close();
20+
}
21+
return sb.toString();
22+
}
23+
}

jme3-core/src/test/java/com/jme3/test/PreventCoreIssueRegressions.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,25 @@
3131
*/
3232
package com.jme3.test;
3333

34+
import com.jme3.anim.AnimComposer;
35+
import com.jme3.anim.Joint;
36+
import com.jme3.anim.SkinningControl;
3437
import com.jme3.app.LegacyApplication;
3538
import com.jme3.app.SimpleApplication;
3639
import com.jme3.app.state.AppState;
3740
import com.jme3.app.state.ScreenshotAppState;
41+
import com.jme3.asset.AssetManager;
3842
import com.jme3.asset.DesktopAssetManager;
3943
import com.jme3.input.InputManager;
4044
import com.jme3.input.dummy.DummyKeyInput;
4145
import com.jme3.input.dummy.DummyMouseInput;
46+
import com.jme3.light.AmbientLight;
47+
import com.jme3.math.Vector3f;
4248
import com.jme3.renderer.Camera;
4349
import com.jme3.renderer.RenderManager;
4450
import com.jme3.renderer.ViewPort;
51+
import com.jme3.scene.Node;
52+
import com.jme3.system.JmeSystem;
4553
import com.jme3.system.NullRenderer;
4654
import org.junit.Assert;
4755
import org.junit.Test;
@@ -94,4 +102,32 @@ public void simpleInitApp() { }
94102
Assert.assertEquals(0, vps.get(0).getProcessors().size());
95103
Assert.assertFalse(app.getInputManager().hasMapping("ScreenShot")); // Confirm that KEY_SYSRQ is unmapped.
96104
}
105+
106+
/**
107+
* Test case for JME issue #1138: Elephant's legUp animation sets Joint translation to NaN.
108+
*/
109+
@Test
110+
public void TestIssue1138() {
111+
AssetManager am = JmeSystem.newAssetManager(PreventCoreIssueRegressions.class.getResource("/com/jme3/asset/Desktop.cfg"));
112+
Node cgModel = (Node)am.loadModel("Models/Elephant/Elephant.mesh.xml");
113+
cgModel.rotate(0f, -1f, 0f);
114+
cgModel.scale(0.04f);
115+
116+
AnimComposer composer = cgModel.getControl(AnimComposer.class);
117+
composer.setCurrentAction("legUp");
118+
SkinningControl sControl = cgModel.getControl(SkinningControl.class);
119+
120+
for (Joint joint : sControl.getArmature().getJointList()) {
121+
Assert.assertTrue("Invalid translation for joint " + joint.getName(),
122+
Vector3f.isValidVector(joint.getLocalTranslation()));
123+
}
124+
125+
cgModel.updateLogicalState(1.0f);
126+
cgModel.updateGeometricState();
127+
128+
for (Joint joint : sControl.getArmature().getJointList()) {
129+
Assert.assertTrue("Invalid translation for joint " + joint.getName(),
130+
Vector3f.isValidVector(joint.getLocalTranslation()));
131+
}
132+
}
97133
}

jme3-examples/src/main/java/jme3test/animation/TestIssue1138.java

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

jme3-examples/src/main/java/jme3test/asset/TestAbsoluteLocators.java

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

jme3-examples/src/main/java/jme3test/asset/TestCustomLoader.java

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

0 commit comments

Comments
 (0)