From 4d4e0e2530629ae9ecfcb379bf0f27c6b18b6891 Mon Sep 17 00:00:00 2001 From: Derek Lamberti Date: Wed, 19 Feb 2020 13:30:47 +0000 Subject: IVGCVSW-4483 Introduce polymorphic_downcast implementation Change-Id: I958dd719162337eb5c7e71f4ac49dd5784564b1a Signed-off-by: Derek Lamberti --- src/armnn/test/UtilityTests.cpp | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/armnn/test/UtilityTests.cpp (limited to 'src/armnn/test/UtilityTests.cpp') 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 +#include +#include + +#define ARMNN_POLYMORPHIC_CAST_TESTABLE + +#include +#include + +#include + +// 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(base1); + BOOST_CHECK(ptr1 != nullptr); + BOOST_CHECK_NO_THROW(polymorphic_downcast(base1)); + BOOST_CHECK(polymorphic_downcast(base1) == ptr1); + + auto ptr2 = dynamic_cast(base1); + BOOST_CHECK(ptr2 == nullptr); + BOOST_CHECK_THROW(polymorphic_downcast(base1), std::bad_cast); + + armnn::IgnoreUnused(ptr1, ptr2); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1