Files
ViewDesignEngine/tests/drafting/test_drawing_standards_profiles.cpp
hm caf3ebae68 补齐 DIN/BSI/GOST 内置标准列表(D-09 尾项)
vde_drafting:
- 新增 DinStandard(DIN 6771 / DIN ISO 128):DIMTXT/DIMASZ 3.5、第一角、
  公制、小数位 2、线宽组 0.35/0.50/0.70,含 description/preferred_scales/
  paper_size_spec(DIN 476)。
- builtin_style 支持 DIN;registry 增加 din 条目(共 7 项);find 与
  is_valid_standard 归一化大小写、版本后缀("DIN:2006" 等)并把对外名称
  "BSI" 归一为注册 id "bs";standard_description 走归一化解析。
- GOST 样式对齐 GOST:2006 标准族:箭头 3.5、字宽比 1.0、线宽 0.30/0.60;
  BS 样式对齐 BSI:2020:箭头 3.5、字宽比 1.0、线宽 0.25/0.50。

brep/auto_dimensioning:
- standard_defaults 的 DIN/BS/GOST 箭头尺寸 3.0 → 3.5(DIMASZ 契约)。
- dimension_standards 支持 "BSI" 与版本后缀名称("DIN:2006"/"GOST:2006"
  等),未知名称仍回退 ISO。

测试:
- 新增 tests/drafting/test_drawing_standards_profiles.cpp(12 项断言:DIN/
  BSI/GOST 指标、名称解析、registry、以名切换)。
- test_auto_dimensioning 追加 DIN/BS/GOST 默认值与名称解析、ISO/ANSI/JIS
  默认值回归断言。

回归:ISO/ANSI/JIS 默认样式与既有黄金字节不变(drawing_sheet、
drafting_intelligence、layer_standards、tolerance_chain、auto_dimensioning、
constraint_solver_3d、dwg_tables、dxf_tables、dwg_writer 全绿)。
2026-11-17 21:21:53 +08:00

