|
| 1 | +/* |
| 2 | +Copyright (c) 2024-2026 Stephen Gold |
| 3 | +
|
| 4 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +of this software and associated documentation files (the "Software"), to deal |
| 6 | +in the Software without restriction, including without limitation the rights |
| 7 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +copies of the Software, and to permit persons to whom the Software is |
| 9 | +furnished to do so, subject to the following conditions: |
| 10 | +
|
| 11 | +The above copyright notice and this permission notice shall be included in all |
| 12 | +copies or substantial portions of the Software. |
| 13 | +
|
| 14 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | +SOFTWARE. |
| 21 | + */ |
| 22 | +package testjoltjni.junit; |
| 23 | + |
| 24 | +import com.github.stephengold.joltjni.CollisionGroup; |
| 25 | +import com.github.stephengold.joltjni.GroupFilterTable; |
| 26 | +import com.github.stephengold.joltjni.readonly.ConstCollisionGroup; |
| 27 | +import com.github.stephengold.joltjni.readonly.ConstGroupFilter; |
| 28 | +import org.junit.Assert; |
| 29 | +import org.junit.Test; |
| 30 | +import testjoltjni.TestUtils; |
| 31 | + |
| 32 | +/** |
| 33 | + * Automated JUnit4 tests for creation, destruction, accessors, and defaults of |
| 34 | + * collision-related classes. |
| 35 | + * |
| 36 | + * @author Stephen Gold sgold@sonic.net |
| 37 | + */ |
| 38 | +public class Test018 { |
| 39 | + // ************************************************************************* |
| 40 | + // new methods exposed |
| 41 | + |
| 42 | + /** |
| 43 | + * Test object creation, destruction, accessors, and defaults. |
| 44 | + */ |
| 45 | + @Test |
| 46 | + public void test018() { |
| 47 | + TestUtils.loadNativeLibrary(); |
| 48 | + TestUtils.initializeNativeLibrary(); |
| 49 | + |
| 50 | + doCollisionGroup(); |
| 51 | + |
| 52 | + TestUtils.cleanup(); |
| 53 | + } |
| 54 | + // ************************************************************************* |
| 55 | + // Java private methods |
| 56 | + |
| 57 | + /** |
| 58 | + * Test the {@code CollisionGroup} class. |
| 59 | + */ |
| 60 | + private static void doCollisionGroup() { |
| 61 | + CollisionGroup group = new CollisionGroup(); |
| 62 | + |
| 63 | + testCollisionGroupDefaults(group); |
| 64 | + CollisionGroup copy = new CollisionGroup(group); |
| 65 | + testCollisionGroupSetters(group); |
| 66 | + testCollisionGroupDefaults(copy); |
| 67 | + group.set(copy); |
| 68 | + testCollisionGroupDefaults(group); |
| 69 | + |
| 70 | + TestUtils.testClose(copy, group); |
| 71 | + System.gc(); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Test the getters and defaults of the specified {@code CollisionGroup}. |
| 76 | + * |
| 77 | + * @param group the group to test (not {@code null}, unaffected) |
| 78 | + */ |
| 79 | + private static void testCollisionGroupDefaults(ConstCollisionGroup group) { |
| 80 | + Assert.assertNull(group.getGroupFilter()); |
| 81 | + Assert.assertEquals(CollisionGroup.cInvalidGroup, group.getGroupId()); |
| 82 | + Assert.assertEquals( |
| 83 | + CollisionGroup.cInvalidGroup, group.getSubGroupId()); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Test the setters of the specified {@code CollisionGroup}. |
| 88 | + * |
| 89 | + * @param group the group to test (not {@code null}) |
| 90 | + */ |
| 91 | + private static void testCollisionGroupSetters(CollisionGroup group) { |
| 92 | + GroupFilterTable filter = new GroupFilterTable(); |
| 93 | + group.setGroupFilter(filter); |
| 94 | + group.setGroupId(101); |
| 95 | + group.setSubGroupId(102); |
| 96 | + |
| 97 | + ConstGroupFilter actualFilter = group.getGroupFilter(); |
| 98 | + Assert.assertEquals(filter, actualFilter); |
| 99 | + Assert.assertEquals(101, group.getGroupId()); |
| 100 | + Assert.assertEquals(102, group.getSubGroupId()); |
| 101 | + |
| 102 | + TestUtils.testClose(actualFilter, filter); |
| 103 | + } |
| 104 | +} |
0 commit comments