Skip to content

Commit

Permalink
Add SetDataPduTest unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
leif81 committed Jun 29, 2016
1 parent e0b2f2d commit bdb67db
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/test/java/edu/nps/moves/dis/SetDataPduTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package edu.nps.moves.dis;

import edu.nps.moves.disutil.PduFactory;
import java.io.IOException;
import org.junit.Test;
import static org.junit.Assert.*;

public class SetDataPduTest {

@Test
public void unmarshal() throws IOException {
PduFactory factory = new PduFactory();
Pdu pdu = factory.createPdu(PduFileLoader.load("SetDataPdu-vbs-script-cmd.raw"));

// Expected field values were determined from Wireshark: Decode As -> DIS.
assertEquals(6, pdu.getProtocolVersion());
assertEquals(1, pdu.getExerciseID());
assertEquals(19, pdu.getPduType());
assertEquals(5, pdu.getProtocolFamily());
assertEquals(0, pdu.getTimestamp());
assertEquals(56, pdu.getLength());
assertEquals(0, pdu.getPadding());

SetDataPdu sdpdu = (SetDataPdu) pdu;

assertEquals(0, sdpdu.getOriginatingEntityID().getSite());
assertEquals(0, sdpdu.getOriginatingEntityID().getApplication());
assertEquals(0, sdpdu.getOriginatingEntityID().getEntity());

assertEquals(0, sdpdu.getReceivingEntityID().getSite());
assertEquals(0, sdpdu.getReceivingEntityID().getApplication());
assertEquals(0, sdpdu.getReceivingEntityID().getEntity());

assertEquals(9, sdpdu.getRequestID());

assertEquals(0, sdpdu.getPadding());

assertEquals(0, sdpdu.getNumberOfFixedDatumRecords());
assertEquals(1, sdpdu.getNumberOfVariableDatumRecords());

VariableDatum vd = sdpdu.getVariableDatums().remove(0);
assertEquals(1, vd.getVariableDatumID());
assertEquals(64, vd.getVariableDatumLength());

byte[] datumValue = new byte[(int) vd.getVariableData().size()];
for (int i = 0; i < vd.getVariableData().size(); i++) {
datumValue[i] = vd.getVariableData().get(i).getOtherParameters()[0];
}
assertEquals("allunits", new String(datumValue));
}

@Test
public void marshal() {
SetDataPdu sdpdu = new SetDataPdu();

byte[] buffer = sdpdu.marshal();

assertEquals(buffer.length, sdpdu.getLength());
}
}
Binary file not shown.

0 comments on commit bdb67db

Please sign in to comment.