https://github.com/FreeCAD/FreeCAD/issues/11965
| 59 | |
| 60 | // https://github.com/FreeCAD/FreeCAD/issues/11965 |
| 61 | TEST_F(PropertyExpressionEngineTest, executeCrossPropertyReference) |
| 62 | { |
| 63 | auto source_text = std::string("1.5 m"); // provided in source |
| 64 | auto target_text = std::string("1500 mm"); // expected in target |
| 65 | |
| 66 | auto source_path = App::ObjectIdentifier::parse(this_obj(), source_name()); |
| 67 | source_prop()->setPathValue(source_path, source_text); |
| 68 | |
| 69 | auto target_expr = "parsequant(" + source_name() + ")"; // Solution B: parsequant() function |
| 70 | |
| 71 | auto target_path = App::ObjectIdentifier::parse(this_obj(), target_name()); |
| 72 | std::shared_ptr<App::Expression> target_rule(App::Expression::parse(this_obj(), target_expr)); |
| 73 | this_obj()->setExpression(target_path, target_rule); |
| 74 | |
| 75 | this_obj() -> ExpressionEngine.execute(); |
| 76 | |
| 77 | auto source_entry = source_prop() -> getPathValue(source_path); |
| 78 | ASSERT_TRUE(source_entry.type() == typeid(std::string)); |
| 79 | auto source_value = App::any_cast<std::string>(source_entry); |
| 80 | |
| 81 | auto target_entry = target_prop() -> getPathValue(target_path); |
| 82 | ASSERT_TRUE(target_entry.type() == typeid(Base::Quantity)); |
| 83 | auto target_quant = App::any_cast<Base::Quantity>(target_entry); |
| 84 | auto target_value = target_quant.getValue(); |
| 85 | auto target_unit = target_quant.getUnit().getString(); |
| 86 | |
| 87 | auto verify_quant = Base::Quantity::parse(target_text); |
| 88 | |
| 89 | EXPECT_EQ(target_quant, verify_quant) << "" |
| 90 | "expecting equal: source_text='" + source_text + "' target_text='" + target_text + "'" |
| 91 | "instead produced: target_value='" + std::to_string(target_value) + "' target_unit='" + target_unit + "'" |
| 92 | ; |
| 93 | } |
| 94 | |
| 95 | // clang-format on |
nothing calls this directly
no test coverage detected