mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
Add unit tests for small_storage
This commit is contained in:
parent
c503812c6f
commit
6a243514ae
@ -454,7 +454,7 @@ public:
|
|||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
class small_storage {
|
class small_storage {
|
||||||
|
|
||||||
static_assert(N > sizeof(holder<int, false>), "N must be greater than sizeof(holder<int, false>)");
|
static_assert(N >= sizeof(holder<void *, false>), "N must be greater than sizeof(holder<void *, false>)");
|
||||||
|
|
||||||
alignas(std::max_align_t) std::array<::LIBIMP::byte, N> storage_;
|
alignas(std::max_align_t) std::array<::LIBIMP::byte, N> storage_;
|
||||||
|
|
||||||
@ -467,11 +467,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
holder_base *get_holder() noexcept {
|
holder_base *get_holder() noexcept {
|
||||||
return static_cast<holder_base *>(storage_.data());
|
return reinterpret_cast<holder_base *>(storage_.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
holder_base const *get_holder() const noexcept {
|
holder_base const *get_holder() const noexcept {
|
||||||
return static_cast<holder_base const *>(storage_.data());
|
return reinterpret_cast<holder_base const *>(storage_.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool valid() const noexcept {
|
bool valid() const noexcept {
|
||||||
|
|||||||
@ -99,5 +99,21 @@ TEST(small_storage, holder_copy_move) {
|
|||||||
h12.destroy(alc);
|
h12.destroy(alc);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(small_storage, construct) {
|
TEST(small_storage, sizeof) {
|
||||||
|
EXPECT_EQ(sizeof(pmr::holder_null), sizeof(void *));
|
||||||
|
EXPECT_EQ(sizeof(pmr::holder<int, true>), sizeof(void *) + imp::round_up(sizeof(int), alignof(void *)));
|
||||||
|
EXPECT_EQ(sizeof(pmr::holder<int, false>), sizeof(void *) + sizeof(void *));
|
||||||
|
EXPECT_EQ(sizeof(pmr::holder<void, true>), sizeof(void *) + sizeof(void *) + sizeof(pmr::detail::holder_info));
|
||||||
|
EXPECT_EQ(sizeof(pmr::holder<void, false>), sizeof(void *) + sizeof(void *));
|
||||||
|
|
||||||
|
// pmr::small_storage<4> s1;
|
||||||
|
EXPECT_EQ(sizeof(pmr::small_storage<16>) , 16);
|
||||||
|
EXPECT_EQ(sizeof(pmr::small_storage<64>) , 64);
|
||||||
|
EXPECT_EQ(sizeof(pmr::small_storage<512>) , 512);
|
||||||
|
EXPECT_EQ(sizeof(pmr::small_storage<4096>), 4096);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(small_storage, construct) {
|
||||||
|
pmr::small_storage<64> ss;
|
||||||
|
SUCCEED();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user