diff --git a/test/edu/nps/moves/dis7/CommentPdusTest.java b/test/edu/nps/moves/dis7/CommentPdusTest.java index c920ecee249d38de9891d4e9002fd7b5766867e0..1c680b5d7ecde60b61a49dc02f4a47600c0c2d94 100644 --- a/test/edu/nps/moves/dis7/CommentPdusTest.java +++ b/test/edu/nps/moves/dis7/CommentPdusTest.java @@ -50,6 +50,7 @@ public class CommentPdusTest disNetworkInterface = null; } + /** Test PDU sending, receiving, marshalling (serialization) and unmarshalling (deserialization) */ @Test public void testRoundTrip() { @@ -66,6 +67,8 @@ public class CommentPdusTest testOne(pduFactory.makeCommentReliablePdu("xyz R first message","mno R second message", "jkl R third message")); } + /** Test single PDU for correctness according to all contained fields in this PDU type + * @param newPdu PDU of interest */ private void testOne(Pdu newPdu) { sendPdu(newPdu); // will wait a while diff --git a/test/edu/nps/moves/dis7/EntityStatePduTest.java b/test/edu/nps/moves/dis7/EntityStatePduTest.java index 3411e9b961d5fbad743632890354b8034c9a8a17..5cb59bb29004125773dd53962eea082148c76d1a 100644 --- a/test/edu/nps/moves/dis7/EntityStatePduTest.java +++ b/test/edu/nps/moves/dis7/EntityStatePduTest.java @@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.*; @DisplayName("Entity State Pdu Test") public class EntityStatePduTest extends PduTest { + /** Test PDU sending, receiving, marshalling (serialization) and unmarshalling (deserialization) */ @Test @Override public void testRoundTrip() @@ -48,6 +49,8 @@ public class EntityStatePduTest extends PduTest testOnePdu(espdu.setEntityID(entityID).setEntityType(entityType)); } + /** Test single PDU for correctness according to all contained fields in this PDU type + * @param newPdu PDU of interest*/ @Override protected void testOnePdu(Pdu newPdu) { diff --git a/test/edu/nps/moves/dis7/FirePduTest.java b/test/edu/nps/moves/dis7/FirePduTest.java new file mode 100644 index 0000000000000000000000000000000000000000..4ac78e6974302a0b86fa5daecf8dba83536876fd --- /dev/null +++ b/test/edu/nps/moves/dis7/FirePduTest.java @@ -0,0 +1,120 @@ +/** + * Copyright (c) 2008-2020, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved. + * This work is provided under a BSD open-source license, see project license.html and license.txt + */ +package edu.nps.moves.dis7; + +import edu.nps.moves.dis7.entities.usa.munition.other.M1A2; +import edu.nps.moves.dis7.enumerations.Country; +import edu.nps.moves.dis7.enumerations.EntityKind; +import edu.nps.moves.dis7.utilities.PduFactory; +import edu.nps.moves.dis7.enumerations.PlatformDomain; +import edu.nps.moves.dis7.pdus.Domain; +import edu.nps.moves.dis7.pdus.EntityID; +import edu.nps.moves.dis7.pdus.FirePdu; +import edu.nps.moves.dis7.pdus.EntityType; +import edu.nps.moves.dis7.pdus.Pdu; +import edu.nps.moves.dis7.pdus.PduBase; +import org.junit.jupiter.api.*; +import static org.junit.jupiter.api.Assertions.*; + +@DisplayName("Fire Pdu Test") +public class FirePduTest extends PduTest +{ + /** Test PDU sending, receiving, marshalling (serialization) and unmarshalling (deserialization) */ + @Test + @Override + public void testRoundTrip() + { + PduFactory pduFactory = new PduFactory(); + + FirePdu firePdu = pduFactory.makeFirePdu(); + // TODO alternate constructors and utility methods + EntityID entityID = new EntityID().setSiteID((short)1).setApplicationID((short)2).setEntityID((short)3); + EntityType entityType = new EntityType() + .setEntityKind (EntityKind.PLATFORM).setEntityKind(EntityKind.PLATFORM) //(short) 1); // Platform (vs lifeform, munition, sensor, etc.); //(short) 1); // Platform (vs lifeform, munition, sensor, etc.) + .setCountry (Country.UNITED_STATES_OF_AMERICA_USA) // 225 USA + .setDomain (Domain.inst(PlatformDomain.LAND)) // Land (vs air, surface, subsurface, space) + .setCategory ((byte) 1) // Tank + .setSubCategory((byte) 1) // M1 Abrams + .setSpecific ((byte) 3); // M1A2 Abrams + + // TODO update PDU-specific tests + +// firePdu.setEntityType(entityType); +// // Alternate way using entity jar(s) +// firePdu.setEntityType(new edu.nps.moves.dis7.entities.usa.platform.land.M1A2()); +// // or simply use an enumeration by name, with accompanying import statement above +// firePdu.setEntityType(new M1A2()); +// +// testOnePdu(firePdu); +// testOnePdu(firePdu.setEntityID(entityID).setEntityType(entityType)); + } + + /** Test single PDU for correctness according to all contained fields in this PDU type + * @param newPdu PDU of interest */ + @Override + protected void testOnePdu(Pdu newPdu) + { + sendPdu(newPdu); // will wait a while + assertTrue(receivedPdu != null, "No response from network receive"); + + assertEquals ( newPdu.getProtocolVersion(), receivedPdu.getProtocolVersion(), "mismatched ProtocolVersion"); + // TODO compatibility version + assertEquals ( newPdu.getExerciseID(), receivedPdu.getExerciseID(), "mismatched ExerciseID"); + assertEquals ( newPdu.getPduType(), receivedPdu.getPduType(), "mismatched PduType"); + assertEquals ( newPdu.getProtocolFamily(), receivedPdu.getProtocolFamily(), "mismatched ProtocolFamily"); // derived from PduType + assertEquals(((PduBase)newPdu).getPduStatus(), ((PduBase)receivedPdu).getPduStatus(), "mismatched PduStatus"); + assertEquals(((PduBase)newPdu).getPadding(), ((PduBase)receivedPdu).getPadding(), "mismatched header padding"); + // TODO HDR length + assertEquals (newPdu.getTimestamp(), receivedPdu.getTimestamp(), "mismatched Timestamp"); + + // can cast PDUs at this point since PduType matched + FirePdu newEspdu = (FirePdu) newPdu; + FirePdu receivedEspdu = (FirePdu) newPdu; +// assertEquals (newEspdu.getEntityID(), receivedEspdu.getEntityID(), "mismatched EntityID"); +// // TODO Sequence number +// assertEquals (newEspdu.getEntityType(), receivedEspdu.getEntityType(), "mismatched EntityType"); +// // padding? +// assertEquals (newEspdu.getEntityAppearance(), receivedEspdu.getEntityAppearance(), "mismatched EntityAppearance"); +// assertEquals (newEspdu.getCapabilities(), receivedEspdu.getCapabilities(), "mismatched EntityCapabilities"); +// assertEquals (newEspdu.getEntityLocation(), receivedEspdu.getEntityLocation(), "mismatched EntityLocation"); +// assertEquals (newEspdu.getEntityOrientation(), receivedEspdu.getEntityOrientation(), "mismatched EntityOrientation"); +// assertEquals (newEspdu.getForceId(), receivedEspdu.getForceId(), "mismatched EntityForceId"); +// assertEquals (newEspdu.getMarking(), receivedEspdu.getMarking(), "mismatched Marking"); +// assertEquals (newEspdu.getDeadReckoningParameters(), receivedEspdu.getDeadReckoningParameters(), "mismatched DeadReckoningParameters"); +// +// // attached parts, utility method for NumberVariableParameters +// assertEquals (newEspdu.getVariableParameters(), receivedEspdu.getVariableParameters(), "mismatched VariableParameters"); +// assertEquals (newEspdu.getEntityLinearVelocity(), receivedEspdu.getEntityLinearVelocity(), "mismatched EntityLinearVelocity"); + + // trace option to compare strings, JSON or XML + if (false) // true || !newEspdu.toString().equals(receivedEspdu.toString())) + { + System.err.println(" newEspdu=" + newEspdu.toString()); + System.err.println("receivedEspdu=" + receivedEspdu.toString()); + } + assertEquals (newEspdu.toString(), receivedEspdu.toString(), "mismatched toString()"); + // built-in object comparison + assertTrue (newEspdu.equalsImpl(receivedEspdu), "FirePdu.equalsImpl() built-in object comparison"); + // final recheck that everything adds up + assertEquals(newPdu.getMarshalledSize(),receivedPdu.getMarshalledSize(), + "Marshalled size mismatch," + + "sent (" + newPdu.getMarshalledSize() + " bytes) and " + + "recieved (" + receivedPdu.getMarshalledSize() + " bytes)"); + assertEquals (newPdu.getLength(), receivedPdu.getLength(), "mismatched length"); // from Pdu superclass + +// comparison of class Pdu is questionable +// assertTrue(compare(newPdu,receivedPdu), "compare() method failed for original and received PDUs"); + receivedPdu = null; // ensure cleared prior to next test + } + + public static void main(String[] args) + { + FirePduTest firePduTest = new FirePduTest(); + + firePduTest.setUp(); + firePduTest.testRoundTrip(); + firePduTest.tearDown(); + } +} diff --git a/test/edu/nps/moves/dis7/PduTest.java b/test/edu/nps/moves/dis7/PduTest.java index 49aa3301c001cc5cfd6f4e8da52c70435b55cb2b..3b1b4568d5b9f3078f6b8a10d83b38caf991b824 100644 --- a/test/edu/nps/moves/dis7/PduTest.java +++ b/test/edu/nps/moves/dis7/PduTest.java @@ -99,9 +99,16 @@ abstract public class PduTest } } + /** Compare all values of these two obects and report if identical + * @param pdu1 first pdu + * @param pdu2 second pdu + * @return true if identical values found */ protected boolean compare(Pdu pdu1, Pdu pdu2) { - return pdu1.equalsImpl(pdu2); + boolean result = (pdu1 != null) && (pdu2 != null) && + pdu1.getPduType().equals(pdu2.getPduType()) && + pdu1.equalsImpl(pdu2); + return result; } protected void setUpReceiver(Pdu newPdu) @@ -109,8 +116,11 @@ abstract public class PduTest receivedPdu = newPdu; } + /** Test PDU sending, receiving, marshalling (serialization) and unmarshalling (deserialization) */ public abstract void testRoundTrip(); + /** Test single PDU for correctness according to all contained fields in this PDU type + * @param newPdu PDU of interest*/ protected abstract void testOnePdu(Pdu newPdu); }