1
0

test: scan

This commit is contained in:
2026-02-21 14:47:30 +02:00
parent 0f40f89cbb
commit 6a3a7541ea
6 changed files with 73 additions and 9 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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(),

View File

@@ -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<std::size_t, std::string> line_data;

View File

@@ -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

64
tests/unit/scan_test.cpp Normal file
View File

@@ -0,0 +1,64 @@
#include <filesystem>
#include <fstream>
#include <gtest/gtest.h>
#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);
}
}