~ubuntu-branches/ubuntu/quantal/lxc/quantal-201205292108

« back to all changes in this revision

Viewing changes to test/tst_list.c

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2009-04-29 17:49:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090429174913-jvahs1ykizqtodje
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <string.h>
 
3
#include <lxc/lxc_list.h>
 
4
 
 
5
int main(int argc, char *argv[])
 
6
{
 
7
        struct lxc_list *iterator;
 
8
        struct lxc_list head = lxc_init_list(&head);
 
9
        struct lxc_list l1 = lxc_init_list(&l1);
 
10
        struct lxc_list l2 = lxc_init_list(&l2);
 
11
        struct lxc_list l3 = lxc_init_list(&l3);
 
12
        struct lxc_list l4 = lxc_init_list(&l4);
 
13
 
 
14
        struct dummy {
 
15
                int a;
 
16
        };
 
17
        
 
18
        struct dummy *elem;
 
19
        struct dummy d1 = { .a = 1 };
 
20
        struct dummy d2 = { .a = 2 };
 
21
        struct dummy d3 = { .a = 3 };
 
22
        struct dummy d4 = { .a = 4 };
 
23
 
 
24
        if (!lxc_list_empty(&head)) {
 
25
                fprintf(stderr, "expected empty list\n");
 
26
                return -1;
 
27
        }
 
28
 
 
29
        l1.elem = &d1;
 
30
        l2.elem = &d2;
 
31
        l3.elem = &d3;
 
32
        l4.elem = &d4;
 
33
 
 
34
        lxc_list_add(&head, &l1);
 
35
        lxc_list_add(&head, &l2);
 
36
        lxc_list_add(&head, &l3);
 
37
        lxc_list_add(&head, &l4);
 
38
 
 
39
        lxc_list_for_each(iterator, &head) {
 
40
                elem = iterator->elem;
 
41
                printf("elem has %d\n", elem->a);
 
42
        }
 
43
 
 
44
        lxc_list_del(&l3);
 
45
 
 
46
        lxc_list_for_each(iterator, &head) {
 
47
                elem = iterator->elem;
 
48
                printf("elem has %d\n", elem->a);
 
49
        }
 
50
        
 
51
        lxc_list_del(&l1);
 
52
        lxc_list_del(&l2);
 
53
        lxc_list_del(&l4);
 
54
 
 
55
        if (!lxc_list_empty(&head)) {
 
56
                fprintf(stderr, "expected empty list\n");
 
57
                return -1;
 
58
        }
 
59
 
 
60
        lxc_list_for_each(iterator, &head) {
 
61
                fprintf(stderr, "should not loop\n");
 
62
                return -1;
 
63
        }
 
64
 
 
65
        return 0;
 
66
}