#include "check_priority_queue.h"
#include "priority_queue.h"
#include <check.h>
+#include <stdio.h>
+
+PrioQueue intQ;
static void setup()
{
+ PrioQueueInit(&intQ, sizeof(int));
}
static void teardown()
{
+ PrioQueueClear(&intQ);
+}
+
+static void push()
+{
+ int val = 1;
+
+ printf("inserting '%d' with prio 3\n", val);
+ PrioQueuePush(&intQ, &val, 3);
+ ck_assert_int_eq(*(int *)intQ.head->data, 1);
+ ck_assert_int_eq(*(int *)intQ.tail->data, 1);
+ val++;
+
+ printf("inserting '%d' with prio 2\n", val);
+ PrioQueuePush(&intQ, &val, 2);
+ ck_assert_int_eq(*(int *)intQ.head->data, 1);
+ ck_assert_int_eq(*(int *)intQ.tail->data, 2);
+ val++;
+
+ printf("inserting '%d' with prio 1\n", val);
+ PrioQueuePush(&intQ, &val, 1);
+ ck_assert_int_eq(*(int *)intQ.head->data, 1);
+ ck_assert_int_eq(*(int *)intQ.tail->data, 3);
+ val++;
+ printf("done\n");
+}
+
+START_TEST(test_priority_queue_push)
+{
+ push();
+}
+END_TEST
+
+START_TEST(test_priority_queue_pop)
+{
+ push();
+ int data = 0;
+
+ PrioQueuePop(&intQ, &data);
+ ck_assert_int_eq(data, 1);
+ ck_assert_ptr_nonnull(intQ.head);
+ ck_assert_ptr_nonnull(intQ.tail);
+
+ PrioQueuePop(&intQ, &data);
+ ck_assert_int_eq(data, 2);
+ ck_assert_ptr_nonnull(intQ.head);
+ ck_assert_ptr_nonnull(intQ.tail);
+
+ PrioQueuePop(&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_priority_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_priority_queue_clear)
+{
+ push();
+ PrioQueueClear(&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_priority_queue_peek)
+{
+ int i = 0;
+ push();
+ PrioQueuePeek(&intQ, &i);
+ ck_assert_int_eq(i, 1);
+}
+END_TEST
-START_TEST(test_priority_queue)
+START_TEST(test_priority_queue_get_size)
{
+ ck_assert_int_eq(intQ.memSize, sizeof(int));
}
END_TEST
Suite *s;
TCase *tc;
- s = suite_create("priority_queue suite");
- tc = tcase_create("priority_queue");
+ s = suite_create("priority queue suite");
+ tc = tcase_create("priority queue");
- tcase_add_unchecked_fixture(tc, setup, teardown);
- tcase_add_test(tc, test_priority_queue);
+ tcase_add_checked_fixture(tc, setup, teardown);
+ tcase_add_test(tc, test_priority_queue_init);
+ tcase_add_test(tc, test_priority_queue_push);
+ tcase_add_test(tc, test_priority_queue_pop);
+ tcase_add_test(tc, test_priority_queue_peek);
+ tcase_add_test(tc, test_priority_queue_get_size);
suite_add_tcase(s, tc);
return s;