test_if_unless.cpp
Go to the documentation of this file.
1 // Unit tests for if/unless attributes
2 // Author: Max Schwarz <max.schwarz@ais.uni-bonn.de>
3 
4 #include <catch_ros/catch.hpp>
5 
6 #include "../../src/launch/launch_config.h"
7 
8 #include "param_utils.h"
9 
10 using namespace rosmon::launch;
11 
12 TEST_CASE("if/unless basic", "[if_unless]")
13 {
14  LaunchConfig config;
15  config.parseString(R"EOF(
16  <launch>
17  <param if="false" name="test_if" value="hello" />
18  <param if="true" name="test_if" value="world" />
19 
20  <param if="1" name="test_if_number" value="hello" />
21  <param if="0" name="test_if_number" value="world" />
22 
23  <param unless="false" name="test_unless" value="hello" />
24  <param unless="true" name="test_unless" value="world" />
25  </launch>
26  )EOF");
27 
28  config.evaluateParameters();
29 
30  CAPTURE(config.parameters());
31 
32  auto& params = config.parameters();
33  checkTypedParam<std::string>(params, "/test_if", XmlRpc::XmlRpcValue::TypeString, "world");
34  checkTypedParam<std::string>(params, "/test_if_number", XmlRpc::XmlRpcValue::TypeString, "hello");
35  checkTypedParam<std::string>(params, "/test_unless", XmlRpc::XmlRpcValue::TypeString, "hello");
36 }
37 
38 TEST_CASE("if/unless invalid", "[if_unless]")
39 {
40  using Catch::Matchers::Contains;
41 
42  REQUIRE_THROWS_WITH(
43  LaunchConfig().parseString(R"EOF(<launch><param if="true" unless="true" name="test" value="test" /></launch>)EOF"),
44  Contains("if") && Contains("unless")
45  );
46 
47  REQUIRE_THROWS_AS(
48  LaunchConfig().parseString(R"EOF(<launch><param if="unknown_value" name="test" value="test" /></launch>)EOF"),
50  );
51 }
auto & params
Definition: test_param.cpp:220
const std::map< std::string, XmlRpc::XmlRpcValue > & parameters() const
void parseString(const std::string &input, bool onlyArguments=false)
TEST_CASE("if/unless basic","[if_unless]")
config parseString(R"EOF( <launch> <group ns="/"> <param name="param1" value="hello" /> </group> <node name="test_node" pkg="rosmon_core" type="abort" ns="/racecar"> <param name="private_param" value="hello again" /> </node> </launch> )EOF")


rosmon_core
Author(s): Max Schwarz
autogenerated on Wed Jul 10 2019 03:10:12