@@ -1089,175 +1089,3 @@ TEST(SubTree, NoNameAttribute_AutoGeneratesUniquePaths)
10891089 auto status = tree.tickWhileRunning ();
10901090 ASSERT_EQ (status, NodeStatus::SUCCESS );
10911091}
1092-
1093- // Regression test: logical NOT should accept literal boolean values passed to
1094- // subtrees without changing their string representation in the blackboard.
1095- TEST (SubTree, LiteralBooleanPortsSupportLogicalNot)
1096- {
1097- // clang-format off
1098- static const char * xml_text = R"(
1099- <root BTCPP_format="4" main_tree_to_execute="MainTree">
1100-
1101- <BehaviorTree ID="MainTree">
1102- <SubTree ID="CheckBooleans" enabled="true" disabled="false"
1103- enabled_upper="TRUE" disabled_title="False"
1104- enabled_numeric="{enabled_numeric}"
1105- disabled_numeric="{disabled_numeric}" />
1106- </BehaviorTree>
1107-
1108- <BehaviorTree ID="CheckBooleans">
1109- <Sequence>
1110- <AlwaysSuccess _skipIf="!enabled" />
1111- <ScriptCondition code="!disabled" />
1112- <ScriptCondition code="!!enabled_upper" />
1113- <ScriptCondition code="!disabled_title" />
1114- <ScriptCondition code="!!enabled_numeric" />
1115- <ScriptCondition code="!disabled_numeric" />
1116- </Sequence>
1117- </BehaviorTree>
1118-
1119- <TreeNodesModel>
1120- <SubTree ID="CheckBooleans">
1121- <input_port name="enabled" type="bool" />
1122- <input_port name="disabled" type="bool" />
1123- <input_port name="enabled_upper" type="bool" />
1124- <input_port name="disabled_title" type="bool" />
1125- <input_port name="enabled_numeric" type="bool" />
1126- <input_port name="disabled_numeric" type="bool" />
1127- </SubTree>
1128- </TreeNodesModel>
1129-
1130- </root>
1131- )" ;
1132- // clang-format on
1133-
1134- BehaviorTreeFactory factory;
1135- auto tree = factory.createTreeFromText (xml_text);
1136- tree.rootBlackboard ()->set (" enabled_numeric" , std::string (" 1" ));
1137- tree.rootBlackboard ()->set (" disabled_numeric" , std::string (" 0" ));
1138-
1139- ASSERT_EQ (tree.tickWhileRunning (), NodeStatus::SUCCESS );
1140- ASSERT_EQ (tree.subtrees [1 ]->blackboard ->get <std::string>(" enabled" ), " true" );
1141- ASSERT_EQ (tree.subtrees [1 ]->blackboard ->get <std::string>(" disabled" ), " false" );
1142- ASSERT_EQ (tree.subtrees [1 ]->blackboard ->get <std::string>(" enabled_upper" ), " TRUE" );
1143- ASSERT_EQ (tree.subtrees [1 ]->blackboard ->get <std::string>(" disabled_title" ), " False" );
1144- }
1145-
1146- TEST (SubTree, LiteralNonBooleanPortsRejectLogicalNot)
1147- {
1148- // clang-format off
1149- static const char * xml_text = R"(
1150- <root BTCPP_format="4" main_tree_to_execute="MainTree">
1151-
1152- <BehaviorTree ID="MainTree">
1153- <SubTree ID="CheckValue" value="1not_bool" />
1154- </BehaviorTree>
1155-
1156- <BehaviorTree ID="CheckValue">
1157- <ScriptCondition code="!value" />
1158- </BehaviorTree>
1159-
1160- </root>
1161- )" ;
1162- // clang-format on
1163-
1164- BehaviorTreeFactory factory;
1165- auto tree = factory.createTreeFromText (xml_text);
1166-
1167- ASSERT_THROW ((void )tree.tickWhileRunning (), RuntimeError);
1168- ASSERT_EQ (tree.subtrees [1 ]->blackboard ->get <std::string>(" value" ), " 1not_bool" );
1169- }
1170-
1171- // Regression test (#1121): Script expressions can do arithmetic with literal
1172- // numeric values passed to subtrees.
1173- TEST (SubTree, LiteralNumericPortsPreserveType)
1174- {
1175- // clang-format off
1176- static const char * xml_text = R"(
1177- <root BTCPP_format="4" main_tree_to_execute="MainTree">
1178-
1179- <BehaviorTree ID="MainTree">
1180- <Sequence>
1181- <SubTree ID="DoMath" int_val="42" dbl_val="3.14" str_val="hello"
1182- remapped_val="{from_parent}" />
1183- </Sequence>
1184- </BehaviorTree>
1185-
1186- <BehaviorTree ID="DoMath">
1187- <Sequence>
1188- <ScriptCondition code=" int_val + 1 == 43 " />
1189- <ScriptCondition code=" dbl_val > 3.0 " />
1190- <ScriptCondition code=" remapped_val + 1 == 101 " />
1191- </Sequence>
1192- </BehaviorTree>
1193-
1194- </root>
1195- )" ;
1196- // clang-format on
1197-
1198- BehaviorTreeFactory factory;
1199-
1200- auto tree = factory.createTreeFromText (xml_text);
1201-
1202- // Set the remapped parent value as an integer
1203- tree.rootBlackboard ()->set (" from_parent" , 100 );
1204-
1205- const auto status = tree.tickWhileRunning ();
1206- ASSERT_EQ (status, NodeStatus::SUCCESS );
1207- }
1208-
1209- // Issue #1246: a literal passed to a SubTree stays a string, so ports of different
1210- // types can read it, and its spelling is preserved.
1211- TEST (SubTree, LiteralPortsAreReadByAnyPortType)
1212- {
1213- // clang-format off
1214- static const char * xml_text = R"(
1215- <root BTCPP_format="4" main_tree_to_execute="MainTree">
1216-
1217- <BehaviorTree ID="MainTree">
1218- <SubTree ID="Sub" mode="1" code="007" />
1219- </BehaviorTree>
1220-
1221- <BehaviorTree ID="Sub">
1222- <Sequence>
1223- <ReadString value="{mode}" />
1224- <ReadInt value="{mode}" />
1225- <ReadDouble value="{mode}" />
1226- <ReadString value="{code}" />
1227- </Sequence>
1228- </BehaviorTree>
1229-
1230- </root>
1231- )" ;
1232- // clang-format on
1233-
1234- BehaviorTreeFactory factory;
1235- std::vector<std::string> strings;
1236- int int_val = 0 ;
1237- double dbl_val = 0 ;
1238- factory.registerSimpleAction (" ReadString" ,
1239- [&](TreeNode& node) {
1240- strings.push_back (
1241- node.getInput <std::string>(" value" ).value ());
1242- return NodeStatus::SUCCESS ;
1243- },
1244- { InputPort<std::string>(" value" ) });
1245- factory.registerSimpleAction (" ReadInt" ,
1246- [&](TreeNode& node) {
1247- int_val = node.getInput <int >(" value" ).value ();
1248- return NodeStatus::SUCCESS ;
1249- },
1250- { InputPort<int >(" value" ) });
1251- factory.registerSimpleAction (" ReadDouble" ,
1252- [&](TreeNode& node) {
1253- dbl_val = node.getInput <double >(" value" ).value ();
1254- return NodeStatus::SUCCESS ;
1255- },
1256- { InputPort<double >(" value" ) });
1257-
1258- auto tree = factory.createTreeFromText (xml_text);
1259- ASSERT_EQ (tree.tickWhileRunning (), NodeStatus::SUCCESS );
1260- ASSERT_EQ (strings, (std::vector<std::string>{ " 1" , " 007" }));
1261- ASSERT_EQ (int_val, 1 );
1262- ASSERT_EQ (dbl_val, 1.0 );
1263- }
0 commit comments