reflex2q3/ReflexToQ3/test/catch-parser.cpp

61 lines
2.3 KiB
C++

#include "oopless-parser.hpp"
#include "catch.hpp"
#include <algorithm>
#include <iterator>
#include <sstream>
std::vector<TFace> getfaces(const std::string &test) {
using namespace std;
stringstream ss;
ss << test;
return parse_face<stringstream>(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);
}