From cc710ab71be78fd795cdfe1ef78299201126b004 Mon Sep 17 00:00:00 2001 From: Pieter Hijma Date: Fri, 8 Aug 2025 14:58:03 +0200 Subject: [PATCH] Core: Add test for a prop rename with expression --- tests/src/App/Property.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/src/App/Property.cpp b/tests/src/App/Property.cpp index 6eaab505cb..f21893cdf0 100644 --- a/tests/src/App/Property.cpp +++ b/tests/src/App/Property.cpp @@ -321,6 +321,43 @@ TEST_F(RenameProperty, updateExpressionDifferentDocument) doc->removeObject(varSet2->getNameInDocument()); } +// Test if we can rename a property which value is the result of an expression +TEST_F(RenameProperty, renamePropertyWithExpression) +{ + // Arrange + auto* prop2 = freecad_cast( + varSet->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables")); + prop2->setValue(Value); + + App::ObjectIdentifier path(*prop); + std::shared_ptr expr(App::Expression::parse(varSet, "Variable2")); + varSet->setExpression(path, expr); + varSet->ExpressionEngine.execute(); + + // Assert before the rename + EXPECT_EQ(prop2->getValue(), Value); + EXPECT_EQ(prop->getValue(), Value); + + // Act + bool isRenamed = varSet->renameDynamicProperty(prop, "NewName"); + varSet->ExpressionEngine.execute(); + + // Assert after the rename + EXPECT_TRUE(isRenamed); + EXPECT_STREQ(varSet->getPropertyName(prop), "NewName"); + EXPECT_EQ(prop->getValue(), Value); + EXPECT_EQ(varSet->getDynamicPropertyByName("Variable"), nullptr); + EXPECT_EQ(varSet->getDynamicPropertyByName("NewName"), prop); + + // Act + prop2->setValue(Value + 1); + varSet->ExpressionEngine.execute(); + + // Assert + EXPECT_EQ(prop2->getValue(), Value + 1); + EXPECT_EQ(prop->getValue(), Value + 1); +} + // Tests whether we can rename a property and undo it TEST_F(RenameProperty, undoRenameProperty) {