6 new tests for CapturePointSystem have been created!

TODO: refactor CapturePointSystem
This commit is contained in:
verysecrethero
2016-01-13 14:37:56 +01:00
parent 7a8604bf2b
commit ed5ac2e923
2 changed files with 354 additions and 31 deletions
+339 -30
View File
@@ -10,12 +10,11 @@ using boost::unit_test_framework::test_case;
#include "Core/EntityFileWriter.h" #include "Core/EntityFileWriter.h"
#include "Game/CapturePointSystem.h" #include "Game/CapturePointSystem.h"
BOOST_AUTO_TEST_SUITE(ShootEventTestSuite) BOOST_AUTO_TEST_SUITE(CapturePointTestSuite)
//dont use the same name as the classname in test cases... //dont use the same name as the classname in test cases...
BOOST_AUTO_TEST_CASE(CapturePointTest1) BOOST_AUTO_TEST_CASE(CapturePointTest1_OnePlayerOnCapturePoint)
{ {
//Test firing primary weapon
CapturePointTest game(1); CapturePointTest game(1);
//100 loops will be more than enough to do the test //100 loops will be more than enough to do the test
int loops = 100; int loops = 100;
@@ -29,7 +28,93 @@ BOOST_AUTO_TEST_CASE(CapturePointTest1)
loops--; loops--;
} }
//The system will process the events, hence it will take a while before we can read anything //The system will process the events, hence it will take a while before we can read anything
success = true; BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest2_TwoPlayersOnCapturePoint)
{
CapturePointTest game(2);
//100 loops will be more than enough to do the test
int loops = 100;
bool success = false;
while (loops > 0) {
game.Tick();
if (game.TestSucceeded) {
success = true;
break;
}
loops--;
}
//The system will process the events, hence it will take a while before we can read anything
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest3_NoPlayersOnCapturePoint)
{
CapturePointTest game(3);
//100 loops will be more than enough to do the test
int loops = 100;
bool success = false;
while (loops > 0) {
game.Tick();
//successCheck needs to know when were close to 100 to check if anything happened then (NumLoops)
game.NumLoops++;
if (game.TestSucceeded) {
success = true;
break;
}
loops--;
}
//The system will process the events, hence it will take a while before we can read anything
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest4_TwoCapturePointsBeingCaptured)
{
CapturePointTest game(4);
//100 loops will be more than enough to do the test
int loops = 100;
bool success = false;
while (loops > 0) {
game.Tick();
if (game.TestSucceeded) {
success = true;
break;
}
loops--;
}
//The system will process the events, hence it will take a while before we can read anything
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest5_SameCapturePointContestedAndTakenOver)
{
CapturePointTest game(5);
//100 loops will be more than enough to do the test
int loops = 100;
bool success = false;
while (loops > 0) {
game.Tick();
if (game.TestSucceeded) {
success = true;
break;
}
loops--;
}
//The system will process the events, hence it will take a while before we can read anything
BOOST_TEST(success);
}
BOOST_AUTO_TEST_CASE(CapturePointTest6_Team1CapturedTheLastPointAndWon)
{
CapturePointTest game(6);
//100 loops will be more than enough to do the test
int loops = 100;
bool success = false;
while (loops > 0) {
game.Tick();
if (game.TestSucceeded) {
success = true;
break;
}
loops--;
}
//The system will process the events, hence it will take a while before we can read anything
BOOST_TEST(success); BOOST_TEST(success);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
@@ -65,8 +150,7 @@ CapturePointTest::CapturePointTest(int runTestNumber)
fp.MergeEntities(m_World); fp.MergeEntities(m_World);
} }
//The Test //create 2 players and 3 capturepoints for testing
//create entity which has transform,player,model,health in it. i.e. is a player
EntityID playerID = m_World->CreateEntity(); EntityID playerID = m_World->CreateEntity();
m_PlayerID = playerID; m_PlayerID = playerID;
ComponentWrapper& player = m_World->AttachComponent(playerID, "Player"); ComponentWrapper& player = m_World->AttachComponent(playerID, "Player");
@@ -89,32 +173,42 @@ CapturePointTest::CapturePointTest(int runTestNumber)
EntityID capturePointID2 = m_World->CreateEntity(); EntityID capturePointID2 = m_World->CreateEntity();
ComponentWrapper& capturePoint2 = m_World->AttachComponent(capturePointID2, "CapturePoint"); ComponentWrapper& capturePoint2 = m_World->AttachComponent(capturePointID2, "CapturePoint");
//this capturePoint is homeBase for team 1 //this capturePoint is homeBase for team 1
capturePoint2["IsHomeCapturePointForTeamNumber"] = 1; capturePoint2["IsHomeCapturePointForTeamNumber"] = 0;
capturePoint2["CapturePointNumber"] = 1; capturePoint2["CapturePointNumber"] = 1;
m_CapturePointID2 = capturePointID2; m_CapturePointID2 = capturePointID2;
EntityID capturePointID3 = m_World->CreateEntity();
ComponentWrapper& capturePoint3 = m_World->AttachComponent(capturePointID3, "CapturePoint");
//this capturePoint is homeBase for team 1
capturePoint3["IsHomeCapturePointForTeamNumber"] = 1;
capturePoint3["CapturePointNumber"] = 2;
m_CapturePointID3 = capturePointID3;
m_RunTestNumber = runTestNumber; m_RunTestNumber = runTestNumber;
//add some touch/leave events //add some touch/leave events
Events::TriggerTouch eTriggerTouched; switch (runTestNumber)
eTriggerTouched.Entity = m_PlayerID; {
eTriggerTouched.Trigger = m_CapturePointID; case 1:
m_EventBroker->Publish(eTriggerTouched); TestSetup1_OnePlayerOnCapturePoint();
break;
//Events::TriggerTouch eTriggerTouched2; case 2:
//eTriggerTouched2.Entity = m_PlayerID2; TestSetup2_TwoPlayersOnCapturePoint();
//eTriggerTouched2.Trigger = m_CapturePointID; break;
//m_EventBroker->Publish(eTriggerTouched2); case 3:
TestSetup3_NoPlayersOnCapturePoint();
Events::TriggerLeave eTriggerLeft; break;
eTriggerLeft.Entity = m_PlayerID; case 4:
eTriggerLeft.Trigger = m_CapturePointID; TestSetup4_TwoCapturePointsBeingCaptured();
m_EventBroker->Publish(eTriggerLeft); break;
case 5:
Events::TriggerTouch eTriggerTouched3; TestSetup5_SameCapturePointContestedAndTakenOver();
eTriggerTouched3.Entity = m_PlayerID; break;
eTriggerTouched3.Trigger = m_CapturePointID2; case 6:
m_EventBroker->Publish(eTriggerTouched3); TestSetup6_Team1CapturedTheLastPointAndWon();
break;
default:
break;
}
//init glfw so dt works //init glfw so dt works
glfwInit(); glfwInit();
@@ -127,13 +221,205 @@ CapturePointTest::~CapturePointTest()
delete m_EventBroker; delete m_EventBroker;
} }
void CapturePointTest::TestSetup1_OnePlayerOnCapturePoint()
{
Events::TriggerTouch touchEvent;
Events::TriggerLeave leaveEvent;
//player touches,leaves,touches m_CapturePointID. and enters m_CapturePointID3
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(touchEvent);
leaveEvent.Entity = m_PlayerID;
leaveEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(leaveEvent);
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(touchEvent);
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID3;
m_EventBroker->Publish(touchEvent);
}
void CapturePointTest::TestSetup2_TwoPlayersOnCapturePoint()
{
Events::TriggerTouch touchEvent;
Events::TriggerLeave leaveEvent;
//player touches,leaves m_CapturePointID. and enters m_CapturePointID3
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(touchEvent);
leaveEvent.Entity = m_PlayerID;
leaveEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(leaveEvent);
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID3;
m_EventBroker->Publish(touchEvent);
//player2 touches m_CapturePointID,m_CapturePointID2
touchEvent.Entity = m_PlayerID2;
touchEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(touchEvent);
touchEvent.Entity = m_PlayerID2;
touchEvent.Trigger = m_CapturePointID2;
m_EventBroker->Publish(touchEvent);
}
void CapturePointTest::TestSetup3_NoPlayersOnCapturePoint()
{
Events::TriggerTouch touchEvent;
Events::TriggerLeave leaveEvent;
//player1 touches and leaves m_CapturePointID
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(touchEvent);
leaveEvent.Entity = m_PlayerID;
leaveEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(leaveEvent);
//player2 touches and leaves m_CapturePointID2
touchEvent.Entity = m_PlayerID2;
touchEvent.Trigger = m_CapturePointID2;
m_EventBroker->Publish(touchEvent);
leaveEvent.Entity = m_PlayerID2;
leaveEvent.Trigger = m_CapturePointID2;
m_EventBroker->Publish(leaveEvent);
}
void CapturePointTest::TestSetup4_TwoCapturePointsBeingCaptured()
{
Events::TriggerTouch touchEvent;
//player1 touches m_CapturePointID3
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID3;
m_EventBroker->Publish(touchEvent);
//player2 touches m_CapturePointID
touchEvent.Entity = m_PlayerID2;
touchEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(touchEvent);
}
void CapturePointTest::TestSetup5_SameCapturePointContestedAndTakenOver()
{
//NOTE: setup events need to trigger first then the real event will be allowed by the system later
Events::TriggerTouch touchEvent;
//"SETUP" homebase->same capturep
//player1 touches m_CapturePointID3
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID3;
m_EventBroker->Publish(touchEvent);
//player2 touches m_CapturePointID
touchEvent.Entity = m_PlayerID2;
touchEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(touchEvent);
//contested same, player1 touches the contested
//player1 touches m_CapturePointID2
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID2;
m_EventBroker->Publish(touchEvent);
//player2 does nothing
}
void CapturePointTest::TestSetup6_Team1CapturedTheLastPointAndWon()
{
//NOTE: setup events need to trigger first then the real event will be allowed by the system later
Events::TriggerTouch touchEvent;
//"SETUP" team1 captures point 2,3
//player1 touches m_CapturePointID3
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID3;
m_EventBroker->Publish(touchEvent);
//player1 touches m_CapturePointID2
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID2;
m_EventBroker->Publish(touchEvent);
//team1 captures point 1
//player1 touches m_CapturePointID
touchEvent.Entity = m_PlayerID;
touchEvent.Trigger = m_CapturePointID;
m_EventBroker->Publish(touchEvent);
//player2 does nothing
}
void CapturePointTest::TestSuccess1() {
//TestSetup1_OnePlayerOnCapturePoint
//if ammocount reaches -- we know the test has succeeded, i.e. a shot has been fired
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"];
if (ownedByID3 == 1)
TestSucceeded = true;
}
void CapturePointTest::TestSuccess2() {
//TestSetup2_TwoPlayersOnCapturePoint
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"];
int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"];
if (ownedByID3 == 1 && ownedByID1 == 2)
TestSucceeded = true;
}
void CapturePointTest::TestSuccess3() {
//TestSetup3_NoPlayersOnCapturePoint
//only do this test if were at the final loopcount
//if any capturePoint changed then, its a failure else a success
if (NumLoops == 95) {
TestSucceeded = true;
int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"];
int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["OwnedBy"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"];
if (ownedByID1 != 0 || ownedByID2 != 0 || ownedByID3 != 0)
TestSucceeded = false;
}
}
void CapturePointTest::TestSuccess4() {
//TestSetup4_TwoCapturePointsBeingCaptured
int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"];
int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["OwnedBy"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"];
if (ownedByID1 == 2 && ownedByID3 == 1)
TestSucceeded = true;
}
void CapturePointTest::TestSuccess5() {
//TestSetup5_SameCapturePointContestedAndTakenOver
int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"];
int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["OwnedBy"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"];
if (ownedByID1 == 2 && ownedByID2 == 1 && ownedByID3 == 1)
TestSucceeded = true;
}
void CapturePointTest::TestSuccess6() {
//NOTE: the actual win-event will have to be manually checked if it triggered or not
//TestSetup6_Team1CapturedTheLastPointAndWon
int ownedByID1 = m_World->GetComponent(m_CapturePointID, "CapturePoint")["OwnedBy"];
int ownedByID2 = m_World->GetComponent(m_CapturePointID2, "CapturePoint")["OwnedBy"];
int ownedByID3 = m_World->GetComponent(m_CapturePointID3, "CapturePoint")["OwnedBy"];
if (ownedByID1 == 1 && ownedByID2 == 1 && ownedByID3 == 1)
TestSucceeded = true;
}
void CapturePointTest::Tick() void CapturePointTest::Tick()
{ {
glfwPollEvents(); glfwPollEvents();
double currentTime = glfwGetTime(); //double currentTime = glfwGetTime();
double dt = currentTime - m_LastTime; //double dt = currentTime - m_LastTime;
m_LastTime = currentTime; //m_LastTime = currentTime;
//just set dt to 10.0 since we want fast testing
double dt = 10.0;
// Iterate through systems and update world! // Iterate through systems and update world!
m_SystemPipeline->Update(m_World, dt); m_SystemPipeline->Update(m_World, dt);
@@ -141,4 +427,27 @@ void CapturePointTest::Tick()
m_EventBroker->Swap(); m_EventBroker->Swap();
m_EventBroker->Clear(); m_EventBroker->Clear();
switch (m_RunTestNumber)
{
case 1:
TestSuccess1();
break;
case 2:
TestSuccess2();
break;
case 3:
TestSuccess3();
break;
case 4:
TestSuccess4();
break;
case 5:
TestSuccess5();
break;
case 6:
TestSuccess6();
break;
default:
break;
}
} }
+15 -1
View File
@@ -27,6 +27,20 @@ public:
void Tick(); void Tick();
bool TestSucceeded = false; bool TestSucceeded = false;
int NumLoops = 0;
void TestSetup1_OnePlayerOnCapturePoint();
void TestSetup2_TwoPlayersOnCapturePoint();
void TestSetup3_NoPlayersOnCapturePoint();
void TestSetup4_TwoCapturePointsBeingCaptured();
void TestSetup5_SameCapturePointContestedAndTakenOver();
void TestSetup6_Team1CapturedTheLastPointAndWon();
void TestSuccess1();
void TestSuccess2();
void TestSuccess3();
void TestSuccess4();
void TestSuccess5();
void TestSuccess6();
private: private:
double m_LastTime; double m_LastTime;
@@ -34,7 +48,7 @@ private:
EventBroker* m_EventBroker; EventBroker* m_EventBroker;
World* m_World; World* m_World;
SystemPipeline* m_SystemPipeline; SystemPipeline* m_SystemPipeline;
int m_PlayerID, m_PlayerID2, m_CapturePointID, m_CapturePointID2; int m_PlayerID, m_PlayerID2, m_CapturePointID, m_CapturePointID2, m_CapturePointID3;
int m_RunTestNumber; int m_RunTestNumber;
}; };