diff options
Diffstat (limited to 'EASTL/test/source/TestMemory.cpp')
-rw-r--r-- | EASTL/test/source/TestMemory.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/EASTL/test/source/TestMemory.cpp b/EASTL/test/source/TestMemory.cpp index 4e25738..77caf9f 100644 --- a/EASTL/test/source/TestMemory.cpp +++ b/EASTL/test/source/TestMemory.cpp @@ -133,6 +133,23 @@ eastl::late_constructed<LCTestObject, false, true> gLCTestObjectFalseTrue; eastl::late_constructed<LCTestObject, false, false> gLCTestObjectFalseFalse; eastl::late_constructed<LCTestObject, true, false> gLCTestObjectTrueFalse; +struct TypeWithPointerTraits {}; + +namespace eastl +{ + template <> + struct pointer_traits<TypeWithPointerTraits> + { + // Note: only parts of the traits we are interested to test are defined here. + static const int* to_address(TypeWithPointerTraits) + { + return &a; + } + + inline static constexpr int a = 42; + }; +} + /////////////////////////////////////////////////////////////////////////////// // TestMemory @@ -684,6 +701,33 @@ int TestMemory() } } + // to_address + { + // Normal pointers. + int a; + int* ptrA = &a; + EATEST_VERIFY(ptrA == to_address(ptrA)); + + // Smart pointer. + struct MockSmartPointer + { + const int* operator->() const + { + return &a; + } + + int a = 42; + }; + + MockSmartPointer sp; + EATEST_VERIFY(&sp.a == to_address(sp)); + + // Type with specialized pointer_traits. + TypeWithPointerTraits t; + const int* result = to_address(t); + EATEST_VERIFY(result != nullptr && *result == 42); + } + { // Test that align handles integral overflow correctly and returns NULL. void* ptr; |