parameter_reader_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #include <aws/core/client/ClientConfiguration.h>
18 #include <gtest/gtest.h>
19 #include <ros/ros.h>
20 
21 #define PARAM_READER_TEST__PARAM_PREFIX "configuration_namespace9181"
22 #define PARAM_READER_TEST__PARAM_KEY "someBogusParamKey"
23 #define PARAM_READER_TEST__PARAM_VALUE "uk-north-2180"
24 using namespace Aws::Client;
25 
26 class ParameterReaderTest : public ::testing::Test {
27 protected:
28  void SetUp() override {
29  producer = ros::NodeHandle("~producers");
31  }
32  void TearDown() {
34  consumer.deleteParam(PARAM_READER_TEST__PARAM_PREFIX "/" PARAM_READER_TEST__PARAM_KEY);
35  }
38 };
39 
40 TEST_F(ParameterReaderTest, parameterPathResolution)
41 {
42  auto parameter_reader = std::make_shared<Aws::Client::Ros1NodeParameterReader>();
43  auto param_path_flat = ParameterPath(
44  "test_parameter_reader/producers/" PARAM_READER_TEST__PARAM_PREFIX "/" PARAM_READER_TEST__PARAM_KEY
45  );
46  auto param_path_variadic = ParameterPath(
47  "test_parameter_reader", "producers", PARAM_READER_TEST__PARAM_PREFIX, PARAM_READER_TEST__PARAM_KEY
48  );
49  auto param_path_complex_no_node_ns = ParameterPath(std::vector<std::string>{},
50  std::vector<std::string>{PARAM_READER_TEST__PARAM_PREFIX, PARAM_READER_TEST__PARAM_KEY});
51  auto param_path_complex_with_node_ns = ParameterPath(
52  std::vector<std::string>{"test_parameter_reader", "producers"},
53  std::vector<std::string>{PARAM_READER_TEST__PARAM_PREFIX, PARAM_READER_TEST__PARAM_KEY});
54 
55  ASSERT_EQ(param_path_flat.get_resolved_path('/', '/'), param_path_variadic.get_resolved_path('/', '/'));
56  ASSERT_EQ(param_path_flat.get_resolved_path('/', '/'), param_path_complex_with_node_ns.get_resolved_path('/', '/'));
57 
58  std::string flat_result;
59  parameter_reader->ReadParam(param_path_flat, flat_result);
60  std::string variadic_result;
61  parameter_reader->ReadParam(param_path_variadic, variadic_result);
62  std::string complex_no_node_ns_result;
63  parameter_reader->ReadParam(param_path_complex_no_node_ns, complex_no_node_ns_result);
64  std::string complex_with_node_ns_result;
65  parameter_reader->ReadParam(param_path_complex_with_node_ns, complex_with_node_ns_result);
66 
67  ASSERT_EQ(flat_result, variadic_result);
68  ASSERT_EQ(variadic_result, complex_with_node_ns_result);
69  ASSERT_EQ(flat_result, PARAM_READER_TEST__PARAM_VALUE);
70 
71  ASSERT_EQ(std::string(), complex_no_node_ns_result);
72  consumer.setParam(PARAM_READER_TEST__PARAM_PREFIX "/" PARAM_READER_TEST__PARAM_KEY, PARAM_READER_TEST__PARAM_VALUE);
73  parameter_reader->ReadParam(param_path_complex_no_node_ns, complex_no_node_ns_result);
74  ASSERT_EQ(complex_no_node_ns_result, complex_with_node_ns_result);
75 }
76 
77 TEST(ParameterReader, failureTests)
78 {
79  auto parameter_reader = std::make_shared<Aws::Client::Ros1NodeParameterReader>();
80  auto nonexistent_path = ParameterPath("I don't exist");
81  std::string nonexistent_path_result = PARAM_READER_TEST__PARAM_VALUE;
82  /* Querying for a nonexistent parameter should return NOT_FOUND and the out parameter remains unchanged. */
83  ASSERT_EQ(Aws::AwsError::AWS_ERR_NOT_FOUND, parameter_reader->ReadParam(nonexistent_path, nonexistent_path_result));
84  ASSERT_EQ(nonexistent_path_result, std::string(PARAM_READER_TEST__PARAM_VALUE));
85 }
86 
87 int main(int argc, char ** argv)
88 {
89  testing::InitGoogleTest(&argc, argv);
90  ros::init(argc, argv, "test_parameter_reader");
91  return RUN_ALL_TESTS();
92 }
int main(int argc, char **argv)
#define PARAM_READER_TEST__PARAM_KEY
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
TEST(ParameterReader, failureTests)
std::string get_resolved_path(char node_namespace_separator, char parameter_namespace_separator) const
#define PARAM_READER_TEST__PARAM_VALUE
#define PARAM_READER_TEST__PARAM_PREFIX
TEST_F(ParameterReaderTest, parameterPathResolution)


aws_ros1_common
Author(s): AWS RoboMaker
autogenerated on Thu Mar 4 2021 03:25:44