cpp-ipc/test/imp/test_imp_byte.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

58 lines
960 B
C++

#include "../archive/test.h"
#include "libipc/imp/byte.h"
#include "libipc/imp/span.h"
#include "libipc/imp/detect_plat.h"
TEST(byte, construct) {
{
LIBIPC_UNUSED ipc::byte b;
SUCCEED();
}
{
ipc::byte b{};
EXPECT_EQ(int(b), 0);
}
{
ipc::byte b{123};
EXPECT_EQ(int(b), 123);
}
{
ipc::byte b{65535};
EXPECT_EQ(int(b), 255);
EXPECT_EQ(std::int8_t(b), -1);
}
{
ipc::byte b{65536};
EXPECT_EQ(int(b), 0);
}
}
TEST(byte, compare) {
{
ipc::byte b1{}, b2{};
EXPECT_EQ(b1, b2);
}
{
ipc::byte b1{}, b2(321);
EXPECT_NE(b1, b2);
}
}
TEST(byte, byte_cast) {
int a = 654321;
int *pa = &a;
// int * => byte *
ipc::byte *pb = ipc::byte_cast(pa);
EXPECT_EQ((std::size_t)pb, (std::size_t)pa);
// byte * => int32_t *
std::int32_t *pc = ipc::byte_cast<std::int32_t>(pb);
EXPECT_EQ(*pc, a);
// byte alignment check
EXPECT_EQ(ipc::byte_cast<int>(pb + 1), nullptr);
}