2017-07-15 12:44:50 +05:30
|
|
|
#include "oopless-parser.hpp"
|
|
|
|
#include "catch.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
|
|
|
#include <sstream>
|
|
|
|
|
2017-07-15 13:56:03 +05:30
|
|
|
std::vector<std::string> readin(const std::string &filename, const int ln = 0) {
|
|
|
|
std::ifstream fin;
|
|
|
|
fin.open(filename);
|
2017-07-15 12:44:50 +05:30
|
|
|
if (!fin.good()) {
|
2017-07-15 13:56:03 +05:30
|
|
|
std::cerr << "error: can not open file with test cases." << std::endl;
|
2017-07-15 12:44:50 +05:30
|
|
|
}
|
2017-07-15 13:56:03 +05:30
|
|
|
std::vector<std::string> output;
|
|
|
|
std::string data;
|
2017-07-15 12:44:50 +05:30
|
|
|
while (getline(fin, data)) {
|
|
|
|
output.push_back(data);
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2017-07-15 13:56:03 +05:30
|
|
|
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);
|
2017-07-15 12:44:50 +05:30
|
|
|
bool is_ok = true;
|
|
|
|
for (struct TFace face : x) {
|
|
|
|
if (face.m_Indices.size() != cnt_indices) {
|
|
|
|
is_ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return is_ok;
|
|
|
|
}
|
|
|
|
|
2017-07-15 13:56:03 +05:30
|
|
|
TEST_CASE ("face parsing case: faces with 3 indices", "[Parser]" ) {
|
|
|
|
bool k = test_parseface("ReflexToQ3/test/cases-face/parser-face-3indices.txt", 3);
|
2017-07-15 12:44:50 +05:30
|
|
|
REQUIRE (k == true);
|
|
|
|
}
|
|
|
|
|
2017-07-15 13:56:03 +05:30
|
|
|
TEST_CASE ("face parsing case: faces with 4 indices", "[Parser]") {
|
|
|
|
bool k = test_parseface("ReflexToQ3/test/cases-face/parser-face-4indices.txt", 4);
|
2017-07-15 12:44:50 +05:30
|
|
|
REQUIRE (k == true);
|
|
|
|
}
|
|
|
|
|
2017-07-15 13:56:03 +05:30
|
|
|
TEST_CASE ("face parsing case: faces with 5 indices", "[Parser]") {
|
|
|
|
bool k = test_parseface("ReflexToQ3/test/cases-face/parser-face-5indices.txt", 5);
|
2017-07-15 12:44:50 +05:30
|
|
|
REQUIRE (k == true);
|
|
|
|
}
|
|
|
|
|