2017-07-04 10:49:50 +05:30
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
|
|
|
* Filename: catch.cpp
|
|
|
|
*
|
|
|
|
* Description: Unit Tests for EntityConverter
|
|
|
|
*
|
|
|
|
* Version: 0.1
|
|
|
|
* Created: 07/03/2017 08:25:04 PM
|
|
|
|
* Revision: none
|
|
|
|
* Compiler: gcc
|
|
|
|
*
|
|
|
|
* Author: suhrke@teknik.io
|
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CATCH_CONFIG_MAIN
|
|
|
|
#define CATCH_CONFIG_MAIN
|
|
|
|
#include "catch.hpp"
|
2017-07-05 17:40:31 +05:30
|
|
|
#include <cmath>
|
2017-07-04 10:49:50 +05:30
|
|
|
#include <queue>
|
|
|
|
#include <vector>
|
2017-07-05 17:40:31 +05:30
|
|
|
#include <sstream>
|
2017-07-04 10:49:50 +05:30
|
|
|
|
|
|
|
#include "EntityConverter.hpp"
|
|
|
|
|
2017-07-06 05:15:57 +05:30
|
|
|
#define PICKUP_FILENAME "ReflexToQ3/r2x.pck"
|
2017-07-05 17:40:31 +05:30
|
|
|
#define DELTA 0.00001
|
2017-07-04 10:49:50 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-05 15:57:00 +05:30
|
|
|
TEST_CASE( "r2x: Unsupported entity types cause return of empty vector", "[EntityConverter]" ) {
|
|
|
|
|
|
|
|
// Instantiate object
|
|
|
|
EntityConverter ec (PICKUP_FILENAME);
|
|
|
|
|
|
|
|
// Mock up entity
|
|
|
|
std::vector<std::string> entity;
|
|
|
|
entity.push_back(" type Worldspawn");
|
|
|
|
|
|
|
|
// Mock up entity queue
|
|
|
|
std::queue<std::vector<std::string>> q;
|
|
|
|
q.push( entity );
|
|
|
|
|
|
|
|
// Match related entities (none)
|
2017-07-06 07:28:07 +05:30
|
|
|
ec.extractMapInfo( q );
|
2017-07-05 15:57:00 +05:30
|
|
|
|
|
|
|
// Convert a single entity
|
|
|
|
std::vector<std::string> converted = ec.convert(entity);
|
|
|
|
|
|
|
|
REQUIRE( converted.size() == 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-04 12:36:13 +05:30
|
|
|
TEST_CASE( "r2x: a single Pickup entity can be converted", "[EntityConverter]" ) {
|
2017-07-04 10:49:50 +05:30
|
|
|
|
|
|
|
// Instantiate object
|
|
|
|
EntityConverter ec (PICKUP_FILENAME);
|
|
|
|
|
|
|
|
// Mock up entity
|
|
|
|
std::vector<std::string> entity;
|
2017-07-05 15:57:00 +05:30
|
|
|
entity.push_back(" type Pickup");
|
|
|
|
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
|
|
|
entity.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
|
|
|
|
entity.push_back(" UInt8 pickupType 2");
|
2017-07-04 10:49:50 +05:30
|
|
|
|
|
|
|
// Mock up entity queue
|
|
|
|
std::queue<std::vector<std::string>> q;
|
2017-07-04 12:36:13 +05:30
|
|
|
q.push( entity );
|
2017-07-04 10:49:50 +05:30
|
|
|
|
|
|
|
// Match related entities (none)
|
2017-07-06 07:28:07 +05:30
|
|
|
ec.extractMapInfo( q );
|
2017-07-04 10:49:50 +05:30
|
|
|
|
2017-07-04 12:36:13 +05:30
|
|
|
// Convert a single entity
|
2017-07-04 10:49:50 +05:30
|
|
|
std::vector<std::string> converted = ec.convert(entity);
|
|
|
|
|
|
|
|
REQUIRE( converted[0] == "\"classname\" \"weapon_grenadelauncher\"\n" );
|
2017-07-05 17:40:31 +05:30
|
|
|
|
2017-07-06 04:30:22 +05:30
|
|
|
// The z (vertical) is offset by +2
|
2017-07-05 17:40:31 +05:30
|
|
|
std::istringstream iss(converted[1]);
|
|
|
|
std::string attribute;
|
|
|
|
std::string coords[2];
|
|
|
|
float offsetCoord;
|
|
|
|
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
|
|
|
|
|
|
|
REQUIRE( attribute == "\"origin\"" );
|
|
|
|
REQUIRE( coords[0] == "\"-216.00000" );
|
|
|
|
REQUIRE( coords[1] == "-1488.000488" );
|
2017-07-06 04:30:22 +05:30
|
|
|
REQUIRE( fabs(-130.00000 - offsetCoord) <= DELTA );
|
2017-07-04 10:49:50 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-06 04:44:17 +05:30
|
|
|
TEST_CASE( "r2x: a single PlayerSpawn (race) entity can be converted", "[EntityConverter]" ) {
|
|
|
|
|
|
|
|
// Instantiate object
|
|
|
|
EntityConverter ec (PICKUP_FILENAME);
|
|
|
|
|
|
|
|
// Mock up entity
|
|
|
|
std::vector<std::string> entity;
|
|
|
|
entity.push_back(" type PlayerSpawn");
|
|
|
|
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
|
|
|
entity.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
|
|
|
|
entity.push_back(" Bool8 teamA 0");
|
|
|
|
entity.push_back(" Bool8 teamB 0");
|
|
|
|
entity.push_back(" Bool8 modeCTF 0");
|
|
|
|
entity.push_back(" Bool8 modeFFA 0");
|
|
|
|
entity.push_back(" Bool8 modeTDM 0");
|
|
|
|
entity.push_back(" Bool8 mode1v1 0");
|
|
|
|
|
2017-07-06 07:28:07 +05:30
|
|
|
// With how map info works, at least one other spawn must be
|
|
|
|
|
2017-07-06 04:44:17 +05:30
|
|
|
// Mock up entity queue
|
|
|
|
std::queue<std::vector<std::string>> q;
|
|
|
|
q.push( entity );
|
|
|
|
|
|
|
|
// Match related entities (none)
|
2017-07-06 07:28:07 +05:30
|
|
|
ec.extractMapInfo( q );
|
2017-07-06 04:44:17 +05:30
|
|
|
|
|
|
|
// Convert a single entity
|
|
|
|
std::vector<std::string> converted = ec.convert(entity);
|
|
|
|
|
|
|
|
REQUIRE( converted[0] == "\"classname\" \"info_player_race\"\n" );
|
|
|
|
REQUIRE( converted[1] == "\"target\" \"cp1\"\n" );
|
|
|
|
REQUIRE( converted[2] == "\"race_place\" \"-1\"\n" );
|
|
|
|
REQUIRE( converted[4] == "\"angle\" \"180.00000\"\n" );
|
|
|
|
|
|
|
|
// The z (vertical) is offset by +32
|
|
|
|
std::istringstream iss(converted[3]);
|
|
|
|
std::string attribute;
|
|
|
|
std::string coords[2];
|
|
|
|
float offsetCoord;
|
|
|
|
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
|
|
|
|
|
|
|
REQUIRE( attribute == "\"origin\"" );
|
|
|
|
REQUIRE( coords[0] == "\"-216.00000" );
|
|
|
|
REQUIRE( coords[1] == "-1488.000488" );
|
|
|
|
REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-04 12:36:13 +05:30
|
|
|
TEST_CASE( "r2x: a single PlayerSpawn (teamA) entity can be converted", "[EntityConverter]" ) {
|
|
|
|
|
|
|
|
// Instantiate object
|
|
|
|
EntityConverter ec (PICKUP_FILENAME);
|
|
|
|
|
|
|
|
// Mock up entity
|
|
|
|
std::vector<std::string> entity;
|
2017-07-05 15:57:00 +05:30
|
|
|
entity.push_back(" type PlayerSpawn");
|
|
|
|
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
|
|
|
entity.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
|
|
|
|
entity.push_back(" Bool8 teamB 0");
|
|
|
|
entity.push_back(" Bool8 modeRace 0");
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Mock up entity queue
|
|
|
|
std::queue<std::vector<std::string>> q;
|
|
|
|
q.push( entity );
|
|
|
|
|
|
|
|
// Match related entities (none)
|
2017-07-06 07:28:07 +05:30
|
|
|
ec.extractMapInfo( q );
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Convert a single entity
|
|
|
|
std::vector<std::string> converted = ec.convert(entity);
|
|
|
|
|
|
|
|
REQUIRE( converted[0] == "\"classname\" \"info_player_team1\"\n" );
|
|
|
|
REQUIRE( converted[2] == "\"angle\" \"180.00000\"\n" );
|
2017-07-05 17:40:31 +05:30
|
|
|
|
2017-07-06 04:30:22 +05:30
|
|
|
// The z (vertical) is offset by +32
|
2017-07-05 17:40:31 +05:30
|
|
|
std::istringstream iss(converted[1]);
|
|
|
|
std::string attribute;
|
|
|
|
std::string coords[2];
|
|
|
|
float offsetCoord;
|
|
|
|
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
|
|
|
|
|
|
|
REQUIRE( attribute == "\"origin\"" );
|
|
|
|
REQUIRE( coords[0] == "\"-216.00000" );
|
|
|
|
REQUIRE( coords[1] == "-1488.000488" );
|
|
|
|
REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA );
|
2017-07-04 12:36:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-06 07:28:07 +05:30
|
|
|
TEST_CASE( "r2x: a single PlayerSpawn (non-team) entity can be converted", "[EntityConverter]" ) {
|
|
|
|
|
|
|
|
// Instantiate object
|
|
|
|
EntityConverter ec (PICKUP_FILENAME);
|
|
|
|
|
|
|
|
// Mock up entity
|
|
|
|
std::vector<std::string> entity;
|
|
|
|
entity.push_back(" type PlayerSpawn");
|
|
|
|
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
|
|
|
entity.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
|
|
|
|
|
|
|
|
// Mock up entity queue
|
|
|
|
std::queue<std::vector<std::string>> q;
|
|
|
|
q.push( entity );
|
|
|
|
|
|
|
|
// Match related entities (none)
|
|
|
|
ec.extractMapInfo( q );
|
|
|
|
|
|
|
|
// Convert a single entity
|
|
|
|
std::vector<std::string> converted = ec.convert(entity);
|
|
|
|
|
|
|
|
REQUIRE( converted[0] == "\"classname\" \"info_player_deathmatch\"\n" );
|
|
|
|
REQUIRE( converted[2] == "\"angle\" \"180.00000\"\n" );
|
|
|
|
|
|
|
|
// The z (vertical) is offset by +32
|
|
|
|
std::istringstream iss(converted[1]);
|
|
|
|
std::string attribute;
|
|
|
|
std::string coords[2];
|
|
|
|
float offsetCoord;
|
|
|
|
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
|
|
|
|
|
|
|
REQUIRE( attribute == "\"origin\"" );
|
|
|
|
REQUIRE( coords[0] == "\"-216.00000" );
|
|
|
|
REQUIRE( coords[1] == "-1488.000488" );
|
|
|
|
REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-04 12:36:13 +05:30
|
|
|
TEST_CASE( "r2x: a single RaceStart entity can be converted", "[EntityConverter]" ) {
|
|
|
|
|
|
|
|
// Instantiate object
|
|
|
|
EntityConverter ec (PICKUP_FILENAME);
|
|
|
|
|
|
|
|
// Mock up entity
|
|
|
|
std::vector<std::string> entity;
|
2017-07-05 15:57:00 +05:30
|
|
|
entity.push_back(" type RaceStart");
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Mock up entity queue
|
|
|
|
std::queue<std::vector<std::string>> q;
|
|
|
|
q.push( entity );
|
|
|
|
|
|
|
|
// Match related entities (none)
|
2017-07-06 07:28:07 +05:30
|
|
|
ec.extractMapInfo( q );
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Convert a single entity
|
|
|
|
std::vector<std::string> converted = ec.convert(entity);
|
|
|
|
|
|
|
|
REQUIRE( converted[0] == "\"classname\" \"trigger_race_checkpoint\"\n" );
|
|
|
|
REQUIRE( converted[1] == "\"targetname\" \"cp1\"\n" );
|
|
|
|
REQUIRE( converted[2] == "\"cnt\" \"1\"\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE( "r2x: a single RaceFinish entity can be converted", "[EntityConverter]" ) {
|
|
|
|
|
|
|
|
// Instantiate object
|
|
|
|
EntityConverter ec (PICKUP_FILENAME);
|
|
|
|
|
|
|
|
// Mock up entity
|
|
|
|
std::vector<std::string> entity;
|
2017-07-05 15:57:00 +05:30
|
|
|
entity.push_back(" type RaceFinish");
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Mock up entity queue
|
|
|
|
std::queue<std::vector<std::string>> q;
|
|
|
|
q.push( entity );
|
|
|
|
|
|
|
|
// Match related entities (none)
|
2017-07-06 07:28:07 +05:30
|
|
|
ec.extractMapInfo( q );
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Convert a single entity
|
|
|
|
std::vector<std::string> converted = ec.convert(entity);
|
|
|
|
|
|
|
|
REQUIRE( converted[0] == "\"classname\" \"trigger_race_checkpoint\"\n" );
|
|
|
|
REQUIRE( converted[1] == "\"targetname\" \"finish\"\n" );
|
|
|
|
REQUIRE( converted[2] == "\"cnt\" \"0\"\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE( "r2x: a single Teleporter and related Target can be converted", "[EntityConverter]" ) {
|
|
|
|
|
|
|
|
// Instantiate object
|
|
|
|
EntityConverter ec (PICKUP_FILENAME);
|
|
|
|
|
|
|
|
// Mock up Teleporter entity
|
|
|
|
std::vector<std::string> entity;
|
2017-07-05 15:57:00 +05:30
|
|
|
entity.push_back(" type Teleporter");
|
|
|
|
entity.push_back(" String32 target tp1");
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Mock up Target entity
|
|
|
|
std::vector<std::string> entity2;
|
2017-07-05 15:57:00 +05:30
|
|
|
entity2.push_back(" type Target");
|
|
|
|
entity2.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
|
|
|
entity2.push_back(" String32 name tp1");
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Mock up entity queue
|
|
|
|
std::queue<std::vector<std::string>> q;
|
|
|
|
q.push( entity );
|
|
|
|
q.push( entity2 );
|
|
|
|
|
|
|
|
// Match related entities (one pair)
|
2017-07-06 07:28:07 +05:30
|
|
|
ec.extractMapInfo( q );
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Convert two entities
|
|
|
|
std::vector<std::string> converted = ec.convert(entity);
|
|
|
|
REQUIRE( converted[0] == "\"classname\" \"trigger_teleport\"\n" );
|
|
|
|
REQUIRE( converted[1] == "\"target\" \"tp1\"\n" );
|
|
|
|
|
|
|
|
std::vector<std::string> converted2 = ec.convert(entity2);
|
|
|
|
REQUIRE( converted2[0] == "\"classname\" \"misc_teleporter_dest\"\n" );
|
|
|
|
REQUIRE( converted2[2] == "\"targetname\" \"tp1\"\n" );
|
2017-07-05 17:40:31 +05:30
|
|
|
//
|
2017-07-06 04:30:22 +05:30
|
|
|
// The z (vertical) is offset by +32
|
2017-07-05 17:40:31 +05:30
|
|
|
std::istringstream iss(converted2[1]);
|
|
|
|
std::string attribute;
|
|
|
|
std::string coords[2];
|
|
|
|
float offsetCoord;
|
|
|
|
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
|
|
|
|
|
2017-07-05 17:52:14 +05:30
|
|
|
// first test fails without busy wait
|
|
|
|
for( int i = 0; i < 10000000; i++ )
|
|
|
|
int x = i;
|
|
|
|
|
|
|
|
REQUIRE( attribute == "\"origin\"" );
|
2017-07-05 17:40:31 +05:30
|
|
|
REQUIRE( coords[0] == "\"-216.00000" );
|
|
|
|
REQUIRE( coords[1] == "-1488.000488" );
|
|
|
|
REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA );
|
2017-07-04 12:36:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE( "r2x: a single JumpPad and related Target can be converted", "[EntityConverter]" ) {
|
|
|
|
|
|
|
|
// Instantiate object
|
|
|
|
EntityConverter ec (PICKUP_FILENAME);
|
|
|
|
|
|
|
|
// Mock up JumpPad entity
|
|
|
|
std::vector<std::string> entity;
|
2017-07-05 15:57:00 +05:30
|
|
|
entity.push_back(" type JumpPad");
|
|
|
|
entity.push_back(" String32 target jp1");
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Mock up Target entity
|
|
|
|
std::vector<std::string> entity2;
|
2017-07-05 15:57:00 +05:30
|
|
|
entity2.push_back(" type Target");
|
|
|
|
entity2.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
|
|
|
|
entity2.push_back(" String32 name jp1");
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Mock up entity queue
|
|
|
|
std::queue<std::vector<std::string>> q;
|
|
|
|
q.push( entity );
|
|
|
|
q.push( entity2 );
|
|
|
|
|
|
|
|
// Match related entities (one pair)
|
2017-07-06 07:28:07 +05:30
|
|
|
ec.extractMapInfo( q );
|
2017-07-04 12:36:13 +05:30
|
|
|
|
|
|
|
// Convert two entities
|
|
|
|
std::vector<std::string> converted = ec.convert(entity);
|
|
|
|
REQUIRE( converted[0] == "\"classname\" \"trigger_push\"\n" );
|
|
|
|
REQUIRE( converted[1] == "\"target\" \"jp1\"\n" );
|
|
|
|
|
|
|
|
std::vector<std::string> converted2 = ec.convert(entity2);
|
|
|
|
REQUIRE( converted2[0] == "\"classname\" \"target_position\"\n" );
|
|
|
|
REQUIRE( converted2[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" );
|
|
|
|
REQUIRE( converted2[2] == "\"targetname\" \"jp1\"\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-04 10:49:50 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif //CATCH_CONFIG_MAIN
|
2017-07-04 12:36:13 +05:30
|
|
|
|