11#include < gtest/gtest.h>
22#include < filesystem>
3+ #include < string>
4+ #include < utility>
5+ #include < vector>
36#include " behaviortree_cpp/xml_parsing.h"
47#include " ../sample_nodes/crossdoor_nodes.h"
58#include " ../sample_nodes/dummy_nodes.h"
@@ -409,7 +412,6 @@ class DescriptiveAction : public SyncActionNode
409412
410413TEST (BehaviorTreeFactory, DescriptionMethod)
411414{
412-
413415 BehaviorTreeFactory factory;
414416 factory.registerNodeType <DescriptiveAction>(" DescriptiveAction" );
415417 const auto & manifest = factory.manifests ().at (" DescriptiveAction" );
@@ -420,3 +422,56 @@ TEST(BehaviorTreeFactory, DescriptionMethod)
420422
421423 ASSERT_NE (xml.find ( " <description>THE DESCRIPTION</description>" ), std::string::npos);
422424}
425+
426+ std::vector<ManifestMetadata> makeTestMetadata ()
427+ {
428+ ManifestMetadata text_metadata;
429+ text_metadata.name = " text_metadata" ;
430+ text_metadata.text_or_attribute = " text" ;
431+
432+ ManifestMetadata attribute_metadata;
433+ attribute_metadata.name = " attribute_metadata" ;
434+ attribute_metadata.text_or_attribute = std::make_pair<std::string, std::string>(" attribute_name" , " attribute_value" );
435+
436+ return {text_metadata, attribute_metadata};
437+ }
438+
439+ class ActionWithMetadata : public SyncActionNode
440+ {
441+ public:
442+ ActionWithMetadata (const std::string& name, const NodeConfig& config):
443+ SyncActionNode (name, config) {}
444+
445+ BT::NodeStatus tick () override {
446+ return NodeStatus::SUCCESS;
447+ }
448+
449+ static PortsList providedPorts () {
450+ return {};
451+ }
452+
453+ static std::vector<ManifestMetadata> metadata () {
454+ return makeTestMetadata ();
455+ }
456+ };
457+
458+ TEST (BehaviorTreeFactory, ManifestMethod)
459+ {
460+ BehaviorTreeFactory factory;
461+ factory.registerNodeType <ActionWithMetadata>(" ActionWithMetadata" );
462+ const auto & manifest = factory.manifests ().at (" ActionWithMetadata" );
463+ ASSERT_EQ (manifest.metadata .size (), 2u );
464+ auto expected_metadata = makeTestMetadata ();
465+ EXPECT_EQ (manifest.metadata [0 ].name , expected_metadata[0 ].name );
466+ EXPECT_EQ (manifest.metadata [0 ].text_or_attribute , expected_metadata[0 ].text_or_attribute );
467+ EXPECT_TRUE (manifest.metadata [0 ].representsText ());
468+ EXPECT_EQ (manifest.metadata [1 ].name , expected_metadata[1 ].name );
469+ EXPECT_EQ (manifest.metadata [1 ].text_or_attribute , expected_metadata[1 ].text_or_attribute );
470+ EXPECT_TRUE (manifest.metadata [1 ].representsAttribute ());
471+
472+ auto xml = writeTreeNodesModelXML (factory, false );
473+ std::cout << xml << std::endl;
474+
475+ ASSERT_NE (xml.find (" <text_metadata>text</text_metadata>" ), std::string::npos);
476+ ASSERT_NE (xml.find (" <attribute_metadata attribute_name=\" attribute_value\" />" ), std::string::npos);
477+ }
0 commit comments