test/psock/test_psock_read_write_boxed_data.cpp
/**
 * Verify that we can read and write boxed data values.
 */
Verify that we can read and write boxed data values.
Verify that we can read and write boxed data values .
TEST(read_write_data)
{
    allocator* alloc = nullptr;
    psock* ls = nullptr;
    psock* rs = nullptr;
    int lhs;
    int rhs;
    const uint8_t EXPECTED_VALUE[] = {7, 6, 4, 1, 3 };
    uint8_t* val = nullptr;
    size_t val_size = 0U;
    TEST_ASSERT(
        STATUS_SUCCESS == malloc_allocator_create(&alloc));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            socket_utility_socketpair(AF_UNIX, SOCK_STREAM, 0, &lhs, &rhs));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            psock_create_from_descriptor(
                &ls, alloc, lhs));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            psock_create_from_descriptor(
                &rs, alloc, rhs));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            psock_write_boxed_data(ls, EXPECTED_VALUE, sizeof(EXPECTED_VALUE)));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            psock_read_boxed_data(rs, alloc, (void**)&val, &val_size));
    TEST_ASSERT(sizeof(EXPECTED_VALUE) == val_size);
    TEST_ASSERT(nullptr != val);
    TEST_EXPECT(0 == memcmp(EXPECTED_VALUE, val, sizeof(EXPECTED_VALUE)));
    TEST_ASSERT(STATUS_SUCCESS == allocator_reclaim(alloc, val));
    TEST_ASSERT(STATUS_SUCCESS == resource_release(psock_resource_handle(ls)));
    TEST_ASSERT(STATUS_SUCCESS == resource_release(psock_resource_handle(rs)));
    TEST_ASSERT(
        STATUS_SUCCESS == resource_release(allocator_resource_handle(alloc)));
}
TEST ( read_write_data ) { allocator * alloc = nullptr ; psock * ls = nullptr ; psock * rs = nullptr ; int lhs ; int rhs ; const uint8_t EXPECTED_VALUE [ ] = { 7 , 6 , 4 , 1 , 3 } ; uint8_t * val = nullptr ; size_t val_size = 0U ; TEST_ASSERT ( STATUS_SUCCESS == malloc_allocator_create ( & alloc ) ) ; TEST_ASSERT ( STATUS_SUCCESS == socket_utility_socketpair ( AF_UNIX , SOCK_STREAM , 0 , & lhs , & rhs ) ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_create_from_descriptor ( & ls , alloc , lhs ) ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_create_from_descriptor ( & rs , alloc , rhs ) ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_write_boxed_data ( ls , EXPECTED_VALUE , sizeof ( EXPECTED_VALUE ) ) ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_read_boxed_data ( rs , alloc , ( void * * ) & val , & val_size ) ) ; TEST_ASSERT ( sizeof ( EXPECTED_VALUE ) == val_size ) ; TEST_ASSERT ( nullptr != val ) ; TEST_EXPECT ( 0 == memcmp ( EXPECTED_VALUE , val , sizeof ( EXPECTED_VALUE ) ) ) ; TEST_ASSERT ( STATUS_SUCCESS == allocator_reclaim ( alloc , val ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( psock_resource_handle ( ls ) ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( psock_resource_handle ( rs ) ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( allocator_resource_handle ( alloc ) ) ) ; }
Verify that we can read and write boxed data values.
Verify that we can read and write boxed data values .
/* we should be able to create a malloc allocator. */ /* we should be able to create a socket pair. */ /* we should be able to create a psock from the lhs socket. */ /* we should be able to create a psock from the rhs socket. */ /* we should be able to write a 8-bit unsigned integer to the lhs socket. */ /* we should be able to read a 8-bit unsigned integer to the rhs socket. */ /* the values should match. */ /* clean up. */