test/psock/test_psock_from_buffer_read.cpp
TEST(basics)
{
    allocator* alloc = nullptr;
    psock* s = nullptr;
    const char* buffer = "TEST";
    size_t buffer_size = strlen(buffer);
    char read_buffer[1];
    size_t read_size;

    /* we should be able to create a malloc allocator. */
    TEST_ASSERT(
        STATUS_SUCCESS == malloc_allocator_create(&alloc));

    /* we should be able to create a psock from the buffer. */
    TEST_ASSERT(
        STATUS_SUCCESS ==
            psock_create_from_buffer(
                &s, alloc, buffer, buffer_size));

    /* we can read a T. */
    read_size = sizeof(read_buffer);
    TEST_ASSERT(STATUS_SUCCESS == psock_read_raw(s, &read_buffer, &read_size));
    TEST_ASSERT(1U == read_size);
    TEST_EXPECT('T' == read_buffer[0]);

    /* we can read an E. */
    read_size = sizeof(read_buffer);
    TEST_ASSERT(STATUS_SUCCESS == psock_read_raw(s, &read_buffer, &read_size));
    TEST_ASSERT(1U == read_size);
    TEST_EXPECT('E' == read_buffer[0]);

    /* we can read an S. */
    read_size = sizeof(read_buffer);
    TEST_ASSERT(STATUS_SUCCESS == psock_read_raw(s, &read_buffer, &read_size));
    TEST_ASSERT(1U == read_size);
    TEST_EXPECT('S' == read_buffer[0]);

    /* we can read a T. */
    read_size = sizeof(read_buffer);
    TEST_ASSERT(STATUS_SUCCESS == psock_read_raw(s, &read_buffer, &read_size));
    TEST_ASSERT(1U == read_size);
    TEST_EXPECT('T' == read_buffer[0]);

    /* The last read ends in EOF. */
    read_size = sizeof(read_buffer);
    TEST_ASSERT(
        ERROR_PSOCK_READ_EOF == psock_read_raw(s, &read_buffer, &read_size));

    /* we should be able to release the socket, which in turn will close the lhs
     * descriptor. */
    TEST_ASSERT(
        STATUS_SUCCESS ==
            resource_release(psock_resource_handle(s)));

    /* clean up. */
    TEST_ASSERT(
        STATUS_SUCCESS == resource_release(allocator_resource_handle(alloc)));
}
/**
 * Verify that we can read data from a psock created from a buffer.
 */
Verify that we can read data from a psock created from a buffer.
Verify that we can read data from a psock created from a buffer .
TEST(basics)
{
    allocator* alloc = nullptr;
    psock* s = nullptr;
    const char* buffer = "TEST";
    size_t buffer_size = strlen(buffer);
    char read_buffer[1];
    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(1U == read_size);
    TEST_EXPECT('T' == read_buffer[0]);
    read_size = sizeof(read_buffer);
    TEST_ASSERT(STATUS_SUCCESS == psock_read_raw(s, &read_buffer, &read_size));
    TEST_ASSERT(1U == read_size);
    TEST_EXPECT('E' == read_buffer[0]);
    read_size = sizeof(read_buffer);
    TEST_ASSERT(STATUS_SUCCESS == psock_read_raw(s, &read_buffer, &read_size));
    TEST_ASSERT(1U == read_size);
    TEST_EXPECT('S' == read_buffer[0]);
    read_size = sizeof(read_buffer);
    TEST_ASSERT(STATUS_SUCCESS == psock_read_raw(s, &read_buffer, &read_size));
    TEST_ASSERT(1U == read_size);
    TEST_EXPECT('T' == read_buffer[0]);
    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 ( basics ) { allocator * alloc = nullptr ; psock * s = nullptr ; const char * buffer = " " ; size_t buffer_size = strlen ( buffer ) ; char read_buffer [ 1 ] ; 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 ( 1U == read_size ) ; TEST_EXPECT ( ' ' == read_buffer [ 0 ] ) ; read_size = sizeof ( read_buffer ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_read_raw ( s , & read_buffer , & read_size ) ) ; TEST_ASSERT ( 1U == read_size ) ; TEST_EXPECT ( ' ' == read_buffer [ 0 ] ) ; read_size = sizeof ( read_buffer ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_read_raw ( s , & read_buffer , & read_size ) ) ; TEST_ASSERT ( 1U == read_size ) ; TEST_EXPECT ( ' ' == read_buffer [ 0 ] ) ; read_size = sizeof ( read_buffer ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_read_raw ( s , & read_buffer , & read_size ) ) ; TEST_ASSERT ( 1U == read_size ) ; TEST_EXPECT ( ' ' == read_buffer [ 0 ] ) ; 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 ) ) ) ; }
Verify that we can read data from a psock created from a buffer.
Verify that we can read data from a psock created from a buffer .
/* 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. */ /* we can read an E. */ /* we can read an S. */ /* 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. */