test/queue/test_queue_pop.cpp
TEST(basics)
{
    allocator* alloc = nullptr;
    queue* q = nullptr;

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

    /* we should be able to create a queue. */
    TEST_ASSERT(STATUS_SUCCESS == queue_create( &q, alloc));

    /* the count for the queue should be 0. */
    TEST_EXPECT(0 == queue_count(q));

    /* create a dummy resource. */
    allocator* r1 = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == malloc_allocator_create(&r1));

    /* get the handle for this resource. */
    resource* r1h = allocator_resource_handle(r1);

    /* append this resource to the queue. */
    TEST_ASSERT(STATUS_SUCCESS == queue_append(q, r1h));

    /* the count for the queue should be 1. */
    TEST_EXPECT(1 == queue_count(q));

    /* create a dummy resource. */
    allocator* r2 = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == malloc_allocator_create(&r2));

    /* get the handle for this resource. */
    resource* r2h = allocator_resource_handle(r2);

    /* append this resource to the queue. */
    TEST_ASSERT(STATUS_SUCCESS == queue_append(q, r2h));

    /* the count for the queue should be 2. */
    TEST_EXPECT(2 == queue_count(q));

    /* create a dummy resource. */
    allocator* r3 = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == malloc_allocator_create(&r3));

    /* get the handle for this resource. */
    resource* r3h = allocator_resource_handle(r3);

    /* append this resource to the queue. */
    TEST_ASSERT(STATUS_SUCCESS == queue_append(q, r3h));

    /* the count for the queue should be 3. */
    TEST_EXPECT(3 == queue_count(q));

    /* popping the first element yields the first resource. */
    resource* r1p = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == queue_pop(q, &r1p));
    TEST_ASSERT(NULL != r1p);

    /* this is the first resource. */
    TEST_EXPECT(r1p == r1h);

    /* the count for the queue should be 2. */
    TEST_EXPECT(2 == queue_count(q));

    /* popping the next element yields the second resource. */
    resource* r2p = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == queue_pop(q, &r2p));
    TEST_ASSERT(NULL != r2p);

    /* this is the second resource. */
    TEST_EXPECT(r2p == r2h);

    /* the count for the queue should be 1. */
    TEST_EXPECT(1 == queue_count(q));

    /* popping the last element yields the third resource. */
    resource* r3p = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == queue_pop(q, &r3p));
    TEST_ASSERT(NULL != r3p);

    /* this is the third resource. */
    TEST_EXPECT(r3p == r3h);

    /* the count for the queue should be 0. */
    TEST_EXPECT(0 == queue_count(q));

    /* we should be able to release the queue instance. */
    TEST_ASSERT(
        STATUS_SUCCESS ==
            resource_release(queue_resource_handle(q)));

    /* clean up. */
    TEST_ASSERT(
        STATUS_SUCCESS == resource_release(allocator_resource_handle(alloc)));
    TEST_ASSERT(STATUS_SUCCESS == resource_release(r1h));
    TEST_ASSERT(STATUS_SUCCESS == resource_release(r2h));
    TEST_ASSERT(STATUS_SUCCESS == resource_release(r3h));
}
/**
 * Verify that we can pop resources off of the head of a queue instance.
 */
