// ═══════════════════════════════════════════════════════════════════════════ // 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 #include "vde_drafting/drawing_standards.h" #include #include #include using namespace vde::drafting; namespace { /// 判断 available_standards() 列表是否包含指定标准名 bool contains_name(const std::vector& 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 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 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(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(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); }