From 7c9d4b03c64ea58364029e5f1a069528b4f8a93c Mon Sep 17 00:00:00 2001 From: KRM7 <70973547+KRM7@users.noreply.github.com> Date: Wed, 7 Aug 2024 22:23:41 +0200 Subject: [PATCH] add some additional tests --- test/small_unique_ptr.cpp | 48 ++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/test/small_unique_ptr.cpp b/test/small_unique_ptr.cpp index 461f58f..191d857 100644 --- a/test/small_unique_ptr.cpp +++ b/test/small_unique_ptr.cpp @@ -124,7 +124,7 @@ TEST_CASE("object_size_default", "[small_unique_ptr]") TEMPLATE_TEST_CASE("object_size_custom", "[small_unique_ptr]", Base, BaseIntrusive) { STATIC_REQUIRE(sizeof(small_unique_ptr) == 8); - STATIC_REQUIRE(sizeof(small_unique_ptr) <= 16); // Base will be always heaps allocated on 64 bit arch + STATIC_REQUIRE(sizeof(small_unique_ptr) <= 16); // Base will be always heap allocated on 64 bit arch STATIC_REQUIRE(sizeof(small_unique_ptr) == 24); STATIC_REQUIRE(sizeof(small_unique_ptr) == 32); STATIC_REQUIRE(sizeof(small_unique_ptr) == 40); @@ -134,17 +134,23 @@ TEMPLATE_TEST_CASE("object_size_custom", "[small_unique_ptr]", Base, BaseIntrusi STATIC_REQUIRE(sizeof(small_unique_ptr) == 128); } -TEMPLATE_TEST_CASE("object_alignment_custom", "[small_unique_ptr]", Base, BaseIntrusive) +TEMPLATE_TEST_CASE("object_align_custom", "[small_unique_ptr]", Base, BaseIntrusive) { STATIC_REQUIRE(alignof(small_unique_ptr) == 8); - STATIC_REQUIRE(alignof(small_unique_ptr) <= 16); // Base will be always heaps allocated on 64 bit arch + STATIC_REQUIRE(alignof(small_unique_ptr) <= 16); // Base will be always heap allocated on 64 bit arch + STATIC_REQUIRE(alignof(small_unique_ptr) == 8); STATIC_REQUIRE(alignof(small_unique_ptr) == 32); + STATIC_REQUIRE(alignof(small_unique_ptr) == 8); + STATIC_REQUIRE(alignof(small_unique_ptr) == 16); + STATIC_REQUIRE(alignof(small_unique_ptr) == 8); STATIC_REQUIRE(alignof(small_unique_ptr) == 64); STATIC_REQUIRE(alignof(small_unique_ptr) == 128); } -TEST_CASE("object_alignment_custom_pod", "[small_unique_ptr]") +TEST_CASE("object_align_custom_pod", "[small_unique_ptr]") { + static_assert(alignof(SmallPOD) <= alignof(SmallPOD*)); + STATIC_REQUIRE(alignof(small_unique_ptr) == alignof(SmallPOD*)); STATIC_REQUIRE(alignof(small_unique_ptr) == alignof(SmallPOD*)); STATIC_REQUIRE(alignof(small_unique_ptr) == alignof(SmallPOD*)); @@ -166,32 +172,37 @@ TEST_CASE("stack_buffer_size", "[small_unique_ptr]") STATIC_REQUIRE(small_unique_ptr::stack_buffer_size() != 0); STATIC_REQUIRE(small_unique_ptr::stack_buffer_size() == 0); - STATIC_REQUIRE(small_unique_ptr::stack_buffer_size() == 0); + STATIC_REQUIRE(small_unique_ptr::stack_buffer_size() != 0); + STATIC_REQUIRE(small_unique_ptr::stack_buffer_size() != 0); + + STATIC_REQUIRE(small_unique_ptr::stack_buffer_size() == 0); STATIC_REQUIRE(small_unique_ptr::stack_buffer_size() == 0); + STATIC_REQUIRE(small_unique_ptr::stack_buffer_size() > small_unique_ptr::stack_buffer_size()); STATIC_REQUIRE(small_unique_ptr::stack_buffer_size() > small_unique_ptr::stack_buffer_size()); -} -TEST_CASE("stack_buffer_size_archdep", "[small_unique_ptr][!mayfail]") -{ - REQUIRE(small_unique_ptr::stack_buffer_size() == 48); - REQUIRE(small_unique_ptr::stack_buffer_size() == 56); + CHECKED_IF(sizeof(void*) == 8) + { + REQUIRE(small_unique_ptr::stack_buffer_size() == 48); + REQUIRE(small_unique_ptr::stack_buffer_size() == 56); - REQUIRE(small_unique_ptr::stack_buffer_size() == 56); -} + REQUIRE(small_unique_ptr::stack_buffer_size() == 48); + REQUIRE(small_unique_ptr::stack_buffer_size() == 56); -TEST_CASE("stack_array_size_archdep", "[small_unique_ptr][!mayfail]") -{ - REQUIRE(small_unique_ptr::stack_array_size() == 56); - REQUIRE(small_unique_ptr::stack_array_size() == 0); + REQUIRE(small_unique_ptr::stack_buffer_size() == 56); + + REQUIRE(small_unique_ptr::stack_array_size() == 56); + REQUIRE(small_unique_ptr::stack_array_size() == 0); - REQUIRE(small_unique_ptr::stack_array_size() > 0); + REQUIRE(small_unique_ptr::stack_array_size() > 0); + } } -TEMPLATE_TEST_CASE("construction_scalar", "[small_unique_ptr]", SmallPOD, LargePOD, Base, SmallDerived, LargeDerived, BaseIntrusive, SmallIntrusive, LargeIntrusive) +TEMPLATE_TEST_CASE("construct_scalar", "[small_unique_ptr]", SmallPOD, LargePOD, Base, SmallDerived, LargeDerived, BaseIntrusive, SmallIntrusive, LargeIntrusive) { STATIC_REQUIRE( std::invoke([]{ (void) small_unique_ptr(); return true; }) ); STATIC_REQUIRE( std::invoke([]{ (void) small_unique_ptr(); return true; }) ); + STATIC_REQUIRE( std::invoke([]{ (void) small_unique_ptr(nullptr); return true; }) ); STATIC_REQUIRE( std::invoke([]{ (void) small_unique_ptr(nullptr); return true; }) ); } @@ -220,6 +231,7 @@ TEMPLATE_TEST_CASE("construction_array", "[small_unique_ptr]", SmallPOD, LargePO { STATIC_REQUIRE( std::invoke([]{ (void) small_unique_ptr(); return true; }) ); STATIC_REQUIRE( std::invoke([]{ (void) small_unique_ptr(); return true; }) ); + STATIC_REQUIRE( std::invoke([]{ (void) small_unique_ptr(nullptr); return true; }) ); STATIC_REQUIRE( std::invoke([]{ (void) small_unique_ptr(nullptr); return true; }) ); }