#include "queue.h"
#include <check.h>
+Queue intQ;
+
static void setup()
{
+ QueueInit(&intQ, sizeof(int));
}
static void teardown()
{
+ QueueClear(&intQ);
+}
+
+static void push()
+{
+ int headVal = 1;
+ int tailVal = 1;
+
+ QueuePush(&intQ, &headVal);
+
+ ck_assert_int_eq(*(int *)intQ.head->data, headVal);
+ ck_assert_int_eq(*(int *)intQ.tail->data, tailVal);
+ tailVal++;
+
+ QueuePush(&intQ, &tailVal);
+ ck_assert_int_eq(*(int *)intQ.head->data, headVal);
+ ck_assert_int_eq(*(int *)intQ.tail->data, tailVal);
+ tailVal++;
+
+ QueuePush(&intQ, &tailVal);
+ ck_assert_int_eq(*(int *)intQ.head->data, headVal);
+ ck_assert_int_eq(*(int *)intQ.tail->data, tailVal);
+ tailVal++;
+}
+
+START_TEST(test_queue_push)
+{
+ push();
}
+END_TEST
+
+START_TEST(test_queue_pop)
+{
+ push();
+ int data = 0;
+
+ QueuePop(&intQ, &data);
+ ck_assert_int_eq(data, 1);
+ ck_assert_ptr_nonnull(intQ.head);
+ ck_assert_ptr_nonnull(intQ.tail);
+
+ QueuePop(&intQ, &data);
+ ck_assert_int_eq(data, 2);
+ ck_assert_ptr_nonnull(intQ.head);
+ ck_assert_ptr_nonnull(intQ.tail);
+
+ QueuePop(&intQ, &data);
+ ck_assert_int_eq(data, 3);
+ ck_assert_ptr_null(intQ.head);
+ ck_assert_ptr_null(intQ.tail);
+ ck_assert_int_eq(intQ.memSize, sizeof(int));
+}
+END_TEST
+
+START_TEST(test_queue_init)
+{
+ ck_assert_ptr_null(intQ.tail);
+ ck_assert_ptr_null(intQ.head);
+ ck_assert_int_eq(sizeof(int), intQ.memSize);
+}
+END_TEST
+
+START_TEST(test_queue_clear)
+{
+ push();
+ QueueClear(&intQ);
+ ck_assert_ptr_null(intQ.head);
+ ck_assert_ptr_null(intQ.tail);
+ ck_assert_int_eq(0, intQ.memSize);
+}
+END_TEST
+
+START_TEST(test_queue_peek)
+{
+ int i = 0;
+ push();
+ QueuePeek(&intQ, &i);
+ ck_assert_int_eq(i, 1);
+}
+END_TEST
-START_TEST(test_queue)
+START_TEST(test_queue_get_size)
{
+ ck_assert_int_eq(intQ.memSize, sizeof(int));
}
END_TEST
s = suite_create("queue suite");
tc = tcase_create("queue");
- tcase_add_unchecked_fixture(tc, setup, teardown);
- tcase_add_test(tc, test_queue);
+ tcase_add_checked_fixture(tc, setup, teardown);
+ tcase_add_test(tc, test_queue_init);
+ tcase_add_test(tc, test_queue_push);
+ tcase_add_test(tc, test_queue_pop);
+ tcase_add_test(tc, test_queue_peek);
+ tcase_add_test(tc, test_queue_get_size);
suite_add_tcase(s, tc);
return s;