From 2b1064eb1f326638fb57a1c28a43917f2607c225 Mon Sep 17 00:00:00 2001 From: Manel Melaouhi Date: Fri, 19 Feb 2021 16:24:33 +0100 Subject: [PATCH] iox-#496 add unit tests to improve coverage of toml_gateway_config_parser class Signed-off-by: Manel Melaouhi --- .../test_popo_toml_gateway_config_parser.cpp | 489 +++++++++++++++--- 1 file changed, 408 insertions(+), 81 deletions(-) diff --git a/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp b/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp index 44ca6b3af9..d516379649 100644 --- a/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_toml_gateway_config_parser.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2020 - 2021 by Robert Bosch GmbH. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,22 +20,46 @@ using namespace ::testing; using ::testing::_; -// ======================================== Helpers ======================================== // +using namespace iox::config; +// ======================================== Helpers ======================================== // +const std::string TestFile = "gwconfig_test.tmp"; +#ifndef _WIN32 +const std::string TempPath = "/tmp"; +const std::string TestFilePath = TempPath + "/" + TestFile; +#else +const std::string TempPath = std::getenv("TEMP"); +const std::string TestFilePath = TempPath + "\\" + TestFile; +#endif // ======================================== Fixture ======================================== // class TomlGatewayConfigParserTest : public Test { public: void SetUp(){}; - void TearDown(){}; + void TearDown() + { + if (std::remove(TestFilePath.c_str()) != 0) + { + std::cerr << "Failed to remove temporary file '" << TestFilePath + << "'. You'll have to remove it by yourself."; + } + }; + + void CreateTmpTomlFile(std::shared_ptr toml) + { + std::fstream fs(TestFilePath, std::fstream::out | std::fstream::trunc); + if (fs.std::fstream::is_open()) + { + fs << *toml; + } + fs.close(); + } }; // ======================================== Tests ======================================== // -TEST_F(TomlGatewayConfigParserTest, PassesValidationIfValidCharactersUsedInServiceDescription) +TEST_F(TomlGatewayConfigParserTest, ValidCharactersUsedInServiceDescriptionReturnNoValidateError) { - // ===== Setup - // Prepare configuration to test with auto toml = cpptoml::make_table(); auto serviceArray = cpptoml::make_table_array(); @@ -43,124 +67,143 @@ TEST_F(TomlGatewayConfigParserTest, PassesValidationIfValidCharactersUsedInServi serviceEntry->insert("service", "service"); serviceEntry->insert("instance", "instance"); serviceEntry->insert("event", "event"); - serviceEntry->insert("size", 0); serviceArray->push_back(serviceEntry); + toml->insert("services", serviceArray); + + auto result = StubbedTomlGatewayConfigParser::validate(*toml); + EXPECT_EQ(false, result.has_error()); +} + +TEST_F(TomlGatewayConfigParserTest, UppercaseCharactersUsedInServiceDescriptionReturnNoValidateError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); auto serviceEntryUppercase = cpptoml::make_table(); serviceEntryUppercase->insert("service", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); serviceEntryUppercase->insert("instance", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); serviceEntryUppercase->insert("event", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - serviceEntryUppercase->insert("size", 0); serviceArray->push_back(serviceEntryUppercase); + toml->insert("services", serviceArray); + + auto result = StubbedTomlGatewayConfigParser::validate(*toml); + EXPECT_EQ(false, result.has_error()); +} + +TEST_F(TomlGatewayConfigParserTest, LowercaseCharactersUsedInServiceDescriptionReturnNoValidateError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); auto serviceEntryLowercase = cpptoml::make_table(); serviceEntryLowercase->insert("service", "abcdefghijklmnopqrstuvwxyz"); serviceEntryLowercase->insert("instance", "abcdefghijklmnopqrstuvwxyz"); serviceEntryLowercase->insert("event", "abcdefghijklmnopqrstuvwxyz"); - serviceEntryLowercase->insert("size", 0); serviceArray->push_back(serviceEntryLowercase); + toml->insert("services", serviceArray); + + auto result = StubbedTomlGatewayConfigParser::validate(*toml); + EXPECT_EQ(false, result.has_error()); +} + +TEST_F(TomlGatewayConfigParserTest, NumbersUsedInServiceDescriptionReturnNoValidateError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); auto serviceEntryNumbers = cpptoml::make_table(); serviceEntryNumbers->insert("service", "Number1234567890"); serviceEntryNumbers->insert("instance", "Number1234567890"); serviceEntryNumbers->insert("event", "Number1234567890"); - serviceEntryNumbers->insert("size", 0); serviceArray->push_back(serviceEntryNumbers); + toml->insert("services", serviceArray); + + auto result = StubbedTomlGatewayConfigParser::validate(*toml); + EXPECT_EQ(false, result.has_error()); +} + +TEST_F(TomlGatewayConfigParserTest, UnderscoreCharactersUsedInServiceDescriptionReturnNoValidateError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); auto serviceEntryUnderscore = cpptoml::make_table(); serviceEntryUnderscore->insert("service", "service_name"); serviceEntryUnderscore->insert("instance", "instance_name"); serviceEntryUnderscore->insert("event", "event_name"); - serviceEntryUnderscore->insert("size", 0); serviceArray->push_back(serviceEntryUnderscore); + toml->insert("services", serviceArray); + + auto result = StubbedTomlGatewayConfigParser::validate(*toml); + EXPECT_EQ(false, result.has_error()); +} + +TEST_F(TomlGatewayConfigParserTest, ServiceEntryBeginsWithUnderscoresUsedInServiceDescriptionReturnNoValidateError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); auto serviceEntryBeginsWithUnderscore = cpptoml::make_table(); serviceEntryBeginsWithUnderscore->insert("service", "_service_name"); serviceEntryBeginsWithUnderscore->insert("instance", "_instance_name"); serviceEntryBeginsWithUnderscore->insert("event", "_event_name"); - serviceEntryBeginsWithUnderscore->insert("size", 0); serviceArray->push_back(serviceEntryBeginsWithUnderscore); - toml->insert("services", serviceArray); - // ===== Test auto result = iox::config::StubbedTomlGatewayConfigParser::validate(*toml); EXPECT_EQ(false, result.has_error()); } -TEST_F(TomlGatewayConfigParserTest, FailsValidationIfNoServiceNameInServiceDescription) +TEST_F(TomlGatewayConfigParserTest, NoServiceNameInServiceDescriptionReturnIncompleteServiceDescriptionError) { - // ===== Setup - // Prepare configuration to test with auto toml = cpptoml::make_table(); auto serviceArray = cpptoml::make_table_array(); auto serviceEntryNoServiceName = cpptoml::make_table(); serviceEntryNoServiceName->insert("instance", "instance"); serviceEntryNoServiceName->insert("event", "event"); - serviceEntryNoServiceName->insert("size", 0); serviceArray->push_back(serviceEntryNoServiceName); toml->insert("services", serviceArray); - // ===== Test - auto result = iox::config::StubbedTomlGatewayConfigParser::validate(*toml); - EXPECT_EQ(true, result.has_error()); - if (result.has_error()) - { - EXPECT_EQ(iox::config::TomlGatewayConfigParseError::INCOMPLETE_SERVICE_DESCRIPTION, result.get_error()); - } + auto result = StubbedTomlGatewayConfigParser::validate(*toml); + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INCOMPLETE_SERVICE_DESCRIPTION, result.get_error()); } -TEST_F(TomlGatewayConfigParserTest, FailsValidationIfNoInstanceNameInServiceDescription) +TEST_F(TomlGatewayConfigParserTest, NoInstanceNameInServiceDescriptionReturnIncompleteServiceDescriptionError) { - // ===== Setup - // Prepare configuration to test with auto toml = cpptoml::make_table(); auto serviceArray = cpptoml::make_table_array(); auto serviceEntryNoInstanceName = cpptoml::make_table(); serviceEntryNoInstanceName->insert("service", "service"); serviceEntryNoInstanceName->insert("event", "event"); - serviceEntryNoInstanceName->insert("size", 0); serviceArray->push_back(serviceEntryNoInstanceName); toml->insert("services", serviceArray); - // ===== Test - auto result = iox::config::StubbedTomlGatewayConfigParser::validate(*toml); - EXPECT_EQ(true, result.has_error()); - if (result.has_error()) - { - EXPECT_EQ(iox::config::TomlGatewayConfigParseError::INCOMPLETE_SERVICE_DESCRIPTION, result.get_error()); - } + auto result = StubbedTomlGatewayConfigParser::validate(*toml); + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INCOMPLETE_SERVICE_DESCRIPTION, result.get_error()); } -TEST_F(TomlGatewayConfigParserTest, FailsValidationIfNoEventNameInServiceDescription) +TEST_F(TomlGatewayConfigParserTest, NoEventNameInServiceDescriptionReturnIncompleteServiceDescriptionError) { - // ===== Setup - // Prepare configuration to test with auto toml = cpptoml::make_table(); auto serviceArray = cpptoml::make_table_array(); auto serviceEntryNoEventName = cpptoml::make_table(); serviceEntryNoEventName->insert("service", "service"); serviceEntryNoEventName->insert("instance", "instance"); - serviceEntryNoEventName->insert("size", 0); serviceArray->push_back(serviceEntryNoEventName); toml->insert("services", serviceArray); - // ===== Test - auto result = iox::config::StubbedTomlGatewayConfigParser::validate(*toml); - EXPECT_EQ(true, result.has_error()); - if (result.has_error()) - { - EXPECT_EQ(iox::config::TomlGatewayConfigParseError::INCOMPLETE_SERVICE_DESCRIPTION, result.get_error()); - } + auto result = StubbedTomlGatewayConfigParser::validate(*toml); + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INCOMPLETE_SERVICE_DESCRIPTION, result.get_error()); } -TEST_F(TomlGatewayConfigParserTest, FailsValidationIfServiceDescriptionBeginsWithNumber) +TEST_F(TomlGatewayConfigParserTest, ServiceDescriptionBeginsWithNumberReturnInvalidServiceDescriptionError) { - // ===== Setup - // Prepare configuration to test with auto toml = cpptoml::make_table(); auto serviceArray = cpptoml::make_table_array(); @@ -168,53 +211,337 @@ TEST_F(TomlGatewayConfigParserTest, FailsValidationIfServiceDescriptionBeginsWit serviceBeginsWithNumber->insert("service", "0000"); serviceBeginsWithNumber->insert("instance", "0000"); serviceBeginsWithNumber->insert("event", "0000"); - serviceBeginsWithNumber->insert("size", 0); serviceArray->push_back(serviceBeginsWithNumber); toml->insert("services", serviceArray); - // ===== Test + auto result = StubbedTomlGatewayConfigParser::validate(*toml); + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INVALID_SERVICE_DESCRIPTION, result.get_error()); +} + +TEST_F(TomlGatewayConfigParserTest, HyphenInServiceDescriptionReturnInvalidServiceDescriptionError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceEntryWithHyphen = cpptoml::make_table(); + serviceEntryWithHyphen->insert("service", "service-name"); + serviceEntryWithHyphen->insert("instance", "instance-name"); + serviceEntryWithHyphen->insert("event", "event-name"); + serviceArray->push_back(serviceEntryWithHyphen); + toml->insert("services", serviceArray); + + auto result = StubbedTomlGatewayConfigParser::validate(*toml); + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INVALID_SERVICE_DESCRIPTION, result.get_error()); +} + +TEST_F(TomlGatewayConfigParserTest, NoServicesInConfigReturnIncompleteConfigurationError) +{ + auto toml = cpptoml::make_table(); + auto result = iox::config::StubbedTomlGatewayConfigParser::validate(*toml); - EXPECT_EQ(true, result.has_error()); - if (result.has_error()) - { - EXPECT_EQ(iox::config::TomlGatewayConfigParseError::INVALID_SERVICE_DESCRIPTION, result.get_error()); - } + + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INCOMPLETE_CONFIGURATION, result.get_error()); +} + +TEST_F(TomlGatewayConfigParserTest, ParseWithoutParameterTakeDefaultPathReturnNoError) +{ + auto result = TomlGatewayConfigParser::parse(); + GatewayConfig config = result.value(); + + EXPECT_FALSE(result.has_error()); + EXPECT_TRUE(config.m_configuredServices.empty()); +} + +TEST_F(TomlGatewayConfigParserTest, ParseWithEmptyPathReturnEmptyConfig) +{ + iox::roudi::ConfigFilePathString_t path = ""; + + auto result = TomlGatewayConfigParser::parse(path); + GatewayConfig config = result.value(); + + EXPECT_FALSE(result.has_error()); + EXPECT_TRUE(config.m_configuredServices.empty()); } -TEST_F(TomlGatewayConfigParserTest, FailsValidationIfHyphenInServiceDescription) +TEST_F(TomlGatewayConfigParserTest, ValidServiceDescriptionInTomlConfigFileReturnNotEmptyConfigObjectAndNoParseError) { - // ===== Setup - // Prepare configuration to test with auto toml = cpptoml::make_table(); auto serviceArray = cpptoml::make_table_array(); + auto serviceEntry = cpptoml::make_table(); - serviceEntry->insert("service", "service-name"); - serviceEntry->insert("instance", "instance-name"); - serviceEntry->insert("event", "event-name"); - serviceEntry->insert("size", 0); + serviceEntry->insert("service", "service"); + serviceEntry->insert("instance", "instance"); + serviceEntry->insert("event", "event"); serviceArray->push_back(serviceEntry); toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); - // ===== Test - auto result = iox::config::StubbedTomlGatewayConfigParser::validate(*toml); - EXPECT_EQ(true, result.has_error()); - if (result.has_error()) - { - EXPECT_EQ(iox::config::TomlGatewayConfigParseError::INVALID_SERVICE_DESCRIPTION, result.get_error()); - } + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + GatewayConfig config = result.value(); + + EXPECT_FALSE(result.has_error()); + EXPECT_FALSE(config.m_configuredServices.empty()); } -TEST_F(TomlGatewayConfigParserTest, FailsValidationIfNoServicesInConfig) +TEST_F(TomlGatewayConfigParserTest, + ParseServiceDescriptionWithUppercaseInTomlConfigFileReturnNotEmptyConfigObjectAndNoParseError) { - // ===== Setup - // Prepare configuration to test with auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); - // ===== Test - auto result = iox::config::StubbedTomlGatewayConfigParser::validate(*toml); - EXPECT_EQ(true, result.has_error()); - if (result.has_error()) - { - EXPECT_EQ(iox::config::TomlGatewayConfigParseError::INCOMPLETE_CONFIGURATION, result.get_error()); - } + auto serviceEntryUppercase = cpptoml::make_table(); + serviceEntryUppercase->insert("service", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + serviceEntryUppercase->insert("instance", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + serviceEntryUppercase->insert("event", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + serviceArray->push_back(serviceEntryUppercase); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + GatewayConfig config = result.value(); + + EXPECT_FALSE(result.has_error()); + EXPECT_FALSE(config.m_configuredServices.empty()); +} + +TEST_F(TomlGatewayConfigParserTest, + ParseServiceDescriptionWithLowercaseInTomlConfigFileReturnReturnNotEmptyConfigObjectAndNoParseError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceEntryLowercase = cpptoml::make_table(); + serviceEntryLowercase->insert("service", "abcdefghijklmnopqrstuvwxyz"); + serviceEntryLowercase->insert("instance", "abcdefghijklmnopqrstuvwxyz"); + serviceEntryLowercase->insert("event", "abcdefghijklmnopqrstuvwxyz"); + serviceArray->push_back(serviceEntryLowercase); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + GatewayConfig config = result.value(); + + EXPECT_FALSE(result.has_error()); + EXPECT_FALSE(config.m_configuredServices.empty()); +} + +TEST_F(TomlGatewayConfigParserTest, + NumbersUsedInServiceDescriptionInTomlConfigFileReturnNotEmptyConfigObjectAndNoParseError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceEntryNumbers = cpptoml::make_table(); + serviceEntryNumbers->insert("service", "Number1234567890"); + serviceEntryNumbers->insert("instance", "Number1234567890"); + serviceEntryNumbers->insert("event", "Number1234567890"); + serviceArray->push_back(serviceEntryNumbers); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + GatewayConfig config = result.value(); + + EXPECT_FALSE(result.has_error()); + EXPECT_FALSE(config.m_configuredServices.empty()); +} + +TEST_F(TomlGatewayConfigParserTest, + UnderscoreCharactersUsedInServiceDescriptionInTomlFileReturnNotEmptyConfigObjectAndNoParseError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceEntryUnderscore = cpptoml::make_table(); + serviceEntryUnderscore->insert("service", "service_name"); + serviceEntryUnderscore->insert("instance", "instance_name"); + serviceEntryUnderscore->insert("event", "event_name"); + serviceArray->push_back(serviceEntryUnderscore); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + GatewayConfig config = result.value(); + + EXPECT_FALSE(result.has_error()); + EXPECT_FALSE(config.m_configuredServices.empty()); +} + +TEST_F(TomlGatewayConfigParserTest, + ServiceEntryBeginsWithUnderscoresUsedInTomlConfigFileReturnNotEmptyConfigObjectAndNoParseError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceEntryBeginsWithUnderscore = cpptoml::make_table(); + serviceEntryBeginsWithUnderscore->insert("service", "_service_name"); + serviceEntryBeginsWithUnderscore->insert("instance", "_instance_name"); + serviceEntryBeginsWithUnderscore->insert("event", "_event_name"); + serviceArray->push_back(serviceEntryBeginsWithUnderscore); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + GatewayConfig config = result.value(); + + EXPECT_FALSE(result.has_error()); + EXPECT_FALSE(config.m_configuredServices.empty()); +} + +TEST_F(TomlGatewayConfigParserTest, + ParseWithoutServiceNameInServiceDescriptionInTomlConfigFileReturnIncompleteServiceDescriptionError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceEntryNoServiceName = cpptoml::make_table(); + serviceEntryNoServiceName->insert("instance", "instance"); + serviceEntryNoServiceName->insert("event", "event"); + serviceArray->push_back(serviceEntryNoServiceName); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INCOMPLETE_SERVICE_DESCRIPTION, result.get_error()); +} + + +TEST_F(TomlGatewayConfigParserTest, + ParseWithoutInstanceNameInServiceDescriptionInTomlConfigFileReturnIncompleteServiceDescriptionError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceEntryNoInstanceName = cpptoml::make_table(); + serviceEntryNoInstanceName->insert("service", "service"); + serviceEntryNoInstanceName->insert("event", "event"); + serviceArray->push_back(serviceEntryNoInstanceName); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INCOMPLETE_SERVICE_DESCRIPTION, result.get_error()); +} + +TEST_F(TomlGatewayConfigParserTest, + ParseWithoutEventNameInServiceDescriptionInTomlConfigFileReturnIncompleteServiceDescriptionError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceEntryNoEventName = cpptoml::make_table(); + serviceEntryNoEventName->insert("service", "service"); + serviceEntryNoEventName->insert("instance", "instance"); + serviceArray->push_back(serviceEntryNoEventName); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INCOMPLETE_SERVICE_DESCRIPTION, result.get_error()); +} + +TEST_F(TomlGatewayConfigParserTest, + ParseWithServiceDescriptionBeginsWithNumberInTomlConfigFileReturnInvalidServiceDesciptionError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceBeginsWithNumber = cpptoml::make_table(); + serviceBeginsWithNumber->insert("service", "0000"); + serviceBeginsWithNumber->insert("instance", "0000"); + serviceBeginsWithNumber->insert("event", "0000"); + serviceArray->push_back(serviceBeginsWithNumber); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INVALID_SERVICE_DESCRIPTION, result.get_error()); +} + +TEST_F(TomlGatewayConfigParserTest, + ParseWithHyphenInServiceDescriptionInTomlConfigFileReturnInvalidServiceDesciptionError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceEntryWithHyphen = cpptoml::make_table(); + serviceEntryWithHyphen->insert("service", "service-name"); + serviceEntryWithHyphen->insert("instance", "instance-name"); + serviceEntryWithHyphen->insert("event", "event-name"); + serviceArray->push_back(serviceEntryWithHyphen); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INVALID_SERVICE_DESCRIPTION, result.get_error()); +} + +TEST_F(TomlGatewayConfigParserTest, + ParseServiceDescriptionWithInvalidCharactersInTomlConfigFileReturnInvalidServiceDesciptionError) +{ + auto toml = cpptoml::make_table(); + auto serviceArray = cpptoml::make_table_array(); + + auto serviceEntryWithInvalidCharacters = cpptoml::make_table(); + serviceEntryWithInvalidCharacters->insert("service", "這場考試_!*#:"); + serviceEntryWithInvalidCharacters->insert("instance", "這場考試_!*#:"); + serviceEntryWithInvalidCharacters->insert("event", "這場考試_!*#:"); + serviceArray->push_back(serviceEntryWithInvalidCharacters); + toml->insert("services", serviceArray); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INVALID_SERVICE_DESCRIPTION, result.get_error()); +} + +TEST_F(TomlGatewayConfigParserTest, ParseWithoutServicesConfigurationInTomlConfigFileReturnIncompleteConfigurationError) +{ + auto toml = cpptoml::make_table(); + CreateTmpTomlFile(toml); + + iox::roudi::ConfigFilePathString_t Path = + iox::roudi::ConfigFilePathString_t(iox::cxx::TruncateToCapacity, TestFilePath); + auto result = TomlGatewayConfigParser::parse(Path); + + ASSERT_TRUE(result.has_error()); + EXPECT_EQ(TomlGatewayConfigParseError::INCOMPLETE_CONFIGURATION, result.get_error()); }