test_config_file.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include <opc/common/addons_core/config_file.h>
00012 #include <opc/common/addons_core/addon.h>
00013 
00014 #include <gtest/gtest.h>
00015 
00016 using namespace testing;
00017 
00018 #ifndef TEST_CORE_CONFIG_PATH
00019 #define TEST_CORE_CONFIG_PATH "./tests/core/configs/"
00020 #endif
00021 
00022 const char* TestConfigFile = TEST_CORE_CONFIG_PATH "test.conf";
00023 const char* TestConfigPath = TEST_CORE_CONFIG_PATH;
00024 
00025 TEST(ModulesConfiguration, ParsesConfigurationFile)
00026 {
00027   Common::Configuration config = Common::ParseConfiguration(TestConfigFile);
00028   ASSERT_EQ(config.Modules.size(), 1);
00029 
00030   ASSERT_EQ(config.Parameters.Parameters.size(), 2);
00031   const std::vector<Common::Parameter> standaloneParams = config.Parameters.Parameters;
00032   EXPECT_EQ(standaloneParams[0].Name, "param1");
00033   EXPECT_EQ(standaloneParams[0].Value, "value1");
00034   EXPECT_EQ(standaloneParams[1].Name, "param2");
00035   EXPECT_EQ(standaloneParams[1].Value, "value2");
00036 
00037   const std::vector<Common::ParametersGroup> standaloneGroups = config.Parameters.Groups;
00038   ASSERT_EQ(standaloneGroups.size(), 2);
00039   ASSERT_EQ(standaloneGroups[0].Name, "group1");
00040   const std::vector<Common::Parameter> group1Params = standaloneGroups[0].Parameters;
00041   ASSERT_EQ(group1Params.size(), 2);
00042   ASSERT_EQ(group1Params[0].Name, "param1");
00043   ASSERT_EQ(group1Params[0].Value, "value1");
00044   ASSERT_EQ(group1Params[1].Name, "param2");
00045   ASSERT_EQ(group1Params[1].Value, "value2");
00046 
00047   ASSERT_EQ(standaloneGroups[1].Name, "group2");
00048   const std::vector<Common::Parameter> group2Params = standaloneGroups[1].Parameters;
00049   ASSERT_EQ(group2Params.size(), 2);
00050   ASSERT_EQ(group2Params[0].Name, "param1");
00051   ASSERT_EQ(group2Params[0].Value, "value1");
00052   ASSERT_EQ(group2Params[1].Name, "param2");
00053   ASSERT_EQ(group2Params[1].Value, "value2");
00054 
00055 
00056   const Common::ModuleConfiguration module = config.Modules.front();
00057   ASSERT_EQ(module.Id, "child_module");
00058   ASSERT_EQ(module.Path, "child_module.so");
00059   ASSERT_EQ(module.Dependencies.size(), 2);
00060   ASSERT_EQ(module.Dependencies[0], "parent_module1");
00061   ASSERT_EQ(module.Dependencies[1], "parent_module2");
00062 
00063   ASSERT_EQ(module.Parameters.Parameters.size(), 5);
00064   ASSERT_EQ(module.Parameters.Parameters[0].Name, "application_name");
00065   ASSERT_EQ(module.Parameters.Parameters[0].Value, "Test OPC UA Server");
00066 
00067   ASSERT_EQ(module.Parameters.Groups.size(), 2);
00068   ASSERT_EQ(module.Parameters.Groups[0].Name, "user_token_policy");
00069   ASSERT_EQ(module.Parameters.Groups[0].Parameters.size(), 3);
00070   ASSERT_EQ(module.Parameters.Groups[0].Parameters[0].Name, "id");
00071   ASSERT_EQ(module.Parameters.Groups[0].Parameters[0].Value, "anonymous");
00072   ASSERT_EQ(module.Parameters.Groups[0].Parameters[1].Name, "type");
00073   ASSERT_EQ(module.Parameters.Groups[0].Parameters[1].Value, "anonymous");
00074 }
00075 
00076 TEST(ModulesConfiguration, SavesConfigurationFile)
00077 {
00078   Common::ModuleConfiguration addon;
00079   addon.Id = "test_addon";
00080   addon.Dependencies.push_back("id1");
00081   addon.Dependencies.push_back("id2");
00082   addon.Path = "path";
00083   Common::ParametersGroup group;
00084   group.Name = "group";
00085   group.Parameters.push_back(Common::Parameter("parameter", "value"));
00086   addon.Parameters.Parameters.push_back(Common::Parameter("parameter", "value"));
00087   addon.Parameters.Groups.push_back(group);
00088 
00089   Common::SaveConfiguration(Common::ModulesConfiguration({addon}), "test_config.config");
00090   const Common::Configuration& config = Common::ParseConfiguration("test_config.config");
00091   ASSERT_EQ(config.Modules.size(), 1);
00092   const Common::ModuleConfiguration& module = config.Modules[0];
00093   ASSERT_EQ(module.Id, "test_addon");
00094   ASSERT_EQ(module.Path, "path");
00095   ASSERT_EQ(module.Dependencies.size(), 2);
00096   ASSERT_EQ(module.Dependencies[0], "id1");
00097   ASSERT_EQ(module.Dependencies[1], "id2");
00098   ASSERT_EQ(module.Parameters.Parameters.size(), 1);
00099   ASSERT_EQ(module.Parameters.Parameters[0].Name, "parameter");
00100   ASSERT_EQ(module.Parameters.Parameters[0].Value, "value");
00101   ASSERT_EQ(module.Parameters.Groups.size(), 1);
00102   ASSERT_EQ(module.Parameters.Groups[0].Name, "group");
00103   ASSERT_EQ(module.Parameters.Groups[0].Parameters.size(), 1);
00104   ASSERT_EQ(module.Parameters.Groups[0].Parameters[0].Name, "parameter");
00105   ASSERT_EQ(module.Parameters.Groups[0].Parameters[0].Value, "value");
00106 }
00107 
00108 TEST(ModulesConfiguration, ParsesConfigurationFilesInDirectory)
00109 {
00110   Common::Configuration config = Common::ParseConfigurationFiles(TestConfigPath);
00111   ASSERT_EQ(config.Modules.size(), 1);
00112   ASSERT_EQ(config.Modules[0].Id, "child_module");
00113 }
00114 


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:57