Skip to content

Commit 8b9ad85

Browse files
Add test to verify support of nested AnyMaps in initializer lists (CppMicroServices#1011) (CppMicroServices#1149)
Signed-off-by: Toby Cormack <tcormack@mathworks.com> Co-authored-by: tcormackMW <113473781+tcormackMW@users.noreply.github.com>
1 parent b43223c commit 8b9ad85

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

compendium/ServiceComponent/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ endforeach()
146146
#Set test properties for compile-only tests to check if compilation fails and corresponding errors are generated in the log
147147
set_tests_properties(usServiceComponentRefOrderTest PROPERTIES PASS_REGULAR_EXPRESSION ".*An appropriate constructor was not found and/or the service implementation does not implement all of the service interface's methods. A constructor with service reference input parameters or a constructor with an AnyMap input parameter for configuration properties and service reference input parameters is required when inject-references is true.*")
148148
set_tests_properties(usServiceComponentRefOrderMultipleCardinalityTest PROPERTIES PASS_REGULAR_EXPRESSION ".*An appropriate constructor was not found and/or the service implementation does not implement all of the service interface's methods. A constructor with service reference input parameters or a constructor with an AnyMap input parameter for configuration properties and service reference input parameters is required when inject-references is true.*")
149-
set_tests_properties(usServiceComponentInvalidInheritanceTest PROPERTIES PASS_REGULAR_EXPRESSION ".*['static_cast' cannot convert].* [Types pointed to are unrelated] .* [conversion requires reinterpret_cast, C-style cast or function-style cast] .*")
149+
set_tests_properties(usServiceComponentInvalidInheritanceTest PROPERTIES PASS_REGULAR_EXPRESSION ".*[error C2440: 'static_cast': cannot convert from].*")
150150
set_tests_properties(usServiceComponentNoDepsNoDefaultCtorTest PROPERTIES PASS_REGULAR_EXPRESSION ".*An appropriate constructor was not found and/or the service implementation does not implement all of the service interface's methods. A default constructor or a constructor with an AnyMap input parameter for the configuration properties is required when inject-references is false..*")
151151
set_tests_properties(usServiceComponentNoDefaultCtorTest PROPERTIES PASS_REGULAR_EXPRESSION ".*An appropriate constructor was not found and/or the service implementation does not implement all of the service interface's methods. A constructor with service reference input parameters or a constructor with an AnyMap input parameter for configuration properties and service reference input parameters is required when inject-references is true.*")
152152
set_tests_properties(usServiceComponentRefCountTest PROPERTIES PASS_REGULAR_EXPRESSION ".*An appropriate constructor was not found and/or the service implementation does not implement all of the service interface's methods. A constructor with service reference input parameters or a constructor with an AnyMap input parameter for configuration properties and service reference input parameters is required when inject-references is true.*")

framework/test/gtest/AnyMapTest.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ TEST(AnyMapTest, AnyMap)
176176
ASSERT_EQ(any_cast<int>(uo_anymap1.at("re")), 2);
177177

178178
// Testing AnyMap::operator[] (const)
179-
const std::string key = "re";
179+
std::string const key = "re";
180180
o_anymap1[key] = 10;
181181
uo_anymap1[key] = 10;
182182
uo_anymap1.insert(std::make_pair(std::string("mi"), Any(3)));
@@ -442,4 +442,24 @@ TEST(AnyMapTest, InitializerList)
442442
EXPECT_EQ(2, unordered_any_cimap.size());
443443
EXPECT_EQ(Any(7), unordered_any_cimap.at("g"));
444444
EXPECT_EQ(Any(8), unordered_any_cimap.at("h"));
445+
AnyMap nested {
446+
{{ "n", 9 }, { "o", 10 }, { "p", std::string("C") }}
447+
};
448+
AnyMap unordered_any_nested {
449+
{
450+
{ "j", 7 },
451+
{ "k", 8 },
452+
{ "l", std::string("B") },
453+
{ "m", AnyMap { { { "n", 9 }, { "o", 10 }, { "p", std::string("C") } } } },
454+
}
455+
};
456+
EXPECT_EQ(any_map::UNORDERED_MAP_CASEINSENSITIVE_KEYS, unordered_any_nested.GetType());
457+
EXPECT_EQ(4, unordered_any_nested.size());
458+
EXPECT_EQ(Any(7), unordered_any_nested.at("j"));
459+
EXPECT_EQ(Any(8), unordered_any_nested.at("k"));
460+
EXPECT_EQ(std::string("B"), any_cast<std::string>(unordered_any_nested.at("l")));
461+
EXPECT_EQ(AnyMap(nested), any_cast<AnyMap>(unordered_any_nested.at("m")));
462+
EXPECT_EQ(Any(9), any_cast<AnyMap>(unordered_any_nested.at("m")).at("n"));
463+
EXPECT_EQ(Any(10), any_cast<AnyMap>(unordered_any_nested.at("m")).at("o"));
464+
EXPECT_EQ(std::string("C"), any_cast<std::string>(any_cast<AnyMap>(unordered_any_nested.at("m")).at("p")));
445465
}

0 commit comments

Comments
 (0)