Files
ViewDesignEngine/tests/foundation/test_step_user_files.cpp
T
hm 960d9cb445 chore(repo): 语料统一迁移至根 corpus/(tests/data 停用,不入 git)
测试/探针/演示的目录宏与源码默认路径从 tests/data 切到 CMAKE_SOURCE_DIR/corpus(含 real/realfile/drawing);test_dxf_drawing 的 drawing 语料宏同步。.gitignore 追加 corpus/、io_demo_out/ 与根目录 *.log/*.txt 排查产物。
2026-09-07 22:52:06 +08:00

92 lines
2.8 KiB
C++

#include <gtest/gtest.h>
#include "vde/brep/step_import.h"
#include "vde/brep/brep.h"
#include "vde/brep/step_export.h"
#include "vde/core/aabb.h"
#include <fstream>
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;
}
TEST(StepUserFile, FileExists) {
std::ifstream f(step("step/test_cube.STEP"));
ASSERT_TRUE(f.is_open()) << "找不到文件: " << step("step/test_cube.STEP");
}
TEST(StepUserFile, ImportTestCube) {
auto bodies = import_step(step("step/test_cube.STEP"));
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) {
auto bodies1 = import_step(step("step/test_cube.STEP"));
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) {
auto bodies = import_step(step("step/test_cube.STEP"));
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) {
std::ifstream f(step("step/test_cube.STEP"));
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(step("step/test_cube.STEP"));
EXPECT_FALSE(bodies.empty()) << "AP203 导入失败";
}
// 调试测试 — 打印 step_last_error
TEST(StepUserFile, DebugImportError) {
auto bodies = import_step(step("step/test_cube.STEP"));
if (bodies.empty()) {
auto err = step_last_error();
// StepError 没有 operator<<, 用 printf 格式
printf("IMPORT FAILED — StepError code: %d\n", static_cast<int>(err));
}
// 不 FAIL, 仅输出
SUCCEED();
}