Added test cases for function 'get_entity'

This commit is contained in:
2017-07-18 01:28:56 -07:00
parent 0993b17333
commit 3e7dd36db3
2 changed files with 71 additions and 1 deletions

View File

@ -8,7 +8,7 @@ all: main test
main: planes.o brushdef.o oopless-parser.o EntityConverter.o
$(CC) $^ main.cpp $(CFLAGS) -o $(EX) 2>error8.log
test: EntityConverter.o catch.o
test: planes.o brushdef.o oopless-parser.o EntityConverter.o catch.o
$(CC) $^ $(CFLAGS) -o $(TESTEX)
mv test/catch ../.git/hooks/pre-commit

View File

@ -87,3 +87,73 @@ TEST_CASE("brush parser case: returns empty when given empty input", "[Parser]")
struct TBrush b = parse_brush<std::stringstream>(ss);
REQUIRE ((b.m_Vertices.size() == 0 && b.m_Faces.size() == 0));
}
TEST_CASE("get entity case: recognizes brush entites", "[Parser]") {
std::string sample = " type JumpPad\n\
String32 target jp2\n\
brush\n\
vertices\n\
324.000000 36.000000 -228.000000\n\
352.000000 36.000000 -228.000000\n\
352.000000 36.000000 -380.000000\n\
324.000000 36.000000 -380.000000\n\
324.000000 32.000000 -228.000000\n\
352.000000 32.000000 -228.000000\n\
352.000000 32.000000 -380.000000\n\
324.000000 32.000000 -380.000000\n\
faces\n\
0.000000 0.000000 -0.250000 -0.000000 270.000000 0 1 2 3 0x00000000 \n\
0.000000 0.000000 -0.250000 -0.000000 0.000000 6 5 4 7 0x00000000 \n\
0.000000 0.000000 -0.250000 -0.000000 0.000000 2 1 5 6 0x00000000 \n\
0.000000 0.000000 -0.250000 -0.000000 0.000000 0 3 7 4 0x00000000 \n\
0.000000 0.000000 -0.250000 -0.000000 0.000000 3 2 6 7 0x00000000 \n\
0.000000 0.000000 -0.250000 -0.000000 0.000000 1 0 4 5 0x00000000 ";
std::stringstream ss;
ss << sample;
std::vector<std::string> ent = get_entity<std::stringstream>(ss);
unsigned int count = 0;
for (const std::string &x : ent) {
if (x.find(KEYWORD_BRUSH) != std::string::npos) {
count++;
}
}
REQUIRE ((count == 1 && ent.size() == 19));
}
TEST_CASE("get entity case: omits unaffiliated brush") {
std::string sample = " type WorldSpawn\n\
String32 targetGameOverCamera end\n\
ColourXRGB32 colorTeamA ff801313\n\
ColourXRGB32 fogColor ff7f5122\n\
Float fogDistanceEnd 3500.000000\n\
String256 title Static Discharge\n\
UInt8 playersMax 6\n\
brush\n\
vertices\n\
-19.000000 28.000000 23.000000\n\
29.000000 28.000000 23.000000\n\
29.000000 28.000000 -25.000000\n\
-19.000000 28.000000 -25.000000\n\
-19.000000 -20.000000 23.000000\n\
29.000000 -20.000000 23.000000\n\
29.000000 -20.000000 -25.000000\n\
-19.000000 -20.000000 -25.000000\n\
faces\n\
0.000000 0.000000 1.000000 1.000000 0.000000 0 1 2 3 0xff888888 common/materials/metal/p_metal3\n\
0.000000 0.000000 1.000000 1.000000 0.000000 6 5 4 7 0xff888888 common/materials/metal/p_metal3\n\
0.000000 0.000000 1.000000 1.000000 0.000000 2 1 5 6 0xff888888 common/materials/metal/p_metal3\n\
0.000000 0.000000 1.000000 1.000000 0.000000 0 3 7 4 0xff888888 common/materials/metal/p_metal3\n\
0.000000 0.000000 1.000000 1.000000 0.000000 3 2 6 7 0xff888888 common/materials/metal/p_metal3\n\
0.000000 0.000000 1.000000 1.000000 0.000000 1 0 4 5 0xff888888 common/materials/metal/p_metal3";
std::stringstream ss;
ss << sample;
std::vector<std::string> ent = get_entity<std::stringstream>(ss);
unsigned int count = 0;
for (const std::string &x : ent) {
if (x.find(KEYWORD_BRUSH) != std::string::npos) {
count++;
}
}
REQUIRE ((count == 0 && ent.size() == 7));
}