From 17e79d4535ef4dba7346dedb2a8341fc4421fa23 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sat, 3 Jan 2015 15:52:40 +0100 Subject: added test for the RttiBase::contains function --- test/core/common/RttiTest.cpp | 52 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/core/common/RttiTest.cpp b/test/core/common/RttiTest.cpp index 64b4bb0..7990593 100644 --- a/test/core/common/RttiTest.cpp +++ b/test/core/common/RttiTest.cpp @@ -25,16 +25,25 @@ #include namespace ousia { +namespace { -class RttiTestClass1 {}; -class RttiTestClass2 {}; -class RttiTestClass3 {}; -class RttiTestClass4 {}; +class RttiTestClass1 { +}; +class RttiTestClass2 { +}; +class RttiTestClass3 { +}; +class RttiTestClass4 { +}; -static const Rtti Type1("Type1"); -static const Rtti Type2("Type2"); -static const Rtti Type3("Type3", {&Type1}); -static const Rtti Type4("Type4", {&Type3, &Type2}); +extern const Rtti Type6; + +const Rtti Type1("Type1"); +const Rtti Type2("Type2"); +const Rtti Type3("Type3", {&Type1}); +const Rtti Type4("Type4", {&Type3, &Type2}); +const Rtti Type5("Type5", {}, {&Type6}); +const Rtti Type6("Type6", {}, {&Type5, &Type1}); TEST(Rtti, isa) { @@ -59,5 +68,32 @@ TEST(Rtti, isa) ASSERT_TRUE(Type4.isa(Type4)); } +TEST(Rtti, contains) +{ + std::vector types{&Type1, &Type2, &Type3, &Type4}; + for (auto t : types) { + ASSERT_FALSE(t->contains(Type1)); + ASSERT_FALSE(t->contains(Type2)); + ASSERT_FALSE(t->contains(Type3)); + ASSERT_FALSE(t->contains(Type4)); + ASSERT_FALSE(t->contains(Type5)); + ASSERT_FALSE(t->contains(Type6)); + } + + ASSERT_TRUE(Type5.contains(Type1)); + ASSERT_FALSE(Type5.contains(Type2)); + ASSERT_FALSE(Type5.contains(Type3)); + ASSERT_FALSE(Type5.contains(Type4)); + ASSERT_TRUE(Type5.contains(Type5)); + ASSERT_TRUE(Type5.contains(Type6)); + + ASSERT_TRUE(Type6.contains(Type1)); + ASSERT_FALSE(Type6.contains(Type2)); + ASSERT_FALSE(Type6.contains(Type3)); + ASSERT_FALSE(Type6.contains(Type4)); + ASSERT_TRUE(Type6.contains(Type5)); + ASSERT_TRUE(Type6.contains(Type6)); +} +} } -- cgit v1.2.3