From 4241d795c036e9eb200d2732ee1c9b75cd017fad Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Mon, 19 May 2025 19:52:20 +0200 Subject: [PATCH 1/3] Base: Skip test for units using GTEST_SKIP() instead of comments --- tests/src/Base/SchemaTests.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/src/Base/SchemaTests.cpp b/tests/src/Base/SchemaTests.cpp index e6ca6f5fca..0b170fa9be 100644 --- a/tests/src/Base/SchemaTests.cpp +++ b/tests/src/Base/SchemaTests.cpp @@ -315,18 +315,16 @@ TEST_F(SchemaTest, imperial_building_special_function_length_foot) EXPECT_EQ(result, expect); } -/* - * QuantityParser::yyparse() is crashing on the >>1' 2" + 1/4"<< input, - * so disable this test TEST_F(SchemaTest, imperial_building_special_function_length) { + GTEST_SKIP() << "QuantityParser::yyparse() is crashing on the >>1' 2\" + 1/4\"<< input, " + "so disable this test"; constexpr auto val {360.6}; const auto result = set("ImperialBuilding", Unit::Length, val); const auto expect = Tools::escapeQuotesFromString("1' 2\" + 1/4\""); EXPECT_EQ(result, expect); } -*/ TEST_F(SchemaTest, imperial_building_special_function_length_neg) { From 1678171e6b60292d66a492aae887f9558f97d089 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Mon, 19 May 2025 19:54:30 +0200 Subject: [PATCH 2/3] Base: Add more tests for imperial building special function --- tests/src/Base/SchemaTests.cpp | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/src/Base/SchemaTests.cpp b/tests/src/Base/SchemaTests.cpp index 0b170fa9be..412bc8ac81 100644 --- a/tests/src/Base/SchemaTests.cpp +++ b/tests/src/Base/SchemaTests.cpp @@ -315,6 +315,41 @@ TEST_F(SchemaTest, imperial_building_special_function_length_foot) EXPECT_EQ(result, expect); } +TEST_F(SchemaTest, imperial_building_special_function_zero_length) +{ + const auto result = set("ImperialBuilding", Unit::Length, 0.0); + const auto expect = Tools::escapeQuotesFromString("0"); + + EXPECT_EQ(result, expect); +} + +TEST_F(SchemaTest, imperial_building_special_function_length_negative_fraction_only) +{ + constexpr auto val {(-1.0 / 8.0) * 25.4}; // -1/8 inch in mm + const auto result = set("ImperialBuilding", Unit::Length, val); + const auto expect = Tools::escapeQuotesFromString("-1/8\""); + + EXPECT_EQ(result, expect); +} + +TEST_F(SchemaTest, imperial_building_special_function_negative_inches_and_fraction) +{ + constexpr auto val {-2.5 * 25.4}; // -2.5 inches in mm + const auto result = set("ImperialBuilding", Unit::Length, val); + const auto expect = Tools::escapeQuotesFromString("-2\" - 1/2\""); + + EXPECT_EQ(result, expect); +} + +TEST_F(SchemaTest, imperial_building_special_function_high_precision_rounding) +{ + constexpr auto val {25.396}; // Very close to exactly 1 inch + const auto result = set("ImperialBuilding", Unit::Length, val); + const auto expect = Tools::escapeQuotesFromString("1\""); + + EXPECT_EQ(result, expect); +} + TEST_F(SchemaTest, imperial_building_special_function_length) { GTEST_SKIP() << "QuantityParser::yyparse() is crashing on the >>1' 2\" + 1/4\"<< input, " From 9efd6baee927c98fb06eaa9aaa6e5cb3cbfab99b Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Mon, 19 May 2025 19:55:14 +0200 Subject: [PATCH 3/3] Base: Fix use after free in unit error message --- src/Base/UnitsApiPy.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Base/UnitsApiPy.cpp b/src/Base/UnitsApiPy.cpp index 7efd122c2d..799ca43ad4 100644 --- a/src/Base/UnitsApiPy.cpp +++ b/src/Base/UnitsApiPy.cpp @@ -89,9 +89,7 @@ PyObject* UnitsApi::sParseQuantity(PyObject* /*self*/, PyObject* args) return new QuantityPy(new Quantity(Quantity::parse(str))); } catch (const ParserError&) { - PyErr_Format(PyExc_ValueError, - "invalid unit expression: '%s'\n", - std::string {pstr}.c_str()); + PyErr_Format(PyExc_ValueError, "invalid unit expression: '%s'\n", str.c_str()); return nullptr; } }