Files
hm 1efbeccaca test: 语料缺失跳过 + 工业格式契约 + 并行抖动修复 + 回归期望对齐
- 全量 ctest 基线 29 failures 分类处置:真实内核缺陷由本分支其它提交修复,
  本提交处理测试基础设施问题。
- 缺外部语料(corpus/ 已 gitignore)的用例改为 GTEST_SKIP 并给出检索路径:
  StepUserFile 6 项(corpus/step/test_cube.STEP)、Io3mfTest 2 项
  (corpus/3mf/*.3mf)、DxfDrawingCorpus.FlangeSampleHasRichContent。
- 并行 ctest 抖动(-j12 下偶发失败)根因:测试共享固定临时文件名。改为
  PID+计数器唯一路径:test_step_corpus(STEP/IGES roundtrip)、test_dwg
  (DwgChannel 桩转换器/输入/夹具)。`ctest -j12 --repeat until-fail:3`
  396 次 0 失败。
- 工业格式契约:read_file_bytes 改 bool 返回不抛异常;import_jt /
  import_parasolid_xt / import_acis_sat 对空路径/不可读文件返回空 BrepModel
  (与 import_step/import_iges 一致;import_ifc 保持原契约),export_jt 返回
  f.good();同步更新 3 个 EXPECT_THROW 用例。
- 回归期望对齐:解析球面 make_sphere(r, su, sv) 面数契约 = su·sv
  (Sphere_1000PlusFaces/5000PlusFaces/Heal_LargeModel/Export_LargeMesh 调整到
  真实契约并保持大模型意图);NURBS 曲率可视化测试容忍离散 H/K 在尖锐顶点
  不满足 H²≥K(判别式钳制退化)。
2026-10-25 16:12:47 +08:00

126 lines
4.4 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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>
#include <string>
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<int>(err));
}
// 不 FAIL, 仅输出
SUCCEED();
}