test/psock/test_psock_from_buffer_write.cpp
/**
 * Verify that we can write 16k bytes to an output buffer.
 */
Verify that we can write 16k bytes to an output buffer.
Verify that we can write 16k bytes to an output buffer .
TEST(sixteen_k)
{
    allocator* alloc = nullptr;
    psock* s = nullptr;
    char* input_buffer;
    size_t input_buffer_size = 16384;
    char* output_buffer = nullptr;
    size_t output_buffer_size = 0;
    TEST_ASSERT(
        STATUS_SUCCESS == malloc_allocator_create(&alloc));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            allocator_allocate(
                alloc, (void**)&input_buffer, input_buffer_size));
    memset(input_buffer, 'a', input_buffer_size);
    TEST_ASSERT(
        STATUS_SUCCESS ==
            psock_create_from_buffer(
                &s, alloc, NULL, 0));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            psock_write_raw_data(s, input_buffer, input_buffer_size));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            psock_from_buffer_get_output_buffer(
                s, alloc, (void**)&output_buffer, &output_buffer_size));
    TEST_ASSERT(nullptr != output_buffer);
    TEST_ASSERT(input_buffer_size == output_buffer_size);
    TEST_EXPECT(
        0 == memcmp(output_buffer, input_buffer, input_buffer_size));
    TEST_ASSERT(STATUS_SUCCESS == allocator_reclaim(alloc, input_buffer));
    TEST_ASSERT(STATUS_SUCCESS == allocator_reclaim(alloc, output_buffer));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            resource_release(psock_resource_handle(s)));
    TEST_ASSERT(
        STATUS_SUCCESS == resource_release(allocator_resource_handle(alloc)));
}
TEST ( sixteen_k ) { allocator * alloc = nullptr ; psock * s = nullptr ; char * input_buffer ; size_t input_buffer_size = 16384 ; char * output_buffer = nullptr ; size_t output_buffer_size = 0 ; TEST_ASSERT ( STATUS_SUCCESS == malloc_allocator_create ( & alloc ) ) ; TEST_ASSERT ( STATUS_SUCCESS == allocator_allocate ( alloc , ( void * * ) & input_buffer , input_buffer_size ) ) ; memset ( input_buffer , ' ' , input_buffer_size ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_create_from_buffer ( & s , alloc , NULL , 0 ) ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_write_raw_data ( s , input_buffer , input_buffer_size ) ) ; TEST_ASSERT ( STATUS_SUCCESS == psock_from_buffer_get_output_buffer ( s , alloc , ( void * * ) & output_buffer , & output_buffer_size ) ) ; TEST_ASSERT ( nullptr != output_buffer ) ; TEST_ASSERT ( input_buffer_size == output_buffer_size ) ; TEST_EXPECT ( 0 == memcmp ( output_buffer , input_buffer , input_buffer_size ) ) ; TEST_ASSERT ( STATUS_SUCCESS == allocator_reclaim ( alloc , input_buffer ) ) ; TEST_ASSERT ( STATUS_SUCCESS == allocator_reclaim ( alloc , output_buffer ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( psock_resource_handle ( s ) ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( allocator_resource_handle ( alloc ) ) ) ; }
Verify that we can write 16k bytes to an output buffer.
Verify that we can write 16k bytes to an output buffer .
/* we should be able to create a malloc allocator. */ /* we should be able to create an input buffer. */ /* set the data in this buffer. */ /* we should be able to create an output buffer psock instance. */ /* we can write the expected buffer. */ /* we can get the output buffer. */ /* clean up the allocated memory for the input buffer. */ /* clean up the allocated memory for the output buffer. */ /* we should be able to release the socket, which in turn will close the lhs
     * descriptor. */ /* clean up. */