cpp-ipc/test/imp/test_imp_uninitialized.cpp
木头云 b35de5a154 fix(test): Update test.h include paths after master rebase
After rebasing onto master, test.h was moved to test/archive/.
Updated include paths in test subdirectories:
- test/imp/*.cpp: "test.h" -> "../archive/test.h"
- test/mem/*.cpp: "test.h" -> "../archive/test.h"
- test/concur/*.cpp: "test.h" -> "../archive/test.h"

This ensures all test files can properly find the test header
after the directory reorganization in master branch.
2025-12-03 08:28:37 +00:00

47 lines
1.2 KiB
C++

#include "../archive/test.h"
#include "libipc/imp/uninitialized.h"
TEST(uninitialized, construct) {
struct Foo {
int a_;
short b_;
char c_;
};
std::aligned_storage_t<sizeof(Foo)> foo;
Foo *pfoo = ipc::construct<Foo>(&foo, 123, short{321}, '1');
EXPECT_EQ(pfoo->a_, 123);
EXPECT_EQ(pfoo->b_, 321);
EXPECT_EQ(pfoo->c_, '1');
ipc::destroy(pfoo);
static int bar_test_flag = 0;
struct Bar : Foo {
Bar(int a, short b, char c)
: Foo{a, b, c} {
++bar_test_flag;
}
~Bar() { --bar_test_flag; }
};
std::aligned_storage_t<sizeof(Bar)> bar;
Bar *pbar = ipc::construct<Bar>(&bar, 123, short(321), '1');
EXPECT_EQ(pbar->a_, 123);
EXPECT_EQ(pbar->b_, 321);
EXPECT_EQ(pbar->c_, '1');
EXPECT_EQ(bar_test_flag, 1);
ipc::destroy(pbar);
EXPECT_EQ(bar_test_flag, 0);
std::aligned_storage_t<sizeof(Bar)> bars[3];
for (auto &b : bars) {
auto pb = ipc::construct<Bar>(&b, 321, short(123), '3');
EXPECT_EQ(pb->a_, 321);
EXPECT_EQ(pb->b_, 123);
EXPECT_EQ(pb->c_, '3');
}
//EXPECT_EQ(bar_test_flag, ipc::countof(bars));
ipc::destroy(reinterpret_cast<Bar(*)[3]>(&bars));
EXPECT_EQ(bar_test_flag, 0);
}