aboutsummaryrefslogtreecommitdiff
path: root/tests/test42.c
blob: 4da8f03ddb5d3bd840ff0721daa5e2d790a28f5a (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
#include "utlist.h"

typedef struct el {
    int id;
    struct el *next, *prev;
} el;

static int eltcmp(el *a, el *b)
{
    return a->id - b->id;
}

int main()
{
    int i;
    el *head = NULL;
    el els[10], *e, *tmp, *tmp2;
    for(i=0; i<10; i++) {
        els[i].id=(int)'a'+i;
    }

    /* test LL macros */
    printf("LL macros\n");
    LL_APPEND(head,&els[0]);
    LL_APPEND(head,&els[1]);
    LL_APPEND(head,&els[2]);
    LL_FOREACH(head,e) {
        printf("%c ", e->id);
    }
    printf("\n");
    LL_SEARCH_SCALAR(head, e, id, 'b');
    if (e != NULL) {
        printf("search scalar found b\n");
    }
    LL_SEARCH(head, e, &els[0], eltcmp);
    if (e != NULL) {
        printf("search found %c\n",e->id);
    }
    LL_FOREACH_SAFE(head,e,tmp) {
        LL_DELETE(head,e);
    }

    printf("\n");

    /* test DL macros */
    printf("DL macros\n");
    DL_APPEND(head,&els[0]);
    DL_APPEND(head,&els[1]);
    DL_APPEND(head,&els[2]);
    DL_FOREACH(head,e) {
        printf("%c ", e->id);
    }
    printf("\n");
    DL_SEARCH_SCALAR(head, e, id, 'b');
    if (e != NULL) {
        printf("search scalar found b\n");
    }
    DL_SEARCH(head, e, &els[0], eltcmp);
    if (e != NULL) {
        printf("search found %c\n",e->id);
    }
    DL_FOREACH_SAFE(head,e,tmp) {
        DL_DELETE(head,e);
    }
    printf("\n");

    /* test CDL macros */
    printf("CDL macros\n");
    CDL_PREPEND(head,&els[0]);
    CDL_PREPEND(head,&els[1]);
    CDL_PREPEND(head,&els[2]);
    CDL_FOREACH(head,e) {
        printf("%c ", e->id);
    }
    printf("\n");
    CDL_SEARCH_SCALAR(head, e, id, 'b');
    if (e != NULL) {
        printf("search scalar found b\n");
    }
    CDL_SEARCH(head, e, &els[0], eltcmp);
    if (e != NULL) {
        printf("search found %c\n",e->id);
    }
    CDL_FOREACH_SAFE(head,e,tmp,tmp2) {
        CDL_DELETE(head,e);
    }

    return 0;
}