diff --git a/CMakeLists.txt b/CMakeLists.txt index 35a08c2..663dbe4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ enable_testing() add_executable(wavefront_tests tests/unit/trim_test.cpp tests/unit/settings_test.cpp + tests/unit/scan_test.cpp ${APP_SOURCES} ) target_link_libraries(wavefront_tests PRIVATE diff --git a/src/main.cpp b/src/main.cpp index 53b16f5..267bc40 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -124,10 +124,10 @@ int main(int argc, char** argv) { using FloatType = float; using IndexType = std::uint32_t; - CATCH_AND_RETURN(scan_data, wavefront::scan_error, 1, wavefront::scan( + auto scan_data = wavefront::scan( settings.input(), settings.selected_objects(), - settings.selected_groups()) + settings.selected_groups() ); std::cerr << "Scanned " << scan_data.total_lines << " lines" << std::endl; diff --git a/src/scan.cpp b/src/scan.cpp index a5ee70e..790249a 100644 --- a/src/scan.cpp +++ b/src/scan.cpp @@ -11,8 +11,6 @@ #include "scan.hpp" namespace wavefront { - scan_error::scan_error(const std::string &message) : std::runtime_error(message) {} - scan_result::scan_result() : total_lines(0), line_data(), diff --git a/src/scan.hpp b/src/scan.hpp index 77f9d96..4541c27 100644 --- a/src/scan.hpp +++ b/src/scan.hpp @@ -10,11 +10,6 @@ #include "settings.hpp" namespace wavefront { - class scan_error : public std::runtime_error { - public: - explicit scan_error(const std::string &message); - }; - struct scan_result { std::size_t total_lines; std::map line_data; diff --git a/tests/data/test-scan-1.txt b/tests/data/test-scan-1.txt index 4223d07..325e095 100644 --- a/tests/data/test-scan-1.txt +++ b/tests/data/test-scan-1.txt @@ -1,4 +1,5 @@ # Command + v 0.1 0.2 0.3 v 0.2 0.3 0.4 v 0.3 0.4 0.5 @@ -18,3 +19,8 @@ o test f 4/3/2 5/2/1 6/1/2 g test f 7/2/2 8/3/2 9/1/1 +o +f 8/1/1 5/2/2 3/3/2 +g +f 2/1/1 6/2/2 4/3/2 +h this line is skipped diff --git a/tests/unit/scan_test.cpp b/tests/unit/scan_test.cpp new file mode 100644 index 0000000..1f17e2a --- /dev/null +++ b/tests/unit/scan_test.cpp @@ -0,0 +1,64 @@ +#include +#include + +#include + +#include "scan.hpp" + +namespace { + std::filesystem::path test_data_path(const std::string &filename) { + const auto here = std::filesystem::path(__FILE__).parent_path(); + return here.parent_path() / "data" / filename; + } + + TEST(Scan, ReadsAllSupportedTypes) { + std::ifstream input(test_data_path("test-scan-1.txt")); + ASSERT_TRUE(input.is_open()); + + const auto result = wavefront::scan(input); + + EXPECT_EQ(result.total_lines, 26u); + EXPECT_EQ(result.line_data.size(), 21u); + + EXPECT_TRUE(result.category_map.contains("v")); + EXPECT_TRUE(result.category_map.contains("vn")); + EXPECT_TRUE(result.category_map.contains("vt")); + EXPECT_TRUE(result.category_map.contains("f")); + + EXPECT_EQ(result.category_map.at("v").size(), 10u); + EXPECT_EQ(result.category_map.at("vn").size(), 4u); + EXPECT_EQ(result.category_map.at("vt").size(), 3u); + EXPECT_EQ(result.category_map.at("f").size(), 5u); + } + + TEST(Scan, FiltersByObject) { + std::ifstream input(test_data_path("test-scan-1.txt")); + ASSERT_TRUE(input.is_open()); + + const auto result = wavefront::scan(input, {"test"}); + + EXPECT_EQ(result.category_map.at("f").size(), 4u); + EXPECT_EQ(result.category_map.at("f")[0], 19u); + EXPECT_EQ(result.category_map.at("f")[1], 21u); + } + + TEST(Scan, FiltersByGroup) { + std::ifstream input(test_data_path("test-scan-1.txt")); + ASSERT_TRUE(input.is_open()); + + const auto result = wavefront::scan(input, {}, {"test"}); + + EXPECT_EQ(result.category_map.at("f").size(), 3u); + EXPECT_EQ(result.category_map.at("f")[0], 21u); + } + + TEST(Scan, FiltersByObjectAndGroup) { + std::ifstream input(test_data_path("test-scan-1.txt")); + ASSERT_TRUE(input.is_open()); + + const auto result = wavefront::scan(input, {"test"}, {"test"}); + + EXPECT_EQ(result.category_map.at("f").size(), 3u); + EXPECT_EQ(result.category_map.at("f")[0], 21u); + } +}