From 640ce93ff4b1441875f9530476f13e3f0b8136d1 Mon Sep 17 00:00:00 2001 From: suhrke Date: Thu, 6 Jul 2017 10:09:15 -0700 Subject: [PATCH] Added tests for PointLight conversion + spawns --- ReflexToQ3/includes/EntityConverter.cpp | 8 ++-- ReflexToQ3/test/catch.cpp | 62 ++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/ReflexToQ3/includes/EntityConverter.cpp b/ReflexToQ3/includes/EntityConverter.cpp index 5f3933a..d2acdd5 100644 --- a/ReflexToQ3/includes/EntityConverter.cpp +++ b/ReflexToQ3/includes/EntityConverter.cpp @@ -138,10 +138,10 @@ EntityConverter::convert(const std::vector &lines) throw std::runtime_error("error: type is required"); } - - // RETURN EMPTY VECTOR if type is WorldSpawn + // If worldspawn, first reenable all gamemodes + // then check worldspawn for disabled modes + // then RETURN EMPTY VECTOR if ( type == "WorldSpawn" ) { - //All modes enabled by default, reset for new worldspawn ws_.cts = true; ws_.ctf = 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 >> value; - // get the necessary components from the right bytes + // get the necessary components from the top 3 bytes r = ((value >> 16) & 0xFF) / 255.0; g = ((value >> 8) & 0xFF) / 255.0; b = ((value) & 0xFF) / 255.0; diff --git a/ReflexToQ3/test/catch.cpp b/ReflexToQ3/test/catch.cpp index e0b33a5..3eed42f 100644 --- a/ReflexToQ3/test/catch.cpp +++ b/ReflexToQ3/test/catch.cpp @@ -149,6 +149,20 @@ TEST_CASE( "r2x: a single PlayerSpawn (race) entity can be converted", "[EntityC REQUIRE( coords[0] == "\"-216.00000" ); REQUIRE( coords[1] == "-1488.000488" ); REQUIRE( fabs(-100.00000 - offsetCoord) <= DELTA ); + + SECTION( "Encountering a new worldspawn reenables all modes" ) { + std::vector basicWorldspawn; + basicWorldspawn.push_back(" type WorldSpawn"); + + std::vector 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 u = ec.convert(basicWorldspawn); + std::vector 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; 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++ ) 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 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> q; + q.push( entity ); + + // Match related entities (none) + ec.extractMapInfo( q ); + + // Convert a single entity + std::vector 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 ); +}