Files
ViewDesignEngine/tests/drafting/test_layer_standards.cpp
T
hm 008768e7e4
Build & Test / build-and-test (push) Canceled after 0s
VDE Build & Test / build-and-test (push) Canceled after 0s
Build & Test / python-bindings (push) Canceled after 0s
feat(proposal): 落地 VDE-366 提案 API(图层专业过滤 + DWT 模板导出)
vde_drafting/layer_standards:
- filter_by_discipline:按图层名专业前缀过滤(ISO+"A-"/GB+"结" 等),空前缀返回全部。
- export_dwt:写出 DXF 格式 LAYER 表(名称/ACI 颜色/线型/线宽 组码 2/62/6/370),
  可被 AutoCAD 读为 DWT 模板。

测试:新增 tests/drafting/test_layer_standards.cpp(5/5 全绿)+ tests/drafting/CMakeLists.txt
- 前缀过滤只留匹配图层、空前缀返回全部。
- DWT 写盘后回读断言含 LAYER 表与已知图层名;非法路径返回 false。

文档:VDE-366.md 状态更正为 Fixed;核验表计数 37/40/0/234。
2026-10-05 03:00:03 +08:00

64 lines
2.1 KiB
C++

/**
* @file test_layer_standards.cpp
* @brief VDE-366:专业过滤 + DWT 模板导出
*/
#include <gtest/gtest.h>
#include "vde_drafting/layer_standards.h"
#include <fstream>
#include <sstream>
#include <cstdio>
#include <string>
using namespace vde::drafting::layer;
// ── filter_by_discipline ──
TEST(LayerStandardsTest, FilterByDiscipline_ISO_Architecture) {
const auto arch = filter_by_discipline(LayerStandardId::ISO_13567, "A-");
EXPECT_FALSE(arch.empty());
bool has_wall = false;
for (const auto& l : arch) {
EXPECT_EQ(l.name.rfind("A-", 0), 0u) << l.name; // 全部以 A- 开头
if (l.name == "A-WALL-M") has_wall = true;
}
EXPECT_TRUE(has_wall);
// 结构层不应出现
for (const auto& l : arch) EXPECT_NE(l.name.rfind("S-", 0), 0u);
}
TEST(LayerStandardsTest, FilterByDiscipline_GB_Structural) {
const auto st = filter_by_discipline(LayerStandardId::GB_T_18229, "结");
EXPECT_FALSE(st.empty());
for (const auto& l : st) EXPECT_EQ(l.name.rfind("结", 0), 0u) << l.name;
}
TEST(LayerStandardsTest, FilterByDiscipline_EmptyPrefixReturnsAll) {
const auto all = filter_by_discipline(LayerStandardId::AIA_NCS, "");
EXPECT_EQ(all.size(), load_standard(LayerStandardId::AIA_NCS).layers.size());
}
// ── export_dwt ──
TEST(LayerStandardsTest, ExportDwt_WritesLayerTable) {
const std::string path = std::string(VDE_TEST_TEMP_DIR) + "/vde366_layers.dwt";
ASSERT_TRUE(export_dwt(LayerStandardId::ISO_13567, path));
std::ifstream in(path);
ASSERT_TRUE(in.good());
std::stringstream ss; ss << in.rdbuf();
const std::string content = ss.str();
EXPECT_NE(content.find("LAYER"), std::string::npos);
EXPECT_NE(content.find("A-WALL-M"), std::string::npos);
EXPECT_NE(content.find("S-COLS-M"), std::string::npos);
EXPECT_NE(content.find("EOF"), std::string::npos);
std::remove(path.c_str());
}
TEST(LayerStandardsTest, ExportDwt_InvalidPathFails) {
// 不存在的目录 → 打开失败
EXPECT_FALSE(export_dwt(LayerStandardId::AIA_NCS,
"no_such_dir_xyz/sub/vde366.dwt"));
}