test_config_file.cpp
Go to the documentation of this file.
1 
13 
14 #include <gtest/gtest.h>
15 
16 using namespace testing;
17 
18 #ifndef TEST_CORE_CONFIG_PATH
19 #define TEST_CORE_CONFIG_PATH "./tests/core/configs/"
20 #endif
21 
22 const char * TestConfigFile = TEST_CORE_CONFIG_PATH "test.conf";
24 
25 TEST(ModulesConfiguration, ParsesConfigurationFile)
26 {
28  ASSERT_EQ(config.Modules.size(), 1);
29 
30  ASSERT_EQ(config.Parameters.Parameters.size(), 2);
31  const std::vector<Common::Parameter> standaloneParams = config.Parameters.Parameters;
32  EXPECT_EQ(standaloneParams[0].Name, "param1");
33  EXPECT_EQ(standaloneParams[0].Value, "value1");
34  EXPECT_EQ(standaloneParams[1].Name, "param2");
35  EXPECT_EQ(standaloneParams[1].Value, "value2");
36 
37  const std::vector<Common::ParametersGroup> standaloneGroups = config.Parameters.Groups;
38  ASSERT_EQ(standaloneGroups.size(), 2);
39  ASSERT_EQ(standaloneGroups[0].Name, "group1");
40  const std::vector<Common::Parameter> group1Params = standaloneGroups[0].Parameters;
41  ASSERT_EQ(group1Params.size(), 2);
42  ASSERT_EQ(group1Params[0].Name, "param1");
43  ASSERT_EQ(group1Params[0].Value, "value1");
44  ASSERT_EQ(group1Params[1].Name, "param2");
45  ASSERT_EQ(group1Params[1].Value, "value2");
46 
47  ASSERT_EQ(standaloneGroups[1].Name, "group2");
48  const std::vector<Common::Parameter> group2Params = standaloneGroups[1].Parameters;
49  ASSERT_EQ(group2Params.size(), 2);
50  ASSERT_EQ(group2Params[0].Name, "param1");
51  ASSERT_EQ(group2Params[0].Value, "value1");
52  ASSERT_EQ(group2Params[1].Name, "param2");
53  ASSERT_EQ(group2Params[1].Value, "value2");
54 
55 
56  const Common::ModuleConfiguration module = config.Modules.front();
57  ASSERT_EQ(module.Id, "child_module");
58  ASSERT_EQ(module.Path, "child_module.so");
59  ASSERT_EQ(module.Dependencies.size(), 2);
60  ASSERT_EQ(module.Dependencies[0], "parent_module1");
61  ASSERT_EQ(module.Dependencies[1], "parent_module2");
62 
63  ASSERT_EQ(module.Parameters.Parameters.size(), 5);
64  ASSERT_EQ(module.Parameters.Parameters[0].Name, "application_name");
65  ASSERT_EQ(module.Parameters.Parameters[0].Value, "Test OPC UA Server");
66 
67  ASSERT_EQ(module.Parameters.Groups.size(), 2);
68  ASSERT_EQ(module.Parameters.Groups[0].Name, "user_token_policy");
69  ASSERT_EQ(module.Parameters.Groups[0].Parameters.size(), 3);
70  ASSERT_EQ(module.Parameters.Groups[0].Parameters[0].Name, "id");
71  ASSERT_EQ(module.Parameters.Groups[0].Parameters[0].Value, "anonymous");
72  ASSERT_EQ(module.Parameters.Groups[0].Parameters[1].Name, "type");
73  ASSERT_EQ(module.Parameters.Groups[0].Parameters[1].Value, "anonymous");
74 }
75 
76 TEST(ModulesConfiguration, SavesConfigurationFile)
77 {
79  addon.Id = "test_addon";
80  addon.Dependencies.push_back("id1");
81  addon.Dependencies.push_back("id2");
82  addon.Path = "path";
84  group.Name = "group";
85  group.Parameters.push_back(Common::Parameter("parameter", "value"));
86  addon.Parameters.Parameters.push_back(Common::Parameter("parameter", "value"));
87  addon.Parameters.Groups.push_back(group);
88 
89  Common::SaveConfiguration(Common::ModulesConfiguration({addon}), "test_config.config");
90  const Common::Configuration & config = Common::ParseConfiguration("test_config.config");
91  ASSERT_EQ(config.Modules.size(), 1);
92  const Common::ModuleConfiguration & module = config.Modules[0];
93  ASSERT_EQ(module.Id, "test_addon");
94  ASSERT_EQ(module.Path, "path");
95  ASSERT_EQ(module.Dependencies.size(), 2);
96  ASSERT_EQ(module.Dependencies[0], "id1");
97  ASSERT_EQ(module.Dependencies[1], "id2");
98  ASSERT_EQ(module.Parameters.Parameters.size(), 1);
99  ASSERT_EQ(module.Parameters.Parameters[0].Name, "parameter");
100  ASSERT_EQ(module.Parameters.Parameters[0].Value, "value");
101  ASSERT_EQ(module.Parameters.Groups.size(), 1);
102  ASSERT_EQ(module.Parameters.Groups[0].Name, "group");
103  ASSERT_EQ(module.Parameters.Groups[0].Parameters.size(), 1);
104  ASSERT_EQ(module.Parameters.Groups[0].Parameters[0].Name, "parameter");
105  ASSERT_EQ(module.Parameters.Groups[0].Parameters[0].Value, "value");
106 }
107 
108 TEST(ModulesConfiguration, ParsesConfigurationFilesInDirectory)
109 {
111  ASSERT_EQ(config.Modules.size(), 1);
112  ASSERT_EQ(config.Modules[0].Id, "child_module");
113 }
114 
Configuration ParseConfigurationFiles(const std::string &directory)
Configuration ParseConfiguration(const std::string &configPath)
Definition: config_file.cpp:65
void SaveConfiguration(const ModulesConfiguration &configuration, const std::string &configPath)
std::vector< AddonId > Dependencies
Definition: config_file.h:22
std::vector< Parameter > Parameters
#define TEST_CORE_CONFIG_PATH
Common::AddonParameters Parameters
Definition: config_file.h:31
bool Value(const T &value, M matcher)
TEST(GTestEnvVarTest, Dummy)
const char * TestConfigFile
const char * TestConfigPath
#define ASSERT_EQ(val1, val2)
std::vector< ParametersGroup > Groups
AddonParameters Parameters
Definition: config_file.h:24
std::vector< Common::ModuleConfiguration > ModulesConfiguration
Definition: config_file.h:27
std::vector< ModuleConfiguration > Modules
Definition: config_file.h:32
#define EXPECT_EQ(expected, actual)
std::vector< Parameter > Parameters


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:08