File: queue_test.c

package info (click to toggle)
cfengine3 3.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,256 kB
  • ctags: 9,613
  • sloc: ansic: 116,129; sh: 12,366; yacc: 1,088; makefile: 1,006; lex: 391; perl: 197; xml: 21; sed: 4
file content (63 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <test.h>

#include <string.h>
#include <queue.c>
#include <queue.h>

static void test_basics(void)
{
    Queue *q = QueueNew(free);

    assert_int_equal(0, QueueCount(q));
    assert_true(QueueIsEmpty(q));


    QueueEnqueue(q, xstrdup("hello"));
    assert_int_equal(1, QueueCount(q));
    assert_false(QueueIsEmpty(q));
    assert_string_equal("hello", QueueHead(q));


    QueueEnqueue(q, xstrdup("world"));
    assert_int_equal(2, QueueCount(q));
    assert_string_equal("hello", QueueHead(q));


    char *head = QueueDequeue(q);
    assert_string_equal("hello", head);
    free(head);


    assert_string_equal("world", QueueHead(q));
    head = QueueDequeue(q);
    assert_string_equal("world", head);
    free(head);


    QueueDestroy(q);
}


static void test_destroy(void)
{
    Queue *q = QueueNew(free);

    QueueEnqueue(q, xstrdup("1"));
    QueueEnqueue(q, xstrdup("2"));
    QueueEnqueue(q, xstrdup("3"));

    assert_int_equal(3, QueueCount(q));

    QueueDestroy(q);
}

int main()
{
    PRINT_TEST_BANNER();
    const UnitTest tests[] =
    {
        unit_test(test_basics),
        unit_test(test_destroy)
    };
    return run_tests(tests);
}