diff options
author | Derek Lamberti <derek.lamberti@arm.com> | 2020-02-19 13:30:47 +0000 |
---|---|---|
committer | Derek Lamberti <derek.lamberti@arm.com> | 2020-03-09 09:17:21 +0000 |
commit | 4d4e0e2530629ae9ecfcb379bf0f27c6b18b6891 (patch) | |
tree | 5240428061fe5c57ce1c762908166432bca7d0c5 /src/armnn/test | |
parent | e66448491b836049df62e63e1e5151eefe3bfcf8 (diff) | |
download | armnn-4d4e0e2530629ae9ecfcb379bf0f27c6b18b6891.tar.gz |
IVGCVSW-4483 Introduce polymorphic_downcast implementation
Change-Id: I958dd719162337eb5c7e71f4ac49dd5784564b1a
Signed-off-by: Derek Lamberti <derek.lamberti@arm.com>
Diffstat (limited to 'src/armnn/test')
-rw-r--r-- | src/armnn/test/UtilityTests.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/armnn/test/UtilityTests.cpp b/src/armnn/test/UtilityTests.cpp new file mode 100644 index 0000000000..5309d82ce4 --- /dev/null +++ b/src/armnn/test/UtilityTests.cpp @@ -0,0 +1,56 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <boost/test/unit_test.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/polymorphic_cast.hpp> + +#define ARMNN_POLYMORPHIC_CAST_TESTABLE + +#include <armnn/utility/IgnoreUnused.hpp> +#include <armnn/utility/PolymorphicDowncast.hpp> + +#include <armnn/Exceptions.hpp> + +// Tests of include/Utility files +BOOST_AUTO_TEST_SUITE(UtilityTests) + +BOOST_AUTO_TEST_CASE(PolymorphicDowncast) +{ + using namespace armnn; + class Base + { + public: + virtual ~Base(){} + float v; + }; + + class Child1 : public Base + { + public: + int j; + }; + + class Child2 : public Base + { + public: + char b; + }; + + Child1 child1; + Base* base1 = &child1; + auto ptr1 = dynamic_cast<Child1*>(base1); + BOOST_CHECK(ptr1 != nullptr); + BOOST_CHECK_NO_THROW(polymorphic_downcast<Child1*>(base1)); + BOOST_CHECK(polymorphic_downcast<Child1*>(base1) == ptr1); + + auto ptr2 = dynamic_cast<Child2*>(base1); + BOOST_CHECK(ptr2 == nullptr); + BOOST_CHECK_THROW(polymorphic_downcast<Child2*>(base1), std::bad_cast); + + armnn::IgnoreUnused(ptr1, ptr2); +} + +BOOST_AUTO_TEST_SUITE_END() |