test/psock/test_psock_from_buffer_read.cpp
/**
 * Reading more data than available results in a success with an adjusted size.
 */
Reading more data than available results in a success with an adjusted size.
Reading more data than available results in a success with an adjusted size .
TEST(overread)
{
    allocator* alloc = nullptr;
    psock* s = nullptr;
    const char* buffer = "TEST";
    size_t buffer_size = strlen(buffer);
    char read_buffer[100];
    size_t read_size;
    TEST_ASSERT(
        STATUS_SUCCESS == malloc_allocator_create(&alloc));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            psock_create_from_buffer(
                &s, alloc, buffer, buffer_size));
    read_size = sizeof(read_buffer);
    TEST_ASSERT(STATUS_SUCCESS == psock_read_raw(s, &read_buffer, &read_size));
    TEST_ASSERT(4U == read_size);
    TEST_EXPECT(0 == memcmp(buffer, read_buffer, 4U));
    read_size = sizeof(read_buffer);
    TEST_ASSERT(
        ERROR_PSOCK_READ_EOF == psock_read_raw(s, &read_buffer, &read_size));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            resource_release(psock_resource_handle(s)));
    TEST_ASSERT(
        STATUS_SUCCESS == resource_release(allocator_resource_handle(alloc)));
}
TEST ( overread ) { allocator * alloc = nullptr ; psock * s = nullptr ; const char * buffer = " " ; size_t buffer_size = strlen ( buffer ) ; char read_buffer [ 100 ] ; size_t read_size ; TEST_ASSERT ( STATUS_SUCCESS == malloc_allocator_create ( & alloc ) ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_create_from_buffer ( & s , alloc , buffer , buffer_size ) ) ; read_size = sizeof ( read_buffer ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_read_raw ( s , & read_buffer , & read_size ) ) ; TEST_ASSERT ( 4U == read_size ) ; TEST_EXPECT ( 0 == memcmp ( buffer , read_buffer , 4U ) ) ; read_size = sizeof ( read_buffer ) ; TEST_ASSERT ( ERROR_PSOCK_READ_EOF == psock_read_raw ( s , & read_buffer , & read_size ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( psock_resource_handle ( s ) ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( allocator_resource_handle ( alloc ) ) ) ; }
Reading more data than available results in a success with an adjusted size.
Reading more data than available results in a success with an adjusted size .
/* we should be able to create a malloc allocator. */ /* we should be able to create a psock from the buffer. */ /* we can read a T. */ /* The last read ends in EOF. */ /* we should be able to release the socket, which in turn will close the lhs
     * descriptor. */ /* clean up. */