Added new tests for parsing faces
This commit is contained in:
parent
775fd60ed2
commit
9fa21f59d9
@ -1,51 +1,60 @@
|
||||
#include "oopless-parser.hpp"
|
||||
#include "catch.hpp"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
std::vector<std::string> readin(const std::string &filename, const int ln = 0) {
|
||||
std::ifstream fin;
|
||||
fin.open(filename);
|
||||
if (!fin.good()) {
|
||||
std::cerr << "error: can not open file with test cases." << std::endl;
|
||||
}
|
||||
std::vector<std::string> output;
|
||||
std::string data;
|
||||
while (getline(fin, data)) {
|
||||
output.push_back(data);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
bool test_parseface(const std::string &filename, const int &cnt_indices) {
|
||||
std::vector<std::string> test = readin(filename);
|
||||
std::stringstream ss;
|
||||
copy(test.begin(), test.end(), std::ostream_iterator<std::string>(ss, "\n"));
|
||||
std::vector<TFace> x = parse_face<std::stringstream>(ss);
|
||||
bool is_ok = true;
|
||||
for (struct TFace face : x) {
|
||||
if (face.m_Indices.size() != cnt_indices) {
|
||||
is_ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return is_ok;
|
||||
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]" ) {
|
||||
bool k = test_parseface("ReflexToQ3/test/cases-face/parser-face-3indices.txt", 3);
|
||||
REQUIRE (k == true);
|
||||
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]") {
|
||||
bool k = test_parseface("ReflexToQ3/test/cases-face/parser-face-4indices.txt", 4);
|
||||
REQUIRE (k == true);
|
||||
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]") {
|
||||
bool k = test_parseface("ReflexToQ3/test/cases-face/parser-face-5indices.txt", 5);
|
||||
REQUIRE (k == true);
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user