test: parse.underflow
This commit is contained in:
@@ -232,4 +232,84 @@ namespace {
|
||||
EXPECT_EQ(std::string(ex.what()), "Missing required \"v\" data");
|
||||
}
|
||||
}
|
||||
|
||||
struct UnderflowCase {
|
||||
std::string line_type;
|
||||
std::size_t number_count;
|
||||
std::string expected_message;
|
||||
};
|
||||
|
||||
class ParseCoordinateDataUnderflowTest
|
||||
: public ::testing::TestWithParam<UnderflowCase> {
|
||||
};
|
||||
|
||||
static std::string build_line_with_count(
|
||||
const std::string &line_type,
|
||||
std::size_t number_count
|
||||
) {
|
||||
std::vector<std::string> values;
|
||||
if (line_type == "vt") {
|
||||
values = {"0.9", "0.8", "0.7"};
|
||||
} else {
|
||||
values = {"0.1", "0.2", "0.3"};
|
||||
}
|
||||
std::string line = line_type;
|
||||
for (std::size_t i = 0; i < number_count && i < values.size(); ++i) {
|
||||
line += " ";
|
||||
line += values[i];
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
TEST_P(ParseCoordinateDataUnderflowTest, ThrowsOnInsufficientNumbers) {
|
||||
const auto ¶m = GetParam();
|
||||
|
||||
wavefront::scan_result scan_result;
|
||||
scan_result.total_lines = 3;
|
||||
scan_result.line_data = {
|
||||
{1u, "v 0.1 0.2 0.3"},
|
||||
{3u, build_line_with_count(param.line_type, param.number_count)}
|
||||
};
|
||||
|
||||
if (param.line_type == "v") {
|
||||
scan_result.category_map = {
|
||||
{"v", {0u, 1u, 3u}}
|
||||
};
|
||||
} else {
|
||||
scan_result.category_map = {
|
||||
{"v", {0u, 1u}},
|
||||
{param.line_type, {0u, 3u}}
|
||||
};
|
||||
}
|
||||
|
||||
wavefront::wavefront_face_data_result_t face_data;
|
||||
if (param.line_type == "v") {
|
||||
face_data.index_position_set = {2};
|
||||
} else if (param.line_type == "vn") {
|
||||
face_data.index_normal_set = {1};
|
||||
} else {
|
||||
face_data.index_texcoord_set = {1};
|
||||
}
|
||||
|
||||
try {
|
||||
(void)wavefront::parse_coordinate_data<float>(scan_result, face_data);
|
||||
FAIL() << "Expected parse_error";
|
||||
} catch (const wavefront::parse_error &ex) {
|
||||
EXPECT_EQ(std::string(ex.what()), param.expected_message);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
ParseCoordinateData,
|
||||
ParseCoordinateDataUnderflowTest,
|
||||
::testing::Values(
|
||||
UnderflowCase{"v", 0u, "[3]: Line \"v\" must contain at least 3 numbers"},
|
||||
UnderflowCase{"v", 1u, "[3]: Line \"v\" must contain at least 3 numbers"},
|
||||
UnderflowCase{"v", 2u, "[3]: Line \"v\" must contain at least 3 numbers"},
|
||||
UnderflowCase{"vn", 0u, "[3]: Line \"vn\" must contain exactly 3 numbers"},
|
||||
UnderflowCase{"vn", 1u, "[3]: Line \"vn\" must contain exactly 3 numbers"},
|
||||
UnderflowCase{"vn", 2u, "[3]: Line \"vn\" must contain exactly 3 numbers"},
|
||||
UnderflowCase{"vt", 0u, "[3]: Unable to parse \"vt\" line: expected minimum one number"}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user