#include #include "vde/brep/step_import.h" #include "vde/brep/brep.h" #include "vde/brep/step_export.h" #include "vde/core/aabb.h" #include #include using namespace vde::brep; // TEST_DATA_DIR defined by CMake as absolute path to repo-root corpus/ #ifndef TEST_DATA_DIR #error "TEST_DATA_DIR must be defined by CMake (e.g. -DTEST_DATA_DIR=\"...\")" #endif static std::string step(const char* fname) { return std::string(TEST_DATA_DIR) + "/" + fname; } // ── 语料夹具守卫 ───────────────────────────────────────────── // corpus/ 是 gitignore 内容(不入库)。没有用户投放的 STEP 样例时整组跳过, // 不把"缺外部夹具"误报成 STEP 导入器缺陷;消息带上实际搜索的路径。 static bool file_exists(const std::string& path) { std::ifstream f(path, std::ios::binary); return f.good(); } TEST(StepUserFile, FileExists) { const std::string path = step("step/test_cube.STEP"); if (!file_exists(path)) GTEST_SKIP() << "缺少 STEP 用户夹具: " << path << "(corpus/ 为 gitignore 内容,TEST_DATA_DIR=" << TEST_DATA_DIR << ")"; std::ifstream f(path); EXPECT_TRUE(f.is_open()) << "找不到文件: " << path; } TEST(StepUserFile, ImportTestCube) { const std::string path = step("step/test_cube.STEP"); if (!file_exists(path)) GTEST_SKIP() << "缺少 STEP 用户夹具: " << path << "(corpus/ 为 gitignore 内容)"; auto bodies = import_step(path); ASSERT_FALSE(bodies.empty()) << "STEP导入返回空"; const auto& body = bodies[0]; EXPECT_TRUE(body.is_valid()); EXPECT_GT(body.num_faces(), 0); EXPECT_GT(body.num_edges(), 0); auto bb = body.bounds(); double dx = bb.max().x() - bb.min().x(); double dy = bb.max().y() - bb.min().y(); double dz = bb.max().z() - bb.min().z(); EXPECT_GT(dx, 0.01); EXPECT_GT(dy, 0.01); EXPECT_GT(dz, 0.01); } TEST(StepUserFile, ImportTestCubeRoundtrip) { const std::string path = step("step/test_cube.STEP"); if (!file_exists(path)) GTEST_SKIP() << "缺少 STEP 用户夹具: " << path << "(corpus/ 为 gitignore 内容)"; auto bodies1 = import_step(path); ASSERT_FALSE(bodies1.empty()); std::string tmp = VDE_TEST_TEMP_DIR "vde_rt_cube.STEP"; ASSERT_TRUE(export_step_file(tmp, bodies1)); auto bodies2 = import_step(tmp); ASSERT_FALSE(bodies2.empty()); EXPECT_EQ(bodies1[0].num_faces(), bodies2[0].num_faces()); std::remove(tmp.c_str()); } TEST(StepUserFile, ImportTestCubeTopology) { const std::string path = step("step/test_cube.STEP"); if (!file_exists(path)) GTEST_SKIP() << "缺少 STEP 用户夹具: " << path << "(corpus/ 为 gitignore 内容)"; auto bodies = import_step(path); ASSERT_FALSE(bodies.empty()); const auto& body = bodies[0]; EXPECT_EQ(body.num_faces(), 6) << "正方体应有6个面"; for (int i = 0; i < body.num_faces(); ++i) EXPECT_GT(body.face_area(i), 0.0) << "面 " << i << " 面积为0"; EXPECT_GE(body.num_edges(), 12) << "正方体至少12条边"; } TEST(StepUserFile, AP203Detection) { const std::string path = step("step/test_cube.STEP"); if (!file_exists(path)) GTEST_SKIP() << "缺少 STEP 用户夹具: " << path << "(corpus/ 为 gitignore 内容)"; std::ifstream f(path); ASSERT_TRUE(f.is_open()); std::string line; bool has_ap203 = false; while (std::getline(f, line)) { if (line.find("AP203") != std::string::npos) { has_ap203 = true; break; } } EXPECT_TRUE(has_ap203) << "文件应声明为 AP203"; auto bodies = import_step(path); EXPECT_FALSE(bodies.empty()) << "AP203 导入失败"; } // 调试测试 — 打印 step_last_error TEST(StepUserFile, DebugImportError) { const std::string path = step("step/test_cube.STEP"); if (!file_exists(path)) GTEST_SKIP() << "缺少 STEP 用户夹具: " << path << "(corpus/ 为 gitignore 内容)"; auto bodies = import_step(path); if (bodies.empty()) { auto err = step_last_error(); // StepError 没有 operator<<, 用 printf 格式 printf("IMPORT FAILED — StepError code: %d\n", static_cast(err)); } // 不 FAIL, 仅输出 SUCCEED(); }