Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
7c1846b9
Commit
7c1846b9
authored
4 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
upgrade test to match CommentsPduTest, TODO extract abstract interfaces
parent
b778d661
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/edu/nps/moves/dis7/EntityStatePduTest.java
+78
-9
78 additions, 9 deletions
test/edu/nps/moves/dis7/EntityStatePduTest.java
with
78 additions
and
9 deletions
test/edu/nps/moves/dis7/EntityStatePduTest.java
+
78
−
9
View file @
7c1846b9
...
@@ -4,13 +4,22 @@
...
@@ -4,13 +4,22 @@
*/
*/
package
edu.nps.moves.dis7
;
package
edu.nps.moves.dis7
;
import
edu.nps.moves.dis7.enumerations.LandPlatformCapabilities
;
import
edu.nps.moves.dis7.entities.usa.platform.land.M1A2
;
import
edu.nps.moves.dis7.enumerations.Country
;
import
edu.nps.moves.dis7.enumerations.EntityKind
;
import
edu.nps.moves.dis7.utilities.DisThreadedNetIF
;
import
edu.nps.moves.dis7.utilities.PduFactory
;
import
edu.nps.moves.dis7.enumerations.PlatformDomain
;
import
org.junit.jupiter.api.*
;
import
org.junit.jupiter.api.*
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
@DisplayName
(
"Entity State Pdu Test"
)
@DisplayName
(
"Entity State Pdu Test"
)
public
class
EntityStatePduTest
public
class
EntityStatePduTest
{
{
DisThreadedNetIF
disThreadedNetworkInterface
;
Pdu
receivedPdu
;
DisThreadedNetIF
.
PduListener
pduListener
;
@BeforeAll
@BeforeAll
public
static
void
setUpClass
()
public
static
void
setUpClass
()
{
{
...
@@ -25,29 +34,89 @@ public class EntityStatePduTest
...
@@ -25,29 +34,89 @@ public class EntityStatePduTest
@BeforeEach
@BeforeEach
public
void
setUp
()
public
void
setUp
()
{
{
disThreadedNetworkInterface
=
new
DisThreadedNetIF
();
pduListener
=
new
DisThreadedNetIF
.
PduListener
()
{
@Override
public
void
incomingPdu
(
Pdu
newPdu
)
{
setUpReceiver
(
newPdu
);
}
};
disThreadedNetworkInterface
.
addListener
(
pduListener
);
}
}
@AfterEach
@AfterEach
public
void
tearDown
()
public
void
tearDown
()
{
{
disThreadedNetworkInterface
.
removeListener
(
pduListener
);
disThreadedNetworkInterface
.
kill
();
disThreadedNetworkInterface
=
null
;
}
}
@Test
@Test
public
void
testEntityCapabilities
()
public
void
testRoundTrip
()
{
PduFactory
pduFactory
=
new
PduFactory
();
EntityStatePdu
espdu
=
pduFactory
.
makeEntityStatePdu
();
// 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
espdu
.
setEntityType
(
entityType
);
// Alternate way using entity jar(s)
espdu
.
setEntityType
(
new
edu
.
nps
.
moves
.
dis7
.
entities
.
usa
.
platform
.
land
.
M1A2
());
// or simply use an enumeration by name, with accompanying import statement above
espdu
.
setEntityType
(
new
M1A2
());
testOne
(
espdu
);
testOne
(
espdu
.
setEntityID
(
entityID
).
setEntityType
(
entityType
));
}
private
void
testOne
(
Pdu
newPdu
)
{
sendPdu
(
newPdu
);
// will wait a while
assertTrue
(
receivedPdu
!=
null
,
"No response from network receive"
);
assertTrue
(
compare
(
newPdu
,
receivedPdu
),
"Comparison failed"
);
assertEqual
(
newPdu
.
getMarshalledSize
(),
receivedPdu
),
getMarshalledSize
(),
"Marshalled size mismatch,"
+
"sent ("
+
newPdu
.
getMarshalledSize
()
+
" bytes) and "
+
"recieved ("
+
receivedPdu
.
getMarshalledSize
()
+
" bytes)"
);
receivedPdu
=
null
;
// ensure cleared prior to next test
}
private
void
sendPdu
(
Pdu
pdu
)
{
{
Throwable
thr
=
null
;
try
{
try
{
EntityStatePdu
espdu
=
new
EntityStatePdu
(
);
disThreadedNetworkInterface
.
send
(
pdu
);
espdu
.
setCapabilities
(
new
LandPlatformCapabilities
()
);
Thread
.
sleep
(
100
);
}
}
catch
(
Throwable
t
)
{
catch
(
InterruptedException
ex
)
{
thr
=
t
;
System
.
err
.
println
(
"Error sending Multicast: "
+
ex
.
getLocalizedMessage
());
System
.
exit
(
1
);
}
}
assertNull
(
thr
,
"Exception indicates error creating EntityStatePdu"
);
}
private
boolean
compare
(
Pdu
pdu1
,
Pdu
pdu2
)
{
return
pdu1
.
equals
(
pdu2
);
}
private
void
setUpReceiver
(
Pdu
newPdu
)
{
receivedPdu
=
newPdu
;
}
}
public
static
void
main
(
String
[]
args
)
public
static
void
main
(
String
[]
args
)
{
{
new
EntityStatePduTest
().
testEntityCapabilities
();
EntityStatePduTest
entityStatePduTest
=
new
EntityStatePduTest
();
entityStatePduTest
.
setUp
();
entityStatePduTest
.
testRoundTrip
();
entityStatePduTest
.
tearDown
();
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment