Skip to content

Commit

Permalink
TESTS: Add tests for waypoint position and orientation
Browse files Browse the repository at this point in the history
The returned angle was negative the value in the toolset. I modified
the check accordingly.
  • Loading branch information
rjshae authored and DrMcCoy committed Jan 12, 2019
1 parent e43a51e commit 21ec875
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 6 deletions.
26 changes: 20 additions & 6 deletions tests/engines/nwn2/waypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include "src/engines/nwn2/waypoint.h"

static const float kEpsilon = 1e-5f;

Engines::NWN2::Waypoint *getWaypoint(const unsigned int index) {
Common::ScopedPtr<Common::MemoryReadStream> stream(new Common::MemoryReadStream(kDataWaypoint));
if (!stream)
Expand All @@ -59,9 +61,6 @@ Engines::NWN2::Waypoint *getWaypoint(const unsigned int index) {
* Expected values:
* -------------------------------------
* Tag = "mapnote1"
* Classification = "{184337}"
* LocalizedName = "Map Note 1"
* Template = "nw_mapnote001"
* MapNoteText = "My note"
* HasMapNote = true
* MapNoteEnabled = true
Expand All @@ -71,11 +70,20 @@ Engines::NWN2::Waypoint *getWaypoint(const unsigned int index) {

GTEST_TEST(NWN2Waypoint, mapnote1) {
Common::ScopedPtr<Engines::NWN2::Waypoint> wp(getWaypoint(0));
float x, y, z, angle;

EXPECT_STREQ(wp->getTag().c_str(), "mapnote1");
EXPECT_TRUE(wp->hasMapNote());
EXPECT_TRUE(wp->enabledMapNote());
EXPECT_STREQ(wp->getMapNote().c_str(), "[???]"); // Should be "My note"

wp->getPosition(x, y, z);
EXPECT_TRUE(abs(x - 6.743333) < kEpsilon);
EXPECT_TRUE(abs(y - 4.81983) < kEpsilon);
EXPECT_TRUE(abs(z) < kEpsilon);

wp->getOrientation(x, y, z, angle);
EXPECT_TRUE(abs(angle - (-31.5129414)) < kEpsilon);
}

/**
Expand All @@ -84,9 +92,6 @@ GTEST_TEST(NWN2Waypoint, mapnote1) {
* Expected values:
* -------------------------------------
* Tag = "waypoint1"
* Classification = "{184337}"
* LocalizedName = "Waypoint 1"
* Template = "nw_waypoint001"
* HasMapNote = false
* MapNoteEnabled = false
* X/Y/ZPosition = 3.91353, 5.69942, 0
Expand All @@ -95,9 +100,18 @@ GTEST_TEST(NWN2Waypoint, mapnote1) {

GTEST_TEST(NWN2Waypoint, waypoint1) {
Common::ScopedPtr<Engines::NWN2::Waypoint> wp(getWaypoint(1));
float x, y, z, angle;

EXPECT_STREQ(wp->getTag().c_str(), "waypoint1");
EXPECT_FALSE(wp->hasMapNote());
EXPECT_FALSE(wp->enabledMapNote());
EXPECT_STREQ(wp->getMapNote().c_str(), "");

wp->getPosition(x, y, z);
EXPECT_TRUE(abs(x - 3.91353) < kEpsilon);
EXPECT_TRUE(abs(y - 5.69942) < kEpsilon);
EXPECT_TRUE(abs(z) < kEpsilon);

wp->getOrientation(x, y, z, angle);
EXPECT_TRUE(abs(angle - 33.80449) < kEpsilon);
}
127 changes: 127 additions & 0 deletions tests/engines/nwn2/waypoint_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<gff3 type="GIT">
<struct id="4294967295">
<list label="Encounter List"/>
<list label="PlacedFXList"/>
<list label="TreeList"/>
<list label="StaticCameraList"/>
<struct label="AreaProperties" id="0">
<sint32 label="AmbientSndNitVol">0</sint32>
<sint32 label="MusicBattle">0</sint32>
<sint32 label="MusicNight">0</sint32>
<sint32 label="AmbientSndNight">0</sint32>
<sint32 label="MusicDelay">500</sint32>
<sint32 label="EnvAudio">0</sint32>
<sint32 label="AmbientSndDayVol">0</sint32>
<sint32 label="AmbientSndDay">0</sint32>
<sint32 label="MusicDay">0</sint32>
</struct>
<list label="TreasureList"/>
<list label="List"/>
<list label="Creature List"/>
<list label="LightList"/>
<list label="StoreList"/>
<list label="WaypointList">
<struct id="5">
<float label="ZPosition">0.000000</float>
<data label="GUID">h9aPiiOz4kWOH9yAc89+pg==</data>
<exostring label="Tag">mapnote1</exostring>
<locstring label="LocalizedName" strref="14814">
<string language="0">Map Note 1</string>
</locstring>
<resref label="TemplateResRef">nw_mapnote001</resref>
<float label="XOrientation">0.522690</float>
<exostring label="LinkedTo"></exostring>
<exostring label="Classification">{184337}</exostring>
<locstring label="Description" strref="4294967295"/>
<list label="VarTable"/>
<struct label="Tintable" id="0">
<struct label="Tint" id="0">
<struct label="1" id="0">
<byte label="r">255</byte>
<byte label="a">255</byte>
<byte label="b">255</byte>
<byte label="g">255</byte>
</struct>
<struct label="2" id="0">
<byte label="r">255</byte>
<byte label="a">255</byte>
<byte label="b">255</byte>
<byte label="g">255</byte>
</struct>
<struct label="3" id="0">
<byte label="r">255</byte>
<byte label="a">255</byte>
<byte label="b">255</byte>
<byte label="g">255</byte>
</struct>
</struct>
</struct>
<byte label="Stackable">0</byte>
<float label="XPosition">6.743330</float>
<locstring label="MapNote" strref="14815">
<string language="0">My note</string>
</locstring>
<float label="YPosition">4.819830</float>
<byte label="HeightLock">0</byte>
<byte label="MapNoteEnabled">1</byte>
<float label="YOrientation">0.852520</float>
<byte label="Appearance">0</byte>
<byte label="HasMapNote">1</byte>
<byte label="PositionLock">0</byte>
</struct>
<struct id="5">
<float label="ZPosition">0.000000</float>
<data label="GUID">vzG3flnuL0CNLwWyjSt79Q==</data>
<exostring label="Tag">waypoint1</exostring>
<locstring label="LocalizedName" strref="14817">
<string language="0">Waypoint 1</string>
</locstring>
<resref label="TemplateResRef">nw_waypoint001</resref>
<float label="XOrientation">-0.556360</float>
<exostring label="LinkedTo"></exostring>
<exostring label="Classification">{184337}</exostring>
<locstring label="Description" strref="4294967295"/>
<list label="VarTable"/>
<struct label="Tintable" id="0">
<struct label="Tint" id="0">
<struct label="1" id="0">
<byte label="r">0</byte>
<byte label="a">255</byte>
<byte label="b">255</byte>
<byte label="g">0</byte>
</struct>
<struct label="2" id="0">
<byte label="r">0</byte>
<byte label="a">255</byte>
<byte label="b">255</byte>
<byte label="g">0</byte>
</struct>
<struct label="3" id="0">
<byte label="r">0</byte>
<byte label="a">255</byte>
<byte label="b">255</byte>
<byte label="g">0</byte>
</struct>
</struct>
</struct>
<byte label="Stackable">0</byte>
<float label="XPosition">3.913530</float>
<locstring label="MapNote" strref="4294967295"/>
<float label="YPosition">5.699420</float>
<byte label="HeightLock">0</byte>
<byte label="MapNoteEnabled">0</byte>
<float label="YOrientation">0.830940</float>
<byte label="Appearance">0</byte>
<byte label="HasMapNote">0</byte>
<byte label="PositionLock">0</byte>
</struct>
</list>
<list label="Placeable List"/>
<list label="SoundList"/>
<list label="TriggerList"/>
<list label="EnvironmentList"/>
<list label="Door List"/>
<list label="VarTable"/>
</struct>
</gff3>

0 comments on commit 21ec875

Please sign in to comment.