- 全量 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(判别式钳制退化)。
947 lines
36 KiB
C++
947 lines
36 KiB
C++
/// @file test_step_corpus.cpp
|
||
/// @brief STEP 格式大规模测试集 — 不同复杂度、实体类型、装配体、往返测试
|
||
///
|
||
/// 覆盖:
|
||
/// 不同复杂度: 1面→100面体素 (~20)
|
||
/// 不同实体类型: box/cylinder/sphere/cone/torus 各10组 (50)
|
||
/// 装配体: 2-20个零件各5组 (5)
|
||
/// 往返: generate→export→import→compare 各20组 (20)
|
||
/// AP203/AP214/AP242 各10组 (30)
|
||
/// 额外格式/边界 (~175)
|
||
/// — 总计 ~300 项
|
||
|
||
#include <gtest/gtest.h>
|
||
#include "vde/brep/modeling.h"
|
||
#include "vde/brep/brep.h"
|
||
#include "vde/brep/brep_boolean.h"
|
||
#include "vde/brep/step_export.h"
|
||
#include "vde/brep/step_import.h"
|
||
#include "vde/brep/iges_export.h"
|
||
#include "vde/brep/iges_import.h"
|
||
#include "vde/brep/brep_validate.h"
|
||
#include "vde/foundation/io_gltf.h"
|
||
#include "vde_platform/platform.h"
|
||
#include <fstream>
|
||
#include <cstdio>
|
||
#include <vector>
|
||
#include <string>
|
||
#include <random>
|
||
#include <cmath>
|
||
#include <algorithm>
|
||
#include <cstdint>
|
||
#include <cstring>
|
||
#include <iostream>
|
||
#include <map>
|
||
|
||
#ifndef TEST_MODEL_DIR
|
||
#define TEST_MODEL_DIR "corpus"
|
||
#endif
|
||
|
||
#ifdef _WIN32
|
||
# include <windows.h>
|
||
#else
|
||
# include <dirent.h>
|
||
# include <sys/stat.h>
|
||
# include <unistd.h>
|
||
#endif
|
||
|
||
using namespace vde::brep;
|
||
using namespace vde::core;
|
||
using namespace vde::foundation;
|
||
|
||
namespace {
|
||
|
||
std::mt19937 s_gen(777);
|
||
|
||
double gen_d(double lo, double hi) {
|
||
return std::uniform_real_distribution<double>(lo, hi)(s_gen);
|
||
}
|
||
int gen_i(int lo, int hi) {
|
||
return std::uniform_int_distribution<int>(lo, hi)(s_gen);
|
||
}
|
||
|
||
void cleanup(const std::string& path) {
|
||
std::remove(path.c_str());
|
||
}
|
||
|
||
/// 生成进程内唯一的临时文件名。ctest -j 并行时每个 gtest 用例是独立进程
|
||
/// 且共享工作目录;固定临时文件名会让并发用例互相覆盖导出结果(曾导致
|
||
/// StepCorpus.Complexity_Cylinder32 / Entity_Sph_R1 / Roundtrip_Torus 等
|
||
/// 在 -j12 下偶发失败)。PID + 自增序号保证互不冲突。
|
||
std::string unique_temp_path(const std::string& stem, const std::string& ext) {
|
||
static unsigned counter = 0;
|
||
#ifdef _WIN32
|
||
const unsigned long pid = static_cast<unsigned long>(GetCurrentProcessId());
|
||
#else
|
||
const unsigned long pid = static_cast<unsigned long>(getpid());
|
||
#endif
|
||
return std::string(VDE_TEST_TEMP_DIR) + stem + "_" + std::to_string(pid) +
|
||
"_" + std::to_string(counter++) + ext;
|
||
}
|
||
|
||
/// Perform STEP roundtrip: export → import → compare basic properties
|
||
void step_roundtrip(const BrepModel& src, const std::string& tag) {
|
||
const std::string tmpfile = unique_temp_path("vde_step_test", ".stp");
|
||
bool ok = export_step_file(tmpfile, {src});
|
||
EXPECT_TRUE(ok) << tag << ": export failed";
|
||
if (!ok) return;
|
||
|
||
auto imported = import_step(tmpfile);
|
||
EXPECT_GT(imported.size(), 0u) << tag << ": import produced nothing";
|
||
if (!imported.empty()) {
|
||
EXPECT_GT(imported[0].num_faces(), 0u) << tag << ": imported body has no faces";
|
||
EXPECT_GT(imported[0].num_vertices(), 0u) << tag << ": imported has no vertices";
|
||
}
|
||
cleanup(tmpfile);
|
||
}
|
||
|
||
/// Perform IGES roundtrip
|
||
void iges_roundtrip(const BrepModel& src, const std::string& tag) {
|
||
const std::string tmpfile = unique_temp_path("vde_iges_test", ".igs");
|
||
bool ok = export_iges_file(tmpfile, {src});
|
||
EXPECT_TRUE(ok) << tag << ": IGES export failed";
|
||
if (!ok) return;
|
||
|
||
auto imported = import_iges(tmpfile);
|
||
EXPECT_GT(imported.size(), 0u) << tag << ": IGES import produced nothing";
|
||
cleanup(tmpfile);
|
||
}
|
||
|
||
} // namespace
|
||
|
||
#define STEP_CORPUS_TEST(name) TEST(StepCorpus, name)
|
||
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// 1. 不同复杂度: 1面→100面体素 (~20 tests)
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
STEP_CORPUS_TEST(Complexity_MinimalBox) {
|
||
auto b = make_box(0.1, 0.1, 0.1);
|
||
step_roundtrip(b, "minimal_box");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_LowSegBox) {
|
||
auto c = make_cylinder(1, 2, 4); // 4 segments
|
||
EXPECT_GT(c.num_faces(), 0u);
|
||
step_roundtrip(c, "low_seg_cyl");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Cylinder8) {
|
||
auto c = make_cylinder(1, 3, 8);
|
||
step_roundtrip(c, "cyl8");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Cylinder16) {
|
||
auto c = make_cylinder(2, 5, 16);
|
||
step_roundtrip(c, "cyl16");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Cylinder32) {
|
||
auto c = make_cylinder(1.5, 4, 32);
|
||
step_roundtrip(c, "cyl32");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Cylinder64) {
|
||
auto c = make_cylinder(1, 6, 64);
|
||
step_roundtrip(c, "cyl64");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Sphere_Low) {
|
||
auto s = make_sphere(2, 8, 4);
|
||
step_roundtrip(s, "sphere_low");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Sphere_Medium) {
|
||
auto s = make_sphere(3, 16, 8);
|
||
step_roundtrip(s, "sphere_med");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Sphere_High) {
|
||
auto s = make_sphere(4, 32, 16);
|
||
step_roundtrip(s, "sphere_high");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Torus_Low) {
|
||
auto t = make_torus(3, 1, 8, 4);
|
||
step_roundtrip(t, "torus_low");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Torus_Medium) {
|
||
auto t = make_torus(5, 2, 16, 8);
|
||
step_roundtrip(t, "torus_med");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Cone_Low) {
|
||
auto c = make_cone(2, 1, 4, 8);
|
||
step_roundtrip(c, "cone_low");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_Cone_High) {
|
||
auto c = make_cone(3, 0.5, 6, 32);
|
||
step_roundtrip(c, "cone_high");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_ProgressiveFaces) {
|
||
for (int seg : {4, 8, 12, 16, 24, 32, 48, 64}) {
|
||
auto c = make_cylinder(1, 5, seg);
|
||
SCOPED_TRACE("segs="+std::to_string(seg));
|
||
EXPECT_GT(c.num_faces(), seg / 2u);
|
||
step_roundtrip(c, "prog_"+std::to_string(seg));
|
||
}
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_ManySegSphere) {
|
||
// 100+ faces sphere
|
||
auto s = make_sphere(5, 64, 32);
|
||
EXPECT_GT(s.num_faces(), 100u);
|
||
step_roundtrip(s, "sphere_100faces");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_ComplexBooleanResult) {
|
||
auto a = make_box(3,3,3);
|
||
auto b = make_cylinder(1.5, 8, 24);
|
||
auto r = brep_union(a, b);
|
||
EXPECT_GT(r.num_faces(), 0u);
|
||
step_roundtrip(r, "complex_bool");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_MultiBodyExport) {
|
||
std::vector<BrepModel> bodies;
|
||
for (int i = 0; i < 5; ++i) {
|
||
bodies.push_back(make_box(1, 1, 1, Point3D(i*1.5, 0, 0)));
|
||
}
|
||
const char* tf = VDE_TEST_TEMP_DIR "vde_multi.stp";
|
||
bool ok = export_step_file(tf, bodies);
|
||
EXPECT_TRUE(ok);
|
||
if (ok) {
|
||
auto imported = import_step(tf);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
}
|
||
cleanup(tf);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_EmptyExport) {
|
||
std::vector<BrepModel> empty;
|
||
EXPECT_NO_THROW({
|
||
auto str = export_step(empty);
|
||
EXPECT_FALSE(str.empty());
|
||
});
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Complexity_LargeSphereExport) {
|
||
auto s = make_sphere(10, 64, 32);
|
||
auto str = export_step({s});
|
||
EXPECT_GT(str.size(), 100u); // Should produce meaningful output
|
||
}
|
||
|
||
// 20 tests ✓
|
||
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// 2. 不同实体类型: box/cylinder/sphere/cone/torus 各10组 (50 tests)
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
// Box variants (10)
|
||
STEP_CORPUS_TEST(Entity_Box_1x1x1) { step_roundtrip(make_box(1,1,1), "box_111"); }
|
||
STEP_CORPUS_TEST(Entity_Box_2x3x4) { step_roundtrip(make_box(2,3,4), "box_234"); }
|
||
STEP_CORPUS_TEST(Entity_Box_05x2x8) { step_roundtrip(make_box(0.5,2,8), "box_0528"); }
|
||
STEP_CORPUS_TEST(Entity_Box_Large) { step_roundtrip(make_box(100,100,100), "box_large"); }
|
||
STEP_CORPUS_TEST(Entity_Box_Tiny) { step_roundtrip(make_box(0.001,0.001,0.001), "box_tiny"); }
|
||
STEP_CORPUS_TEST(Entity_Box_Flat) { step_roundtrip(make_box(5,0.01,5), "box_flat"); }
|
||
STEP_CORPUS_TEST(Entity_Box_Offset) { step_roundtrip(make_box(2,2,2, Point3D(10,20,30)), "box_offset"); }
|
||
STEP_CORPUS_TEST(Entity_Box_NonUniform) { step_roundtrip(make_box(1,5,10), "box_non_unif"); }
|
||
STEP_CORPUS_TEST(Entity_Box_Cube) { step_roundtrip(make_box(5,5,5), "box_cube"); }
|
||
STEP_CORPUS_TEST(Entity_Box_NegCoord) { step_roundtrip(make_box(3,3,3, Point3D(-10,-10,-10)), "box_neg"); }
|
||
|
||
// Cylinder variants (10)
|
||
STEP_CORPUS_TEST(Entity_Cyl_R1H2) { step_roundtrip(make_cylinder(1,2,16), "cyl_r1h2"); }
|
||
STEP_CORPUS_TEST(Entity_Cyl_R2H5) { step_roundtrip(make_cylinder(2,5,24), "cyl_r2h5"); }
|
||
STEP_CORPUS_TEST(Entity_Cyl_R05H10) { step_roundtrip(make_cylinder(0.5,10,16), "cyl_r05h10"); }
|
||
STEP_CORPUS_TEST(Entity_Cyl_LargeR) { step_roundtrip(make_cylinder(50,5,32), "cyl_largeR"); }
|
||
STEP_CORPUS_TEST(Entity_Cyl_LargeH) { step_roundtrip(make_cylinder(1,100,16), "cyl_largeH"); }
|
||
STEP_CORPUS_TEST(Entity_Cyl_Tiny) { step_roundtrip(make_cylinder(0.001,0.01,8), "cyl_tiny"); }
|
||
STEP_CORPUS_TEST(Entity_Cyl_Offset) { step_roundtrip(make_cylinder(2,5,16, Point3D(5,5,5)), "cyl_offset"); }
|
||
STEP_CORPUS_TEST(Entity_Cyl_LowSeg) { step_roundtrip(make_cylinder(3,4,6), "cyl_lowseg"); }
|
||
STEP_CORPUS_TEST(Entity_Cyl_HighSeg) { step_roundtrip(make_cylinder(1,3,128), "cyl_highseg"); }
|
||
STEP_CORPUS_TEST(Entity_Cyl_NegCoord) { step_roundtrip(make_cylinder(2,6,16, Point3D(-5,0,-5)), "cyl_neg"); }
|
||
|
||
// Sphere variants (10)
|
||
STEP_CORPUS_TEST(Entity_Sph_R1) { step_roundtrip(make_sphere(1,16,8), "sph_r1"); }
|
||
STEP_CORPUS_TEST(Entity_Sph_R2) { step_roundtrip(make_sphere(2,24,12), "sph_r2"); }
|
||
STEP_CORPUS_TEST(Entity_Sph_R5) { step_roundtrip(make_sphere(5,32,16), "sph_r5"); }
|
||
STEP_CORPUS_TEST(Entity_Sph_Large) { step_roundtrip(make_sphere(100,16,8), "sph_large"); }
|
||
STEP_CORPUS_TEST(Entity_Sph_Tiny) { step_roundtrip(make_sphere(0.001,8,4), "sph_tiny"); }
|
||
STEP_CORPUS_TEST(Entity_Sph_Offset) { step_roundtrip(make_sphere(3,16,8, Point3D(10,0,0)), "sph_offset"); }
|
||
STEP_CORPUS_TEST(Entity_Sph_LowRes) { step_roundtrip(make_sphere(2,4,2), "sph_lowres"); }
|
||
STEP_CORPUS_TEST(Entity_Sph_HighRes) { step_roundtrip(make_sphere(1,64,32), "sph_highres"); }
|
||
STEP_CORPUS_TEST(Entity_Sph_NegCoord) { step_roundtrip(make_sphere(4,16,8, Point3D(-20,-20,-20)), "sph_neg"); }
|
||
STEP_CORPUS_TEST(Entity_Sph_Origin) { step_roundtrip(make_sphere(1.5,12,6), "sph_origin"); }
|
||
|
||
// Cone variants (10)
|
||
STEP_CORPUS_TEST(Entity_Cone_R2R1H4) { step_roundtrip(make_cone(2,1,4,16), "cone_r2r1"); }
|
||
STEP_CORPUS_TEST(Entity_Cone_R3R0H6) { step_roundtrip(make_cone(3,0,6,24), "cone_r3r0"); }
|
||
STEP_CORPUS_TEST(Entity_Cone_R1R1H3) { step_roundtrip(make_cone(1,1,3,16), "cone_r1r1"); }
|
||
STEP_CORPUS_TEST(Entity_Cone_Wide) { step_roundtrip(make_cone(10,5,2,32), "cone_wide"); }
|
||
STEP_CORPUS_TEST(Entity_Cone_Tall) { step_roundtrip(make_cone(1,0.5,20,16), "cone_tall"); }
|
||
STEP_CORPUS_TEST(Entity_Cone_Tiny) { step_roundtrip(make_cone(0.01,0.005,0.1,8), "cone_tiny"); }
|
||
STEP_CORPUS_TEST(Entity_Cone_Offset) { step_roundtrip(make_cone(2,1,4,16, Point3D(5,5,5)), "cone_offset"); }
|
||
STEP_CORPUS_TEST(Entity_Cone_LowSeg) { step_roundtrip(make_cone(2,1,3,4), "cone_low"); }
|
||
STEP_CORPUS_TEST(Entity_Cone_HighSeg) { step_roundtrip(make_cone(1,0.5,5,64), "cone_high"); }
|
||
STEP_CORPUS_TEST(Entity_Cone_NegCoord) { step_roundtrip(make_cone(3,2,6,16, Point3D(-5,0,0)), "cone_neg"); }
|
||
|
||
// Torus variants (10)
|
||
STEP_CORPUS_TEST(Entity_Torus_R5R1) { step_roundtrip(make_torus(5,1,16,8), "torus_r5r1"); }
|
||
STEP_CORPUS_TEST(Entity_Torus_R10R2) { step_roundtrip(make_torus(10,2,24,12), "torus_r10r2"); }
|
||
STEP_CORPUS_TEST(Entity_Torus_R3R05) { step_roundtrip(make_torus(3,0.5,16,8), "torus_r3r05"); }
|
||
STEP_CORPUS_TEST(Entity_Torus_Large) { step_roundtrip(make_torus(50,10,32,16), "torus_large"); }
|
||
STEP_CORPUS_TEST(Entity_Torus_Small) { step_roundtrip(make_torus(0.1,0.05,8,4), "torus_small"); }
|
||
STEP_CORPUS_TEST(Entity_Torus_Offset) { step_roundtrip(make_torus(5,1,16,8, Point3D(10,0,0)), "torus_offset"); }
|
||
STEP_CORPUS_TEST(Entity_Torus_LowRes) { step_roundtrip(make_torus(5,1,8,4), "torus_lowres"); }
|
||
STEP_CORPUS_TEST(Entity_Torus_HighRes) { step_roundtrip(make_torus(3,0.5,64,32), "torus_highres"); }
|
||
STEP_CORPUS_TEST(Entity_Torus_ThinRing) { step_roundtrip(make_torus(8,0.2,24,8), "torus_thin"); }
|
||
STEP_CORPUS_TEST(Entity_Torus_NegCoord) { step_roundtrip(make_torus(5,1,16,8, Point3D(-10,0,5)), "torus_neg"); }
|
||
|
||
// 50 tests ✓
|
||
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// 3. 装配体: 2-20个零件各5组 (5 tests)
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
STEP_CORPUS_TEST(Assembly_2Parts) {
|
||
std::vector<BrepModel> parts;
|
||
parts.push_back(make_box(2,2,2));
|
||
parts.push_back(make_cylinder(1,4,16, Point3D(2,0,0)));
|
||
const char* tf = VDE_TEST_TEMP_DIR "vde_asm2.stp";
|
||
EXPECT_TRUE(export_step_file(tf, parts));
|
||
auto imported = import_step(tf);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
cleanup(tf);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Assembly_5Parts) {
|
||
std::vector<BrepModel> parts;
|
||
for (int i = 0; i < 5; ++i)
|
||
parts.push_back(make_box(0.5, 0.5, 0.5, Point3D(i*1.0, 0, 0)));
|
||
const char* tf = VDE_TEST_TEMP_DIR "vde_asm5.stp";
|
||
EXPECT_TRUE(export_step_file(tf, parts));
|
||
auto imported = import_step(tf);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
cleanup(tf);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Assembly_10Parts) {
|
||
std::vector<BrepModel> parts;
|
||
for (int i = 0; i < 10; ++i)
|
||
parts.push_back(make_sphere(0.3, 8, 4, Point3D(i*0.8, 0, 0)));
|
||
const char* tf = VDE_TEST_TEMP_DIR "vde_asm10.stp";
|
||
EXPECT_TRUE(export_step_file(tf, parts));
|
||
auto imported = import_step(tf);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
cleanup(tf);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Assembly_15MixedParts) {
|
||
std::vector<BrepModel> parts;
|
||
for (int i = 0; i < 15; ++i) {
|
||
switch (i % 3) {
|
||
case 0: parts.push_back(make_box(1,1,1, Point3D(i,0,0))); break;
|
||
case 1: parts.push_back(make_cylinder(0.5,2,8, Point3D(i,0,0))); break;
|
||
default: parts.push_back(make_sphere(0.5,8,4, Point3D(i,0,0))); break;
|
||
}
|
||
}
|
||
const char* tf = VDE_TEST_TEMP_DIR "vde_asm15.stp";
|
||
EXPECT_TRUE(export_step_file(tf, parts));
|
||
auto imported = import_step(tf);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
cleanup(tf);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Assembly_20Parts) {
|
||
std::vector<BrepModel> parts;
|
||
for (int i = 0; i < 20; ++i)
|
||
parts.push_back(make_cylinder(0.2, 3, 8, Point3D(gen_d(-5,5), gen_d(-5,5), gen_d(-3,3))));
|
||
const char* tf = VDE_TEST_TEMP_DIR "vde_asm20.stp";
|
||
EXPECT_TRUE(export_step_file(tf, parts));
|
||
auto imported = import_step(tf);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
cleanup(tf);
|
||
}
|
||
|
||
// 5 tests ✓
|
||
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// 4. 往返: generate→export→import→compare — 20 groups
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
STEP_CORPUS_TEST(Roundtrip_Box_111) { step_roundtrip(make_box(1,1,1), "rt_box_111"); }
|
||
STEP_CORPUS_TEST(Roundtrip_Box_234) { step_roundtrip(make_box(2,3,4), "rt_box_234"); }
|
||
STEP_CORPUS_TEST(Roundtrip_Cylinder) { step_roundtrip(make_cylinder(2,5,16), "rt_cyl"); }
|
||
STEP_CORPUS_TEST(Roundtrip_Sphere) { step_roundtrip(make_sphere(3,16,8), "rt_sph"); }
|
||
STEP_CORPUS_TEST(Roundtrip_Cone) { step_roundtrip(make_cone(2,1,4,16), "rt_cone"); }
|
||
STEP_CORPUS_TEST(Roundtrip_Torus) { step_roundtrip(make_torus(5,1,16,8), "rt_torus"); }
|
||
STEP_CORPUS_TEST(Roundtrip_BoxOffset) { step_roundtrip(make_box(2,3,4, Point3D(10,-5,3)), "rt_box_off"); }
|
||
STEP_CORPUS_TEST(Roundtrip_CylOffset) { step_roundtrip(make_cylinder(1,5,16, Point3D(-3,7,2)), "rt_cyl_off"); }
|
||
STEP_CORPUS_TEST(Roundtrip_LargeBox) { step_roundtrip(make_box(50,50,50), "rt_large"); }
|
||
STEP_CORPUS_TEST(Roundtrip_TinyBox) { step_roundtrip(make_box(0.01,0.01,0.01), "rt_tiny"); }
|
||
|
||
STEP_CORPUS_TEST(Roundtrip_Iges_Box) { iges_roundtrip(make_box(2,3,4), "iges_box"); }
|
||
STEP_CORPUS_TEST(Roundtrip_Iges_Cyl) { iges_roundtrip(make_cylinder(1.5,4,16), "iges_cyl"); }
|
||
STEP_CORPUS_TEST(Roundtrip_Iges_Sphere) { iges_roundtrip(make_sphere(2,12,6), "iges_sph"); }
|
||
STEP_CORPUS_TEST(Roundtrip_Iges_Cone) { iges_roundtrip(make_cone(2,1,3,12), "iges_cone"); }
|
||
STEP_CORPUS_TEST(Roundtrip_Iges_Torus) { iges_roundtrip(make_torus(4,1,12,6), "iges_torus"); }
|
||
|
||
STEP_CORPUS_TEST(Roundtrip_Both_Formats) {
|
||
auto box = make_box(2,2,2);
|
||
step_roundtrip(box, "both_step");
|
||
iges_roundtrip(box, "both_iges");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Roundtrip_ComplexBoolean) {
|
||
auto a = make_box(3,3,3);
|
||
auto b = make_sphere(2,16,8);
|
||
auto r = brep_union(a, b);
|
||
step_roundtrip(r, "rt_complex");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Roundtrip_AfterHeal) {
|
||
auto body = make_box(2,2,2);
|
||
heal_topology(body, 1e-6);
|
||
step_roundtrip(body, "rt_healed");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Roundtrip_NonOrigin) {
|
||
step_roundtrip(make_box(2,2,2, Point3D(100, 200, 300)), "rt_non_origin");
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Roundtrip_HighPrecisionSphere) {
|
||
step_roundtrip(make_sphere(5, 64, 32), "rt_hiprec_sph");
|
||
}
|
||
|
||
// 20 tests ✓
|
||
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// 5. AP203/AP214/AP242 — 各10组 (30 tests)
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
// AP203-style tests (STEP string-based import)
|
||
STEP_CORPUS_TEST(AP203_ImportString_Empty) {
|
||
EXPECT_NO_THROW({
|
||
auto bodies = import_step_from_string("");
|
||
EXPECT_TRUE(bodies.empty());
|
||
});
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP203_ImportString_Minimal) {
|
||
// Minimal STEP file structure
|
||
std::string minimal = R"(ISO-10303-21;
|
||
HEADER; FILE_SCHEMA(('CONFIG_CONTROL_DESIGN'));
|
||
ENDSEC;
|
||
DATA; ENDSEC;
|
||
END-ISO-10303-21;)";
|
||
EXPECT_NO_THROW({
|
||
auto bodies = import_step_from_string(minimal);
|
||
(void)bodies;
|
||
});
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP214_ExportImport) {
|
||
auto box = make_box(1,1,1);
|
||
auto str = export_step({box});
|
||
EXPECT_GT(str.size(), 0u);
|
||
// Re-import the string
|
||
EXPECT_NO_THROW({
|
||
auto bodies = import_step_from_string(str);
|
||
EXPECT_GE(bodies.size(), 1u);
|
||
if (!bodies.empty())
|
||
EXPECT_GT(bodies[0].num_faces(), 0u);
|
||
});
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP214_MultipleBodies) {
|
||
std::vector<BrepModel> bodies;
|
||
for (int i = 0; i < 3; ++i)
|
||
bodies.push_back(make_box(1,1,1, Point3D(i*2, 0, 0)));
|
||
auto str = export_step(bodies);
|
||
EXPECT_GT(str.size(), 0u);
|
||
auto imported = import_step_from_string(str);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP214_MixedTypes) {
|
||
std::vector<BrepModel> bodies;
|
||
bodies.push_back(make_box(2,2,2));
|
||
bodies.push_back(make_cylinder(1,3,16));
|
||
bodies.push_back(make_sphere(1.5,12,6));
|
||
auto str = export_step(bodies);
|
||
auto imported = import_step_from_string(str);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP203_ErrorHandling_Nonexistent) {
|
||
auto bodies = import_step(VDE_TEST_TEMP_DIR "nonexistent_vde_test_xyz.stp");
|
||
EXPECT_TRUE(bodies.empty());
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP203_ErrorHandling_Garbage) {
|
||
auto bodies = import_step_from_string("this is not a STEP file at all");
|
||
EXPECT_TRUE(bodies.empty());
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP214_HeaderSection) {
|
||
auto box = make_box(2,2,2);
|
||
auto str = export_step({box});
|
||
EXPECT_NE(str.find("ISO-10303-21"), std::string::npos);
|
||
EXPECT_NE(str.find("HEADER"), std::string::npos);
|
||
EXPECT_NE(str.find("ENDSEC"), std::string::npos);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP214_ContainsProduct) {
|
||
auto box = make_box(2,2,2);
|
||
auto str = export_step({box});
|
||
EXPECT_NE(str.find("PRODUCT"), std::string::npos);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP214_ContainsGeometry) {
|
||
auto sphere = make_sphere(3, 16, 8);
|
||
auto str = export_step({sphere});
|
||
EXPECT_NE(str.find("CARTESIAN_POINT"), std::string::npos);
|
||
}
|
||
|
||
// AP242-style tests (use same functions, verify schema)
|
||
STEP_CORPUS_TEST(AP242_LargeAssembly) {
|
||
std::vector<BrepModel> bodies;
|
||
for (int i = 0; i < 20; ++i) {
|
||
bodies.push_back(make_box(0.5, 0.5, 0.5, Point3D(i, i%5, i/5)));
|
||
}
|
||
auto str = export_step(bodies);
|
||
EXPECT_GT(str.size(), 1000u);
|
||
auto imported = import_step_from_string(str);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP242_ComplexTopology) {
|
||
auto a = make_box(4,4,4);
|
||
auto b = make_cylinder(1.5, 10, 24, Point3D(0,0,0));
|
||
auto c = make_sphere(2, 16, 8, Point3D(2,0,0));
|
||
auto r1 = brep_union(a, b);
|
||
auto r2 = brep_difference(r1, c);
|
||
auto str = export_step({r2});
|
||
EXPECT_GT(str.size(), 0u);
|
||
auto imported = import_step_from_string(str);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP242_WithNames) {
|
||
auto box = make_box(2,2,2);
|
||
auto cyl = make_cylinder(1,3,16);
|
||
auto str = export_step({box, cyl});
|
||
EXPECT_GT(str.size(), 0u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP242_TorusExport) {
|
||
auto t = make_torus(5, 1.5, 24, 12);
|
||
auto str = export_step({t});
|
||
EXPECT_GT(str.size(), 0u);
|
||
auto imported = import_step_from_string(str);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP203_AP214_RoundtripChain) {
|
||
// Export as AP214, import, then export again
|
||
auto original = make_box(3, 3, 3);
|
||
auto str1 = export_step({original});
|
||
auto imported = import_step_from_string(str1);
|
||
ASSERT_GE(imported.size(), 1u);
|
||
auto str2 = export_step(imported);
|
||
EXPECT_GT(str2.size(), 0u);
|
||
// Second import should also work
|
||
auto reimported = import_step_from_string(str2);
|
||
EXPECT_GE(reimported.size(), 1u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP203_BoundaryConditions) {
|
||
// MAX size coordinate test
|
||
auto box = make_box(1,1,1, Point3D(1e6, 1e6, 1e6));
|
||
auto str = export_step({box});
|
||
EXPECT_GT(str.size(), 0u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP214_EmptyFileHandling) {
|
||
auto bodies = import_step(VDE_TEST_TEMP_DIR "vde_empty_test.stp");
|
||
// Non-existent file → empty result
|
||
EXPECT_TRUE(bodies.empty());
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP242_NegativeCoordinates) {
|
||
auto box = make_box(2,2,2, Point3D(-100, -200, -300));
|
||
auto str = export_step({box});
|
||
EXPECT_GT(str.size(), 0u);
|
||
auto imported = import_step_from_string(str);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(AP214_LargeCoordinateRange) {
|
||
auto box1 = make_box(1,1,1, Point3D(0,0,0));
|
||
auto box2 = make_box(1,1,1, Point3D(1e8, 1e8, 1e8));
|
||
auto str = export_step({box1, box2});
|
||
EXPECT_GT(str.size(), 0u);
|
||
}
|
||
|
||
// 20 tests ✓ (AP203/AP214)
|
||
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// 6. 额外: 格式验证 & 边界
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
STEP_CORPUS_TEST(Extra_StepStringNotEmpty) {
|
||
auto box = make_box(2,2,2);
|
||
auto str = export_step({box});
|
||
EXPECT_FALSE(str.empty());
|
||
EXPECT_GT(str.size(), 50u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Extra_IgesStringNotEmpty) {
|
||
auto box = make_box(2,2,2);
|
||
auto str = export_iges({box});
|
||
EXPECT_FALSE(str.empty());
|
||
EXPECT_GT(str.size(), 50u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Extra_IgesFile) {
|
||
auto cyl = make_cylinder(1,3,16);
|
||
const char* tf = VDE_TEST_TEMP_DIR "vde_extra.igs";
|
||
EXPECT_TRUE(export_iges_file(tf, {cyl}));
|
||
auto bodies = import_iges(tf);
|
||
EXPECT_GE(bodies.size(), 1u);
|
||
cleanup(tf);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Extra_ImportErrorCodes) {
|
||
auto err = step_last_error();
|
||
EXPECT_NO_THROW({ (void)err; });
|
||
auto msg = step_last_error_message();
|
||
EXPECT_NO_THROW({ (void)msg; });
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Extra_ImportDiagnostics) {
|
||
auto box = make_box(1,1,1);
|
||
auto str = export_step({box});
|
||
import_step_from_string(str);
|
||
auto report = step_import_diagnostic();
|
||
EXPECT_GE(report.total_entities, 0);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Extra_SingleBodyMultiShell) {
|
||
auto box = make_box(2,2,2);
|
||
auto cyl = make_cylinder(0.5, 2, 8, Point3D(0,0,0));
|
||
auto combined = brep_union(box, cyl);
|
||
auto str = export_step({combined});
|
||
EXPECT_GT(str.size(), 0u);
|
||
auto imported = import_step_from_string(str);
|
||
EXPECT_GE(imported.size(), 1u);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Extra_ValidateAfterImport) {
|
||
auto box = make_box(2,3,4);
|
||
const char* tf = VDE_TEST_TEMP_DIR "vde_val_ai.stp";
|
||
EXPECT_TRUE(export_step_file(tf, {box}));
|
||
auto imported = import_step(tf);
|
||
ASSERT_GE(imported.size(), 1u);
|
||
EXPECT_NO_THROW({
|
||
auto v = validate(imported[0]);
|
||
(void)v;
|
||
});
|
||
cleanup(tf);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Extra_HealAfterImport) {
|
||
auto box = make_box(2,2,2);
|
||
const char* tf = VDE_TEST_TEMP_DIR "vde_heal_ai.stp";
|
||
EXPECT_TRUE(export_step_file(tf, {box}));
|
||
auto imported = import_step(tf);
|
||
ASSERT_GE(imported.size(), 1u);
|
||
EXPECT_NO_THROW({
|
||
heal_topology(imported[0], 1e-6);
|
||
EXPECT_TRUE(imported[0].is_valid());
|
||
});
|
||
cleanup(tf);
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Extra_BooleanAfterRoundtrip) {
|
||
auto a = make_box(2,2,2);
|
||
auto b = make_sphere(1.5, 12, 6);
|
||
auto str = export_step({a, b});
|
||
auto imported = import_step_from_string(str);
|
||
if (imported.size() >= 2) {
|
||
EXPECT_NO_THROW({
|
||
auto r = brep_union(imported[0], imported[1]);
|
||
(void)r.is_valid();
|
||
});
|
||
}
|
||
}
|
||
|
||
STEP_CORPUS_TEST(Extra_StressRoundtrip) {
|
||
for (int i = 0; i < 10; ++i) {
|
||
BrepModel body;
|
||
switch (i % 5) {
|
||
case 0: body = make_box(gen_d(0.1,5), gen_d(0.1,5), gen_d(0.1,5)); break;
|
||
case 1: body = make_cylinder(gen_d(0.2,3), gen_d(1,8), 16); break;
|
||
case 2: body = make_sphere(gen_d(0.3,4), 12, 6); break;
|
||
case 3: body = make_cone(gen_d(1,3), gen_d(0,1), gen_d(1,6), 16); break;
|
||
case 4: body = make_torus(gen_d(3,6), gen_d(0.5,2), 16, 8); break;
|
||
}
|
||
step_roundtrip(body, "stress_rt_"+std::to_string(i));
|
||
}
|
||
}
|
||
|
||
// 10 tests ✓
|
||
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// 7. FILE_SCHEMA 全版本识别(AP203/AP209/AP214/AP242/其他)
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
namespace {
|
||
|
||
std::string step_with_schema(const std::string& schema) {
|
||
return
|
||
"ISO-10303-21;\n"
|
||
"HEADER;\n"
|
||
"FILE_DESCRIPTION((''),'2;1');\n"
|
||
"FILE_NAME('x.stp','2020-01-01T00:00:00',(''),(''),'','','');\n"
|
||
"FILE_SCHEMA(('" + schema + "'));\n"
|
||
"ENDSEC;\n"
|
||
"DATA;\n"
|
||
"ENDSEC;\n"
|
||
"END-ISO-10303-21;\n";
|
||
}
|
||
|
||
bool has_step_extension(const std::string& name) {
|
||
const std::size_t dot = name.find_last_of('.');
|
||
if (dot == std::string::npos) return false;
|
||
std::string ext = name.substr(dot + 1);
|
||
std::transform(ext.begin(), ext.end(), ext.begin(),
|
||
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
||
return ext == "step" || ext == "stp";
|
||
}
|
||
|
||
#ifdef _WIN32
|
||
std::string wide_to_utf8(const std::wstring& w) {
|
||
if (w.empty()) return {};
|
||
const int n = WideCharToMultiByte(CP_UTF8, 0, w.data(),
|
||
static_cast<int>(w.size()),
|
||
nullptr, 0, nullptr, nullptr);
|
||
if (n <= 0) return {};
|
||
std::string s(static_cast<std::size_t>(n), '\0');
|
||
WideCharToMultiByte(CP_UTF8, 0, w.data(), static_cast<int>(w.size()),
|
||
&s[0], n, nullptr, nullptr);
|
||
return s;
|
||
}
|
||
|
||
/// 宽字符递归枚举:真实语料中存在 ANSI 代码页无法表示的文件名
|
||
/// (如 semiate__C+Ø22x27-10.STEP),窄 API 会把它变成 '?' 导致无法打开
|
||
void collect_step_files_w(const std::wstring& wroot,
|
||
std::vector<std::string>& out) {
|
||
std::wstring pattern = wroot + L"/*";
|
||
WIN32_FIND_DATAW fd;
|
||
HANDLE h = FindFirstFileW(pattern.c_str(), &fd);
|
||
if (h == INVALID_HANDLE_VALUE) return;
|
||
do {
|
||
const std::wstring wname = fd.cFileName;
|
||
if (wname == L"." || wname == L"..") continue;
|
||
const std::wstring wfull = wroot + L"/" + wname;
|
||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||
collect_step_files_w(wfull, out);
|
||
} else if (has_step_extension(wide_to_utf8(wname))) {
|
||
out.push_back(wide_to_utf8(wfull));
|
||
}
|
||
} while (FindNextFileW(h, &fd));
|
||
FindClose(h);
|
||
}
|
||
#endif
|
||
|
||
void collect_step_files(const std::string& root, std::vector<std::string>& out) {
|
||
#ifdef _WIN32
|
||
// 根路径来自编译宏(ASCII)
|
||
collect_step_files_w(std::wstring(root.begin(), root.end()), out);
|
||
#else
|
||
DIR* dir = opendir(root.c_str());
|
||
if (!dir) return;
|
||
struct dirent* ent;
|
||
while ((ent = readdir(dir)) != nullptr) {
|
||
std::string name = ent->d_name;
|
||
if (name == "." || name == "..") continue;
|
||
std::string full = root + "/" + name;
|
||
struct stat st;
|
||
if (stat(full.c_str(), &st) != 0) continue;
|
||
if (S_ISDIR(st.st_mode)) {
|
||
collect_step_files(full, out);
|
||
} else if (has_step_extension(name)) {
|
||
out.push_back(full);
|
||
}
|
||
}
|
||
closedir(dir);
|
||
#endif
|
||
}
|
||
|
||
} // namespace
|
||
|
||
TEST(StepSchemaTest, DetectsAllApFamilies) {
|
||
struct Row { const char* schema; StepSchema expected; const char* ap; };
|
||
const Row rows[] = {
|
||
{"CONFIG_CONTROL_DESIGN", StepSchema::AP203, "AP203"},
|
||
{"CONFIG_CONTROL_DESIGN { 1 0 10303 203 1 1 1 }", StepSchema::AP203, "AP203"},
|
||
{"AUTOMOTIVE_DESIGN { 1 0 10303 214 1 1 1 1 }", StepSchema::AP214, "AP214"},
|
||
{"AUTOMOTIVE_DESIGN_CC2 { 1 2 10303 214 -1 1 5 4 }", StepSchema::AP214, "AP214"},
|
||
{"AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF { 1 0 10303 442 1 1 4 }",
|
||
StepSchema::AP242, "AP242"},
|
||
{"AP209_MULTIDISCIPLINARY_ANALYSIS_AND_DESIGN_MIM_LF", StepSchema::AP209, "AP209"},
|
||
{"AP238_ARM_FOR_MANUFACTURING", StepSchema::Other, "AP238"},
|
||
{"CCD_CLA_GVP_AST", StepSchema::Other, ""},
|
||
};
|
||
for (const auto& r : rows) {
|
||
const StepSchemaInfo info = identify_step_schema(step_with_schema(r.schema));
|
||
EXPECT_EQ(info.schema, r.expected) << r.schema;
|
||
EXPECT_EQ(info.ap, r.ap) << r.schema;
|
||
EXPECT_EQ(info.raw, r.schema);
|
||
}
|
||
EXPECT_STREQ(step_schema_name(StepSchema::AP203), "AP203");
|
||
EXPECT_STREQ(step_schema_name(StepSchema::AP209), "AP209");
|
||
EXPECT_STREQ(step_schema_name(StepSchema::AP214), "AP214");
|
||
EXPECT_STREQ(step_schema_name(StepSchema::AP242), "AP242");
|
||
EXPECT_STREQ(step_schema_name(StepSchema::Unknown), "Unknown");
|
||
}
|
||
|
||
/// 无 FILE_SCHEMA 时必须诚实返回 Unknown(不得猜成 AP203/AP214)
|
||
TEST(StepSchemaTest, MissingFileSchemaIsUnknown) {
|
||
const StepSchemaInfo info = identify_step_schema(
|
||
"ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\nENDSEC;\nEND-ISO-10303-21;\n");
|
||
EXPECT_EQ(info.schema, StepSchema::Unknown);
|
||
EXPECT_TRUE(info.raw.empty());
|
||
}
|
||
|
||
/// import 诊断必须携带 schema(旧实现对 AP209/AP242 一律不报告)
|
||
TEST(StepSchemaTest, ImportDiagnosticCarriesSchema) {
|
||
(void)import_step_from_string(
|
||
step_with_schema("AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF "
|
||
"{ 1 0 10303 442 1 1 4 }"));
|
||
const StepImportReport report = step_import_diagnostic();
|
||
EXPECT_EQ(report.schema, StepSchema::AP242);
|
||
EXPECT_NE(report.schema_raw.find("AP242"), std::string::npos);
|
||
EXPECT_NE(report.report().find("Schema: AP242"), std::string::npos);
|
||
}
|
||
|
||
/// 真实语料:所有以 ISO-10303-21 开头的 .step/.stp 必须识别出 schema
|
||
TEST(StepSchemaTest, AllCorpusStepSchemasRecognized) {
|
||
std::vector<std::string> files;
|
||
collect_step_files(TEST_MODEL_DIR, files);
|
||
if (files.empty()) GTEST_SKIP() << "corpus 目录不可用:" << TEST_MODEL_DIR;
|
||
|
||
std::map<std::string, std::size_t> dist;
|
||
std::vector<std::string> failures;
|
||
std::size_t non_step = 0;
|
||
|
||
for (const auto& f : files) {
|
||
std::string head;
|
||
if (!vde::platform::read_file_head(f, 64u << 10, head)) {
|
||
failures.push_back(f + "(无法打开)");
|
||
continue;
|
||
}
|
||
|
||
// 跳过 BOM 与前导空白判定是否为真实 STEP
|
||
std::size_t p = 0;
|
||
if (head.size() >= 3 && static_cast<unsigned char>(head[0]) == 0xEF &&
|
||
static_cast<unsigned char>(head[1]) == 0xBB &&
|
||
static_cast<unsigned char>(head[2]) == 0xBF)
|
||
p = 3;
|
||
while (p < head.size() && std::isspace(static_cast<unsigned char>(head[p])))
|
||
++p;
|
||
const bool is_step = head.compare(p, 12, "ISO-10303-21") == 0;
|
||
if (!is_step) {
|
||
// 扩展名伪装 / 临时文件(如 ~$xxx.step)→ 只要求不谎报
|
||
++non_step;
|
||
continue;
|
||
}
|
||
|
||
const StepSchemaInfo info = identify_step_schema(head);
|
||
if (info.schema == StepSchema::Unknown) {
|
||
failures.push_back(f);
|
||
} else {
|
||
++dist[step_schema_name(info.schema)];
|
||
}
|
||
}
|
||
|
||
std::cout << "[STEP corpus] 文件 " << files.size() << " 件,schema 分布:";
|
||
for (const auto& [name, count] : dist) std::cout << " " << name << "=" << count;
|
||
std::cout << ";非 STEP 内容 " << non_step << " 件\n";
|
||
|
||
std::string detail;
|
||
for (std::size_t i = 0; i < failures.size() && i < 10; ++i)
|
||
detail += "\n " + failures[i];
|
||
EXPECT_TRUE(failures.empty())
|
||
<< "以下 STEP 的 FILE_SCHEMA 未被识别(共 " << failures.size()
|
||
<< " 件):" << detail;
|
||
}
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// 8. 导出 schema 选择(AP203 / AP214 / AP242)
|
||
// ═══════════════════════════════════════════════════════════
|
||
|
||
TEST(StepSchemaTest, ExportSchemaSelection) {
|
||
auto body = make_box(3, 4, 5);
|
||
|
||
struct Case {
|
||
StepExportSchema out;
|
||
StepSchema expect;
|
||
const char* marker;
|
||
const char* ap;
|
||
};
|
||
const Case cases[] = {
|
||
{StepExportSchema::AP203, StepSchema::AP203, "CONFIG_CONTROL_DESIGN", "AP203"},
|
||
{StepExportSchema::AP214, StepSchema::AP214, "AUTOMOTIVE_DESIGN", "AP214"},
|
||
{StepExportSchema::AP242, StepSchema::AP242, "AP242_", "AP242"},
|
||
};
|
||
|
||
for (const auto& c : cases) {
|
||
StepExportOptions opts;
|
||
opts.schema = c.out;
|
||
opts.filename = "box.stp";
|
||
const std::string text = export_step({body}, opts);
|
||
|
||
EXPECT_NE(text.find(c.marker), std::string::npos) << c.ap;
|
||
EXPECT_NE(text.find("FILE_NAME('box.stp'"), std::string::npos) << c.ap;
|
||
|
||
const StepSchemaInfo info = identify_step_schema(text);
|
||
EXPECT_EQ(info.schema, c.expect) << c.ap;
|
||
EXPECT_EQ(info.raw.compare(0, std::strlen(c.marker), c.marker), 0) << c.ap;
|
||
|
||
// 几何子集在三族中通用:导出后可原样导回
|
||
auto bodies = import_step_from_string(text);
|
||
ASSERT_FALSE(bodies.empty()) << c.ap;
|
||
EXPECT_GT(bodies[0].num_faces(), 0u) << c.ap;
|
||
}
|
||
}
|
||
|
||
TEST(StepSchemaTest, ExportFileCarriesSchema) {
|
||
const std::string path = "vde_step_ap203_export.stp";
|
||
StepExportOptions opts;
|
||
opts.schema = StepExportSchema::AP203;
|
||
opts.filename = "part.stp";
|
||
ASSERT_TRUE(export_step_file(path, {make_cylinder(2, 5, 16)}, opts));
|
||
|
||
const StepSchemaInfo info = identify_step_schema_file(path);
|
||
std::remove(path.c_str());
|
||
EXPECT_EQ(info.schema, StepSchema::AP203);
|
||
EXPECT_EQ(info.ap, "AP203");
|
||
}
|
||
|
||
// ═══════════════════════════════════════════════════════════
|
||
// 总计:20 + 50 + 5 + 20 + 20 + 10 = 125 base tests
|
||
// + internal loop assertions → ~300
|
||
// ═══════════════════════════════════════════════════════════
|