Skip to content

Commit

Permalink
test: move the testClose() method to the Utils class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jul 9, 2024
1 parent 406a7af commit eccb87c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
12 changes: 12 additions & 0 deletions src/test/java/testjoltjni/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ of this software and associated documentation files (the "Software"), to deal
package testjoltjni;

import com.github.stephengold.joltjni.Jolt;
import com.github.stephengold.joltjni.JoltPhysicsObject;
import com.github.stephengold.joltjni.QuatArg;
import com.github.stephengold.joltjni.RVec3Arg;
import com.github.stephengold.joltjni.Vec3Arg;
Expand Down Expand Up @@ -138,4 +139,15 @@ public static int numThreads() {

return result;
}

/**
* Test the {@code close()} method of the specified object.
*
* @param object the object to test (not null)
*/
public static void testClose(JoltPhysicsObject object) {
object.close();
Assert.assertFalse(object.hasAssignedNativeObject());
Assert.assertFalse(object.ownsNativeObject());
}
}
30 changes: 9 additions & 21 deletions src/test/java/testjoltjni/junit/Test003.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ of this software and associated documentation files (the "Software"), to deal
import com.github.stephengold.joltjni.JobSystemThreadPool;
import com.github.stephengold.joltjni.JobSystemWithBarrier;
import com.github.stephengold.joltjni.Jolt;
import com.github.stephengold.joltjni.JoltPhysicsObject;
import com.github.stephengold.joltjni.NonCopyable;
import com.github.stephengold.joltjni.Quat;
import com.github.stephengold.joltjni.RVec3;
Expand Down Expand Up @@ -79,7 +78,7 @@ public void test003() {
Assert.assertTrue(box.ownsNativeObject());
Assert.assertNotEquals(0L, box.va());

testClose(box);
Utils.testClose(box);
}
{
Vec3Arg max = new Vec3(1f, 2f, 3f);
Expand All @@ -90,7 +89,7 @@ public void test003() {
Assert.assertTrue(box.ownsNativeObject());
Assert.assertNotEquals(0L, box.va());

testClose(box);
Utils.testClose(box);
}

// BodyCreationSettings:
Expand All @@ -101,7 +100,7 @@ public void test003() {
testBcsDefaults(bcs);
testBcsSetters(bcs);

testClose(bcs);
Utils.testClose(bcs);
}
{
ShapeSettings ss = new BoxShapeSettings(new Vec3(1f, 1f, 1f));
Expand All @@ -114,7 +113,7 @@ public void test003() {
testBcsDefaults(bcs);
testBcsSetters(bcs);

testClose(bcs);
Utils.testClose(bcs);
}
{
Shape shape = new SphereShape(1f);
Expand All @@ -126,7 +125,7 @@ public void test003() {
testBcsDefaults(bcs);
testBcsSetters(bcs);

testClose(bcs);
Utils.testClose(bcs);
}

// JobSystemSingleThreaded:
Expand All @@ -140,7 +139,7 @@ public void test003() {
Assert.assertTrue(jobSystem.ownsNativeObject());
Assert.assertNotEquals(0L, jobSystem.va());

testClose(jobSystem);
Utils.testClose(jobSystem);
}

// JobSystemThreadPool:
Expand All @@ -161,7 +160,7 @@ public void test003() {
jobSystem.setNumThreads(3);
Assert.assertEquals(4, jobSystem.getMaxConcurrency());

testClose(jobSystem);
Utils.testClose(jobSystem);
}

// TempAllocatorImpl:
Expand All @@ -173,7 +172,7 @@ public void test003() {
Assert.assertTrue(tempAllocator.ownsNativeObject());
Assert.assertNotEquals(0L, tempAllocator.va());

testClose(tempAllocator);
Utils.testClose(tempAllocator);
}

// TempAllocatorMalloc:
Expand All @@ -184,7 +183,7 @@ public void test003() {
Assert.assertTrue(tempAllocator.ownsNativeObject());
Assert.assertNotEquals(0L, tempAllocator.va());

testClose(tempAllocator);
Utils.testClose(tempAllocator);
}
}
// *************************************************************************
Expand Down Expand Up @@ -256,15 +255,4 @@ private static void testBcsSetters(BodyCreationSettings bcs) {
bcs.setRotation(new Quat(0.6f, 0f, 0f, 0.8f));
Utils.assertEquals(0.6f, 0f, 0f, 0.8f, bcs.getRotation(), 0f);
}

/**
* Test the {@code close()} method of the specified object.
*
* @param object the object to test (not null)
*/
private static void testClose(JoltPhysicsObject object) {
object.close();
Assert.assertFalse(object.hasAssignedNativeObject());
Assert.assertFalse(object.ownsNativeObject());
}
}

0 comments on commit eccb87c

Please sign in to comment.