Verify that we can pop resources off of the head of a queue instance.
Verify that we can pop resources off of the head of a queue instance .
TEST(basics)
{
    allocator* alloc = nullptr;
    queue* q = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == malloc_allocator_create(&alloc));
    TEST_ASSERT(STATUS_SUCCESS == queue_create( &q, alloc));
    TEST_EXPECT(0 == queue_count(q));
    allocator* r1 = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == malloc_allocator_create(&r1));
    resource* r1h = allocator_resource_handle(r1);
    TEST_ASSERT(STATUS_SUCCESS == queue_append(q, r1h));
    TEST_EXPECT(1 == queue_count(q));
    allocator* r2 = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == malloc_allocator_create(&r2));
    resource* r2h = allocator_resource_handle(r2);
    TEST_ASSERT(STATUS_SUCCESS == queue_append(q, r2h));
    TEST_EXPECT(2 == queue_count(q));
    allocator* r3 = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == malloc_allocator_create(&r3));
    resource* r3h = allocator_resource_handle(r3);
    TEST_ASSERT(STATUS_SUCCESS == queue_append(q, r3h));
    TEST_EXPECT(3 == queue_count(q));
    resource* r1p = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == queue_pop(q, &r1p));
    TEST_ASSERT(NULL != r1p);
    TEST_EXPECT(r1p == r1h);
    TEST_EXPECT(2 == queue_count(q));
    resource* r2p = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == queue_pop(q, &r2p));
    TEST_ASSERT(NULL != r2p);
    TEST_EXPECT(r2p == r2h);
    TEST_EXPECT(1 == queue_count(q));
    resource* r3p = nullptr;
    TEST_ASSERT(STATUS_SUCCESS == queue_pop(q, &r3p));
    TEST_ASSERT(NULL != r3p);
    TEST_EXPECT(r3p == r3h);
    TEST_EXPECT(0 == queue_count(q));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            resource_release(queue_resource_handle(q)));
    TEST_ASSERT(
        STATUS_SUCCESS == resource_release(allocator_resource_handle(alloc)));
    TEST_ASSERT(STATUS_SUCCESS == resource_release(r1h));
    TEST_ASSERT(STATUS_SUCCESS == resource_release(r2h));
    TEST_ASSERT(STATUS_SUCCESS == resource_release(r3h));
}
TEST ( basics ) { allocator * alloc = nullptr ; queue * q = nullptr ; TEST_ASSERT ( STATUS_SUCCESS == malloc_allocator_create ( & alloc ) ) ; TEST_ASSERT ( STATUS_SUCCESS == queue_create ( & q , alloc ) ) ; TEST_EXPECT ( 0 == queue_count ( q ) ) ; allocator * r1 = nullptr ; TEST_ASSERT ( STATUS_SUCCESS == malloc_allocator_create ( & r1 ) ) ; resource * r1h = allocator_resource_handle ( r1 ) ; TEST_ASSERT ( STATUS_SUCCESS == queue_append ( q , r1h ) ) ; TEST_EXPECT ( 1 == queue_count ( q ) ) ; allocator * r2 = nullptr ; TEST_ASSERT ( STATUS_SUCCESS == malloc_allocator_create ( & r2 ) ) ; resource * r2h = allocator_resource_handle ( r2 ) ; TEST_ASSERT ( STATUS_SUCCESS == queue_append ( q , r2h ) ) ; TEST_EXPECT ( 2 == queue_count ( q ) ) ; allocator * r3 = nullptr ; TEST_ASSERT ( STATUS_SUCCESS == malloc_allocator_create ( & r3 ) ) ; resource * r3h = allocator_resource_handle ( r3 ) ; TEST_ASSERT ( STATUS_SUCCESS == queue_append ( q , r3h ) ) ; TEST_EXPECT ( 3 == queue_count ( q ) ) ; resource * r1p = nullptr ; TEST_ASSERT ( STATUS_SUCCESS == queue_pop ( q , & r1p ) ) ; TEST_ASSERT ( NULL != r1p ) ; TEST_EXPECT ( r1p == r1h ) ; TEST_EXPECT ( 2 == queue_count ( q ) ) ; resource * r2p = nullptr ; TEST_ASSERT ( STATUS_SUCCESS == queue_pop ( q , & r2p ) ) ; TEST_ASSERT ( NULL != r2p ) ; TEST_EXPECT ( r2p == r2h ) ; TEST_EXPECT ( 1 == queue_count ( q ) ) ; resource * r3p = nullptr ; TEST_ASSERT ( STATUS_SUCCESS == queue_pop ( q , & r3p ) ) ; TEST_ASSERT ( NULL != r3p ) ; TEST_EXPECT ( r3p == r3h ) ; TEST_EXPECT ( 0 == queue_count ( q ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( queue_resource_handle ( q ) ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( allocator_resource_handle ( alloc ) ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( r1h ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( r2h ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( r3h ) ) ; }
Verify that we can pop resources off of the head of a queue instance.
Verify that we can pop resources off of the head of a queue instance .
/* we should be able to create a malloc allocator. */ /* we should be able to create a queue. */ /* the count for the queue should be 0. */ /* create a dummy resource. */ /* get the handle for this resource. */ /* append this resource to the queue. */ /* the count for the queue should be 1. */ /* create a dummy resource. */ /* get the handle for this resource. */ /* append this resource to the queue. */ /* the count for the queue should be 2. */ /* create a dummy resource. */ /* get the handle for this resource. */ /* append this resource to the queue. */ /* the count for the queue should be 3. */ /* popping the first element yields the first resource. */ /* this is the first resource. */ /* the count for the queue should be 2. */ /* popping the next element yields the second resource. */ /* this is the second resource. */ /* the count for the queue should be 1. */ /* popping the last element yields the third resource. */ /* this is the third resource. */ /* the count for the queue should be 0. */ /* we should be able to release the queue instance. */ /* clean up. */