| 10 | #include "fl/stl/static_assert.h" |
| 11 | |
| 12 | FL_TEST_FILE(FL_FILEPATH) { |
| 13 | |
| 14 | using namespace fl; |
| 15 | |
| 16 | // Test allocation_result struct |
| 17 | FL_TEST_CASE("fl::allocation_result") { |
| 18 | FL_SUBCASE("basic construction") { |
| 19 | allocation_result<int*, fl::size> result{nullptr, 0}; |
| 20 | FL_CHECK_EQ(result.ptr, nullptr); |
| 21 | FL_CHECK_EQ(result.count, 0); |
| 22 | |
| 23 | int value = 42; |
| 24 | allocation_result<int*, fl::size> result2{&value, 1}; |
| 25 | FL_CHECK_EQ(result2.ptr, &value); |
| 26 | FL_CHECK_EQ(result2.count, 1); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // Test allocator_traits |
| 31 | FL_TEST_CASE("fl::allocator_traits") { |
| 32 | FL_SUBCASE("basic allocator traits") { |
| 33 | using traits = allocator_traits<allocator<int>>; |
| 34 | FL_CHECK((fl::is_same<traits::value_type, int>::value)); |
| 35 | FL_CHECK((fl::is_same<traits::pointer, int*>::value)); |
| 36 | FL_CHECK((fl::is_same<traits::size_type, fl::size>::value)); |
| 37 | } |
| 38 | |
| 39 | FL_SUBCASE("allocator_realloc has both capabilities") { |
| 40 | // allocator_realloc should support both reallocate() and allocate_at_least() |
| 41 | FL_STATIC_ASSERT(allocator_traits<allocator_realloc<int>>::has_reallocate_v, |
| 42 | "allocator_realloc should support reallocate()"); |
| 43 | FL_STATIC_ASSERT(allocator_traits<allocator_realloc<int>>::has_allocate_at_least_v, |
| 44 | "allocator_realloc should support allocate_at_least()"); |
| 45 | FL_CHECK(true); // Compile-time checks passed |
| 46 | } |
| 47 | |
| 48 | FL_SUBCASE("base allocator<T> has allocate_at_least") { |
| 49 | // Standard allocator should have allocate_at_least() (with default implementation) |
| 50 | FL_STATIC_ASSERT(allocator_traits<allocator<int>>::has_allocate_at_least_v, |
| 51 | "allocator<T> should support allocate_at_least()"); |
| 52 | FL_CHECK(true); |
| 53 | } |
| 54 | |
| 55 | FL_SUBCASE("base allocator<T> has default reallocate") { |
| 56 | // Standard allocator has reallocate() that returns nullptr (no-op) |
| 57 | FL_STATIC_ASSERT(allocator_traits<allocator<int>>::has_reallocate_v, |
| 58 | "allocator<T> should have reallocate() method"); |
| 59 | FL_CHECK(true); |
| 60 | } |
| 61 | |
| 62 | FL_SUBCASE("allocator_psram capabilities") { |
| 63 | // PSRam allocator may or may not have the optional methods |
| 64 | // Just verify the traits can be queried without errors |
| 65 | (void)allocator_traits<allocator_psram<int>>::has_allocate_at_least_v; |
| 66 | (void)allocator_traits<allocator_psram<int>>::has_reallocate_v; |
| 67 | FL_CHECK(true); // Just checking it compiles |
| 68 | } |
| 69 |
nothing calls this directly
no test coverage detected