~serge-hallyn/ubuntu/natty/lxc/lxc-fix-3bugs

« back to all changes in this revision

Viewing changes to test/tst_list.c

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter, Stéphane Graber, Guido Trotter
  • Date: 2010-01-10 10:40:21 UTC
  • mfrom: (1.1.2 upstream) (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100110104021-z8rj5zw5mlvra08l
Tags: 0.6.4-1
[ Stéphane Graber ]
* Upgrade standards-version to 3.8.3
* Drop the copy of etc/* from rules as "etc" is no longer in the tarball

[ Guido Trotter ]
* New Upstream Version
* Update libcap2-dev dependency to libcap-dev
* Install upstream-built man pages via debian/lxc.manpages
* Drop unneeded docbook-utils build dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <string.h>
3
 
#include <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
 
}