Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity and Receiver Pdu tests (DIS 6) #23

Merged
merged 3 commits into from
Apr 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 86 additions & 11 deletions src/test/java/edu/nps/moves/dis/EntityStatePduTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package edu.nps.moves.dis;

import edu.nps.moves.disutil.PduFactory;
import java.io.IOException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
Expand Down Expand Up @@ -53,12 +50,90 @@ public void testMobility()
espdu.setEntityAppearance_mobility(1);
mobility = espdu.getEntityAppearance_mobility();
assert(mobility == 1);

}

// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
// @Test
// public void hello() {}
@Test
public void unmarshal() throws IOException {
PduFactory factory = new PduFactory();
Pdu pdu = factory.createPdu(PduFileLoader.load("EntityStatePdu-26.raw"));

// Expected field values were determined from Wireshark: Decode As -> DIS.

// Header
assertEquals(6, pdu.getProtocolVersion());
assertEquals(7, pdu.getExerciseID());
assertEquals(1, pdu.getPduType());
assertEquals(1, pdu.getProtocolFamily());
//TODO assertEquals((long) ???, aPdu.getTimestamp());
assertEquals(144, pdu.getLength());
assertEquals(0, pdu.getPadding());

EntityStatePdu espdu = (EntityStatePdu) pdu;

// Entity ID
assertEquals(42, espdu.getEntityID().getSite());
assertEquals(4, espdu.getEntityID().getApplication());
assertEquals(26, espdu.getEntityID().getEntity());

// Force ID
assertEquals(1, espdu.getForceId());

// Articulation Parameters
assertEquals(0, espdu.getArticulationParameters().size());

// Entity Type (aka DIS Enumeration)
assertEquals(1, espdu.getEntityType().getEntityKind());
assertEquals(1, espdu.getEntityType().getDomain());
assertEquals(39, espdu.getEntityType().getCountry());
assertEquals(7, espdu.getEntityType().getCategory());
assertEquals(2, espdu.getEntityType().getSubcategory());
assertEquals(1, espdu.getEntityType().getSpec());
assertEquals(0, espdu.getEntityType().getExtra());

// Alternative Entity Type
assertEquals(1, espdu.getAlternativeEntityType().getEntityKind());
assertEquals(1, espdu.getAlternativeEntityType().getDomain());
assertEquals(39, espdu.getAlternativeEntityType().getCountry());
assertEquals(7, espdu.getAlternativeEntityType().getCategory());
assertEquals(2, espdu.getAlternativeEntityType().getSubcategory());
assertEquals(1, espdu.getAlternativeEntityType().getSpec());
assertEquals(0, espdu.getAlternativeEntityType().getExtra());

// Entity Linear Velocity
assertEquals(0, espdu.getEntityLinearVelocity().getX(), 0);
assertEquals(0, espdu.getEntityLinearVelocity().getY(), 0);
assertEquals(0, espdu.getEntityLinearVelocity().getZ(), 0);

// Entity Location
assertEquals(4374082.80485589, espdu.getEntityLocation().getX(), 0.001);
assertEquals(1667679.95730107, espdu.getEntityLocation().getY(), 0.001);
assertEquals(4318284.36890269, espdu.getEntityLocation().getZ(), 0.001);

// Entity Orientation
assertEquals(1.93505, espdu.getEntityOrientation().getPsi(), 0.001);
assertEquals(0, espdu.getEntityOrientation().getTheta(), 0.001);
assertEquals(-2.31924, espdu.getEntityOrientation().getPhi(), 0.001);

// Entity Appearance
assertEquals(0, espdu.getEntityAppearance_paintScheme());
assertEquals(0, espdu.getEntityAppearance_mobility());
assertEquals(0, espdu.getEntityAppearance_firepower());

// Dead Reckoning Parameters
// TODO assertEquals(???, espdu.getDeadReckoningParameters());
// Entity Marking
assertEquals("26", new String(espdu.getMarking().getCharacters()).trim());

// Capabilities
assertEquals(0, espdu.getCapabilities());
}

@Test
public void marshal() {
EntityStatePdu espdu = new EntityStatePdu();

byte[] buffer = espdu.marshal();

assertEquals(buffer.length, espdu.getLength());
}
}
10 changes: 6 additions & 4 deletions src/test/java/edu/nps/moves/dis/MarkingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ public void MarkingToLongTest()
{
EntityStatePdu espdu = new EntityStatePdu();
Marking marking = espdu.getMarking();
//marking.setCharacters("This is a marking that is much, much too loong");
final String s = new String("This is a marking that is much, much too loong");
marking.setCharacters(s.getBytes());
byte[] buff = marking.getCharacters();
assertEquals(buff.length, 11);
assertEquals(buff.length, s.length());
}

@Test
public void MarkingToShortTest()
{
EntityStatePdu espdu = new EntityStatePdu();
Marking marking = espdu.getMarking();
//marking.setCharacters("short");
final String s = new String("short");
marking.setCharacters(s.getBytes());
byte[] buff = marking.getCharacters();
assertEquals(buff.length, 11);
assertEquals(buff.length, s.length());
}

@Before
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/edu/nps/moves/dis/ReceiverPduTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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 ReceiverPduTest {

@Test
public void unmarshal() throws IOException {
PduFactory factory = new PduFactory();
Pdu pdu = factory.createPdu(PduFileLoader.load("ReceiverPdu.raw"));

// Expected field values were determined from Wireshark: Decode As -> DIS.
assertEquals(6, pdu.getProtocolVersion());
assertEquals(1, pdu.getExerciseID());
assertEquals(27, pdu.getPduType());
assertEquals(4, pdu.getProtocolFamily());
//FIXME is timestamp wrong? assertEquals((long) 0, aPdu.getTimestamp());
assertEquals(36, pdu.getLength());
assertEquals(0, pdu.getPadding());

ReceiverPdu rpdu = (ReceiverPdu) pdu;

assertEquals(1, rpdu.getEntityId().getSite());
assertEquals(1, rpdu.getEntityId().getApplication());
assertEquals(0, rpdu.getEntityId().getEntity());

assertEquals(2, rpdu.getRadioId());

assertEquals(2, rpdu.getReceiverState());
assertEquals(0, rpdu.getReceivedPower(), 0);

assertEquals(0, rpdu.getPadding());

assertEquals(99, rpdu.getTransmitterRadioId());
assertEquals(999, rpdu.getTransmitterEntityId().getEntity());
assertEquals(1, rpdu.getTransmitterEntityId().getSite());
assertEquals(1, rpdu.getTransmitterEntityId().getApplication());
}

@Test
public void marshal() {
ReceiverPdu rpdu = new ReceiverPdu();

byte[] buffer = rpdu.marshal();

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