#include "oopless-parser.hpp" #include "catch.hpp" #include std::vector getfaces(const std::string &test) { using namespace std; stringstream ss; ss << test; return parse_face(ss); } TEST_CASE ("face parsing case: faces with 3 indices", "[Parser]" ) { std::string sample = " 0.000000 0.000000 1.000000 1.000000 0.000000 6 0 7 0xff727278 common/materials/stone/stone"; struct TFace f = getfaces(sample).front(); REQUIRE (f.m_Indices.size() == 3); } TEST_CASE ("face parsing case: faces with 4 indices", "[Parser]") { std::string sample = " 0.000000 0.000000 1.000000 1.000000 0.000000 3 1 0 4 0xffffffff common/materials/metal/aluminum"; struct TFace f = getfaces(sample).front(); REQUIRE (f.m_Indices.size() == 4); } TEST_CASE ("face parsing case: faces with 5 indices", "[Parser]") { std::string sample = " 0.000000 0.000000 1.000000 1.000000 0.000000 2 7 5 7 4 0xff727278 common/materials/stone/stone"; struct TFace f = getfaces(sample).front(); REQUIRE (f.m_Indices.size() == 5); } TEST_CASE ("face parsing case: faces with 9 indices", "[Parser]") { std::string sample = " 0.000000 0.000000 1.000000 1.000000 0.000000 2 7 5 7 4 7 5 7 4 0xff727278 common/materials/stone/stone"; struct TFace f = getfaces(sample).front(); REQUIRE (f.m_Indices.size() == 9); } TEST_CASE("face parsing case: faces with no material", "[Parser]") { std::string sample = " 0.000000 0.000000 1.000000 1.000000 0.000000 1 0 4 5 0x00000000 "; std::string answer; //empty string struct TFace f = getfaces(sample).front(); REQUIRE (f.m_Material == answer); } TEST_CASE("face parsing case: face's material name is preserved", "[Parser]") { std::string sample = " 0.000000 0.000000 1.000000 1.000000 0.000000 3 1 0 4 0xffffffff common/materials/metal/aluminum"; std::string answer = "common/materials/metal/aluminum"; struct TFace f = getfaces(sample).front(); REQUIRE (f.m_Material == answer); } TEST_CASE("face parsing case: face's color code is preserved", "[Parser]") { std::string sample = " 0.000000 0.000000 1.000000 1.000000 0.000000 2 4 1 5 0xffa5a5a5 common/materials/metal/p_metal3"; std::string answer = "0xffa5a5a5"; struct TFace f = getfaces(sample).front(); REQUIRE (f.hex == answer); } TEST_CASE("brush parser case: returns populated Vertices and Faces list", "[Parser]") { std::string sample = " vertices\n\ -23.000000 -20.000000 15.000000\n\ 9.000000 -20.000000 15.000000\n\ 9.000000 -20.000000 -17.000000\n\ -15.000000 -24.000000 -9.000000\n\ -23.000000 -20.000000 -17.000000\n\ 1.000000 -24.000000 7.000000\n\ 1.000000 -24.000000 -9.000000\n\ -15.000000 -24.000000 7.000000\n\ faces\n\ 0.000000 0.000000 1.000000 1.000000 0.000000 0 1 2 4 0xff888888 common/materials/metal/p_metal3\n\ 0.000000 0.000000 1.000000 1.000000 0.000000 3 4 2 6 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 4 3 7 0xff888888 common/materials/metal/p_metal3\n\ 0.000000 0.000000 1.000000 1.000000 131.810318 5 1 0 7 0xff888888 common/materials/metal/p_metal3\n\ 0.000000 0.000000 1.000000 1.000000 0.000000 3 6 5 7 0xff888888 common/materials/metal/p_metal3"; std::stringstream ss; ss << sample; struct TBrush b = parse_brush(ss); REQUIRE ((b.m_Vertices.size() == 8 && b.m_Faces.size() == 6)); } TEST_CASE("brush parser case: returns empty when given empty input", "[Parser]") { std::string empty; std::stringstream ss; ss << empty; struct TBrush b = parse_brush(ss); REQUIRE ((b.m_Vertices.size() == 0 && b.m_Faces.size() == 0)); }