Added tests for PointLight conversion + spawns

This commit is contained in:
suhrke 2017-07-06 10:09:15 -07:00
parent d16f3f8503
commit 640ce93ff4
2 changed files with 65 additions and 5 deletions

View File

@ -138,10 +138,10 @@ EntityConverter::convert(const std::vector<std::string> &lines)
throw std::runtime_error("error: type is required"); throw std::runtime_error("error: type is required");
} }
// If worldspawn, first reenable all gamemodes
// RETURN EMPTY VECTOR if type is WorldSpawn // then check worldspawn for disabled modes
// then RETURN EMPTY VECTOR
if ( type == "WorldSpawn" ) { if ( type == "WorldSpawn" ) {
//All modes enabled by default, reset for new worldspawn
ws_.cts = true; ws_.cts = true;
ws_.ctf = true; ws_.ctf = true;
ws_.ffa = true; ws_.ffa = true;
@ -712,7 +712,7 @@ EntityConverter::hexToRGB(const std::string &hex, float &r, float &g, float &b)
ss << std::hex << hex; ss << std::hex << hex;
ss >> value; ss >> value;
// get the necessary components from the right bytes // get the necessary components from the top 3 bytes
r = ((value >> 16) & 0xFF) / 255.0; r = ((value >> 16) & 0xFF) / 255.0;
g = ((value >> 8) & 0xFF) / 255.0; g = ((value >> 8) & 0xFF) / 255.0;
b = ((value) & 0xFF) / 255.0; b = ((value) & 0xFF) / 255.0;

View File

@ -149,6 +149,20 @@ TEST_CASE( "r2x: a single PlayerSpawn (race) entity can be converted", "[EntityC
REQUIRE( coords[0] == "\"-216.00000" ); REQUIRE( coords[0] == "\"-216.00000" );
REQUIRE( coords[1] == "-1488.000488" ); REQUIRE( coords[1] == "-1488.000488" );
REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA ); REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA );
SECTION( "Encountering a new worldspawn reenables all modes" ) {
std::vector<std::string> basicWorldspawn;
basicWorldspawn.push_back(" type WorldSpawn");
std::vector<std::string> e;
e.push_back(" type PlayerSpawn");
e.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
e.push_back(" Vector3 angles 180.00000 0.00000 0.00000");
std::vector<std::string> u = ec.convert(basicWorldspawn);
std::vector<std::string> c = ec.convert(e);
REQUIRE( c[0] == "\"classname\" \"info_player_deathmatch\"\n" );
}
} }
@ -327,7 +341,7 @@ TEST_CASE( "r2x: a single Teleporter and related Target can be converted", "[Ent
float offsetCoord; float offsetCoord;
iss >> attribute >> coords[0] >> coords[1] >> offsetCoord; iss >> attribute >> coords[0] >> coords[1] >> offsetCoord;
// first test fails without busy wait // next REQUIRE fails without busy wait
for( int i = 0; i < 10000000; i++ ) for( int i = 0; i < 10000000; i++ )
int x = i; int x = i;
@ -376,6 +390,52 @@ TEST_CASE( "r2x: a single JumpPad and related Target can be converted", "[Entity
TEST_CASE( "r2x: a single PointLight entity can be converted", "[EntityConverter]" ) {
// Instantiate object
EntityConverter ec (PICKUP_FILENAME);
// Mock up entity
std::vector<std::string> entity;
entity.push_back(" type PointLight");
entity.push_back(" Vector3 position -216.00000 -132.00000 -1488.000488");
entity.push_back(" ColourXRGB32 color ffffc400");
entity.push_back(" Float intensity 1.500000");
entity.push_back(" Float nearAttenuation 32.000000");
entity.push_back(" Float farAttenuation 160.000000");
// 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\" \"light\"\n" );
REQUIRE( converted[1] == "\"origin\" \"-216.00000 -1488.000488 -132.00000\"\n" );
REQUIRE( converted[2] == "\"light\" \"75\"\n" );
INFO( converted[3] );
std::istringstream iss(converted[3]);
std::string attribute;
std::string r;
float red;
float green;
float blue;
iss >> attribute >> r >> green >> blue;
r.erase(r.begin()); //removing preceding quote is necessary
std::stringstream redStream(r);
redStream >> red;
REQUIRE( attribute == "\"_color\"" );
REQUIRE( fabs(1.0 - red) <= DELTA );
REQUIRE( fabs(0.768627 - green) <= DELTA );
REQUIRE( fabs(0.0 - blue) <= DELTA );
}