forked from Alepha/Alepha
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
static_assert( __cplusplus > 2020'99 );
|
|
|
|
#include "../derived_pointer_cast.h"
|
|
|
|
#include <Alepha/Testing/TableTest.h>
|
|
#include <Alepha/Testing/test.h>
|
|
|
|
#include <Alepha/Utility/evaluation_helpers.h>
|
|
|
|
static auto init= Alepha::Utility::enroll <=[]
|
|
{
|
|
using namespace Alepha::Testing::exports;
|
|
|
|
struct Base
|
|
{
|
|
virtual ~Base()= default;
|
|
};
|
|
|
|
struct Derived : Base {};
|
|
|
|
struct Derived2 : Base {};
|
|
|
|
"Can `derived_pointer_cast` work on simple cases?"_test <=TableTest
|
|
<
|
|
[]( std::function< std::unique_ptr< Base >() > makeBase )
|
|
{
|
|
auto base= makeBase();
|
|
return static_cast< bool >( Alepha::Utility::derived_pointer_cast< Derived >( std::move( base ) ) );
|
|
}
|
|
>
|
|
::Cases
|
|
{
|
|
{ "Is derived", { [] { return std::make_unique< Derived >(); } }, true },
|
|
{ "Not derived", { [] { return std::make_unique< Base >(); } }, std::type_identity< std::bad_cast >{} },
|
|
{ "Other derived", { [] { return std::make_unique< Derived2 >(); } }, std::type_identity< std::bad_cast >{} },
|
|
};
|
|
|
|
struct Alien
|
|
{
|
|
virtual ~Alien()= default;
|
|
};
|
|
|
|
struct AlienDerived : Alien {};
|
|
|
|
"Alien Test"_test <=TableTest
|
|
<
|
|
[]( std::function< std::unique_ptr< Alien >() > makeBase )
|
|
{
|
|
auto base= makeBase();
|
|
return static_cast< bool >( Alepha::Utility::derived_pointer_cast< Derived >( std::move( base ) ) );
|
|
}
|
|
>
|
|
::Cases
|
|
{
|
|
{ "Alien", { [] { return std::make_unique< Alien >(); } }, std::type_identity< std::bad_cast >{} },
|
|
{ "Alien Derived", { [] { return std::make_unique< AlienDerived >(); } }, std::type_identity< std::bad_cast >{} },
|
|
};
|
|
};
|