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"
@@ -388,10 +391,18 @@ TEST(BehaviorTreeReload, ReloadSameTree)
388391 }
389392}
390393
391- class DescriptiveAction : public SyncActionNode
394+ std::vector<std::pair<std::string, std::string>> makeTestMetadata ()
395+ {
396+ return {
397+ std::make_pair<std::string, std::string>(" foo" , " hello" ),
398+ std::make_pair<std::string, std::string>(" bar" , " 42" ),
399+ };
400+ }
401+
402+ class ActionWithMetadata : public SyncActionNode
392403{
393404public:
394- DescriptiveAction (const std::string& name, const NodeConfig& config):
405+ ActionWithMetadata (const std::string& name, const NodeConfig& config):
395406 SyncActionNode (name, config) {}
396407
397408 BT::NodeStatus tick () override {
@@ -402,21 +413,39 @@ class DescriptiveAction : public SyncActionNode
402413 return {};
403414 }
404415
405- static std::string description () {
406- return " THE DESCRIPTION " ;
416+ static std::vector<std::pair<std:: string, std::string>> metadata () {
417+ return makeTestMetadata () ;
407418 }
408419};
409420
410- TEST (BehaviorTreeFactory, DescriptionMethod )
421+ TEST (BehaviorTreeFactory, ManifestMethod )
411422{
423+ const char * expectedXML = R"(
424+ <Action ID="ActionWithMetadata">
425+ <MetadataFields>
426+ <Metadata foo="hello"/>
427+ <Metadata bar="42"/>
428+ </MetadataFields>
429+ </Action>)" ;
412430
413431 BehaviorTreeFactory factory;
414- factory.registerNodeType <DescriptiveAction >(" DescriptiveAction " );
415- const auto & manifest = factory.manifests ().at (" DescriptiveAction " );
416- ASSERT_EQ (manifest.description , " THE DESCRIPTION " );
432+ factory.registerNodeType <ActionWithMetadata >(" ActionWithMetadata " );
433+ const auto & manifest = factory.manifests ().at (" ActionWithMetadata " );
434+ EXPECT_EQ (manifest.metadata , makeTestMetadata () );
417435
418436 auto xml = writeTreeNodesModelXML (factory, false );
419437 std::cout << xml << std::endl;
420438
421- ASSERT_NE (xml.find ( " <description>THE DESCRIPTION</description>" ), std::string::npos);
439+ EXPECT_NE (xml.find (expectedXML), std::string::npos);
440+ }
441+
442+ TEST (BehaviorTreeFactory, addMetadataToManifest)
443+ {
444+ BehaviorTreeFactory factory;
445+ factory.registerNodeType <DummyNodes::SaySomething>(" SaySomething" );
446+ const auto & initial_manifest = factory.manifests ().at (" SaySomething" );
447+ EXPECT_TRUE (initial_manifest.metadata .empty ());
448+ factory.addMetadataToManifest (" SaySomething" , makeTestMetadata ());
449+ const auto & modified_manifest = factory.manifests ().at (" SaySomething" );
450+ EXPECT_EQ (modified_manifest.metadata , makeTestMetadata ());
422451}
0 commit comments