195 lines
9.2 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.
// ═══════════════════════════════════════════════════════════════════════════
// test_drawing_standards_profiles.cpp
//
// D-09 尾项:DIN / BSI / GOST 不在 VDE engine 自带标准列表 — 补齐后的回归用例
//
// 验证:
// 1. DIN/BS/GOST 标准样式指标与宿主 DIN:2006 / BSI:2020 / GOST:2006 标准族对齐;
// 2. 标准注册表包含 din,find/is_valid_standard 兼容大小写与版本后缀
// ("DIN" / "DIN:2006" / "BSI" / "GOST:2006");
// 3. apply_standard_by_name 不再把 DIN/BS/GOST 静默回退为 ISO 样式;
// 4. ISO / ANSI / JIS 既有默认样式保持不变(默认等价回归)。
// ═══════════════════════════════════════════════════════════════════════════
#include <gtest/gtest.h>
#include "vde_drafting/drawing_standards.h"
#include <algorithm>
#include <string>
#include <vector>
using namespace vde::drafting;
namespace {
/// 判断 available_standards() 列表是否包含指定标准名
bool contains_name(const std::vector<std::string>& list, const std::string& value) {
return std::find(list.begin(), list.end(), value) != list.end();
}
} // namespace
// ═══════════════════════════════════════════════════════════
// 默认等价:ISO / ANSI / JIS 样式不变
// ═══════════════════════════════════════════════════════════
TEST(DrawingStandardsProfileTest, IsoStyleDefaultsUnchanged) {
const auto s = IsoStandard::create_style();
EXPECT_DOUBLE_EQ(s.text_height, 3.5);
EXPECT_DOUBLE_EQ(s.text_width_factor, 0.7);
EXPECT_DOUBLE_EQ(s.arrow_length, 3.5);
EXPECT_DOUBLE_EQ(s.line_width_thin, 0.25);
EXPECT_DOUBLE_EQ(s.line_width_thick, 0.50);
EXPECT_EQ(s.projection_angle, ProjectionAngle::FirstAngle);
EXPECT_EQ(s.unit, DimensionUnit::Millimeter);
}
TEST(DrawingStandardsProfileTest, AnsiAndJisStyleDefaultsUnchanged) {
const auto a = AnsiStandard::create_style();
EXPECT_DOUBLE_EQ(a.text_height, 3.0);
EXPECT_DOUBLE_EQ(a.arrow_length, 3.5);
EXPECT_EQ(a.projection_angle, ProjectionAngle::ThirdAngle);
EXPECT_EQ(a.unit, DimensionUnit::Inch);
EXPECT_TRUE(a.show_trailing_zeros);
const auto j = JisStandard::create_style();
EXPECT_DOUBLE_EQ(j.text_height, 3.5);
EXPECT_EQ(j.cutting_plane, LineType::Chain);
EXPECT_EQ(j.projection_angle, ProjectionAngle::FirstAngle);
}
// ═══════════════════════════════════════════════════════════
// DIN / BSI / GOST 样式指标(与宿主标准族契约对齐)
// ═══════════════════════════════════════════════════════════
TEST(DrawingStandardsProfileTest, DinStandardMatchesHostContract) {
const auto s = DinStandard::create_style();
EXPECT_DOUBLE_EQ(s.text_height, 3.5); // DIMTXT
EXPECT_DOUBLE_EQ(s.arrow_length, 3.5); // DIMASZ
EXPECT_EQ(s.arrow_style, ArrowStyle::Filled);
EXPECT_DOUBLE_EQ(s.text_width_factor, 1.0);
EXPECT_DOUBLE_EQ(s.line_width_thin, 0.35); // 线宽 0.70 / 0.35
EXPECT_DOUBLE_EQ(s.line_width_thick, 0.70);
EXPECT_GT(s.line_width_thick, s.line_width_thin);
EXPECT_EQ(s.projection_angle, ProjectionAngle::FirstAngle);
EXPECT_EQ(s.unit, DimensionUnit::Millimeter);
EXPECT_FALSE(DinStandard::description().empty());
EXPECT_FALSE(DinStandard::preferred_scales().empty());
EXPECT_NE(DinStandard::paper_size_spec("A4").find("DIN 476"), std::string::npos);
}
TEST(DrawingStandardsProfileTest, BsStandardMatchesHostContract) {
const auto s = BsStandard::create_style();
EXPECT_DOUBLE_EQ(s.text_height, 3.5);
EXPECT_DOUBLE_EQ(s.arrow_length, 3.5);
EXPECT_DOUBLE_EQ(s.text_width_factor, 1.0);
EXPECT_DOUBLE_EQ(s.line_width_thin, 0.25); // 线宽 0.50 / 0.25
EXPECT_DOUBLE_EQ(s.line_width_thick, 0.50);
EXPECT_EQ(s.projection_angle, ProjectionAngle::FirstAngle);
EXPECT_EQ(s.unit, DimensionUnit::Millimeter);
}
TEST(DrawingStandardsProfileTest, GostStandardMatchesHostContract) {
const auto s = GostStandard::create_style();
EXPECT_DOUBLE_EQ(s.text_height, 3.5);
EXPECT_DOUBLE_EQ(s.arrow_length, 3.5);
EXPECT_DOUBLE_EQ(s.text_width_factor, 1.0);
EXPECT_DOUBLE_EQ(s.line_width_thin, 0.30); // 线宽 0.60 / 0.30
EXPECT_DOUBLE_EQ(s.line_width_thick, 0.60);
EXPECT_EQ(s.projection_angle, ProjectionAngle::FirstAngle);
EXPECT_EQ(s.unit, DimensionUnit::Millimeter);
}
// ═══════════════════════════════════════════════════════════
// apply_standard_by_name:不再回退 ISO
// ═══════════════════════════════════════════════════════════
TEST(DrawingStandardsProfileTest, ApplyStandardByNameResolvesDin) {
const std::vector<ProjectionView> views;
StandardOptions opts;
const auto ctx = drawing::apply_standard_by_name(views, "DIN", opts);
EXPECT_EQ(ctx.standard_name, "DIN");
EXPECT_DOUBLE_EQ(ctx.style.line_width_thick, 0.70); // ISO 回退为 0.50
EXPECT_DOUBLE_EQ(ctx.style.line_width_thin, 0.35); // ISO 回退为 0.25
}
TEST(DrawingStandardsProfileTest, ApplyStandardByNameAcceptsVersionSuffix) {
const std::vector<ProjectionView> views;
StandardOptions opts;
const auto din = drawing::apply_standard_by_name(views, "DIN:2006", opts);
EXPECT_DOUBLE_EQ(din.style.line_width_thick, 0.70);
const auto bsi = drawing::apply_standard_by_name(views, "BSI:2020", opts);
EXPECT_DOUBLE_EQ(bsi.style.text_width_factor, 1.0); // ISO 回退为 0.7
const auto gost = drawing::apply_standard_by_name(views, "GOST:2006", opts);
EXPECT_DOUBLE_EQ(gost.style.line_width_thick, 0.60); // ISO 回退为 0.50
}
TEST(DrawingStandardsProfileTest, RealTimeSwitchSupportsDin) {
drawing::RealTimeStdSwitch sw;
EXPECT_TRUE(sw.switch_to("DIN:2006"));
EXPECT_DOUBLE_EQ(sw.current_style().line_width_thick, 0.70);
// 切换预览:ISO → DIN 应有线宽差异
const auto changes = drawing::preview_changes(IsoStandard::create_style(), "DIN");
EXPECT_FALSE(changes.empty());
}
// ═══════════════════════════════════════════════════════════
// 标准注册表 / 名称解析
// ═══════════════════════════════════════════════════════════
TEST(DrawingStandardsProfileTest, RegistryListsSevenStandards) {
const auto reg = standards::registry();
EXPECT_EQ(reg.size(), static_cast<size_t>(7));
const auto din = standards::find("din");
ASSERT_TRUE(din.has_value());
EXPECT_EQ(din->id, "din");
EXPECT_EQ(din->projection, ProjectionAngle::FirstAngle);
EXPECT_EQ(din->preferred_unit, DimensionUnit::Millimeter);
EXPECT_FALSE(din->description.empty());
EXPECT_FALSE(din->supported_paper_sizes.empty());
}
TEST(DrawingStandardsProfileTest, FindNormalizesCaseAliasAndVersion) {
// 大小写与版本后缀
EXPECT_TRUE(standards::find("DIN").has_value());
EXPECT_TRUE(standards::find("DIN:2006").has_value());
EXPECT_TRUE(standards::find("GOST:2006").has_value());
// 对外名称 BSI 归一为注册 id bs
const auto bsi = standards::find("BSI");
ASSERT_TRUE(bsi.has_value());
EXPECT_EQ(bsi->id, "bs");
// 未知 id
EXPECT_FALSE(standards::find("UNKNOWN").has_value());
EXPECT_FALSE(standards::find("").has_value());
EXPECT_TRUE(standards::is_valid_standard("DIN"));
EXPECT_TRUE(standards::is_valid_standard("BSI"));
EXPECT_TRUE(standards::is_valid_standard("GOST"));
EXPECT_FALSE(standards::is_valid_standard("UNKNOWN"));
}
TEST(DrawingStandardsProfileTest, AvailableStandardsIncludesDinBsiGost) {
const auto list = drawing::available_standards();
EXPECT_EQ(list.size(), static_cast<size_t>(7));
EXPECT_TRUE(contains_name(list, "ISO"));
EXPECT_TRUE(contains_name(list, "DIN"));
EXPECT_TRUE(contains_name(list, "BSI"));
EXPECT_TRUE(contains_name(list, "GOST"));
}
TEST(DrawingStandardsProfileTest, StandardDescriptionsForDinBsiGost) {
EXPECT_NE(drawing::standard_description("DIN").find("DIN"), std::string::npos);
EXPECT_NE(drawing::standard_description("DIN:2006").find("DIN"), std::string::npos);
EXPECT_NE(drawing::standard_description("BSI").find("BS 8888"), std::string::npos);
EXPECT_NE(drawing::standard_description("gost").find("GOST"), std::string::npos);
}