88371a2f74488f95ae127e37033bcec1d5b964db
[project/opkg-lede.git] / tests / opkg_active_list_test.c
1 /* opkg_active_list.c - the opkg package management system
2
3 Tick Chen <tick@openmoko.com>
4
5 Copyright (C) 2008 Openmoko
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16 */
17
18
19 #include <stdlib.h>
20 #include <libopkg/active_list.h>
21 #include <active_list.h>
22 #include <stdio.h>
23
24 struct active_test {
25 char *str;
26 struct active_list list;
27 };
28
29 struct active_test *active_test_new(char *str) {
30 struct active_test *ans = (struct active_test *)calloc(1, sizeof(struct active_test));
31 ans->str = str;
32 active_list_init(&ans->list);
33 return ans;
34 }
35 void active_test_add(struct active_list *head, struct active_test *node) {
36 active_list_add(head, &node->list);
37 }
38
39 void active_test_add_depend(struct active_test *A, struct active_test *B) {
40 active_list_add_depend(&A->list, &B->list);
41 }
42
43 /*
44 .--A---B----C----D-----E----F
45 | |__k---L
46 | |_ N
47 |__ G ---H ---I---J
48 |_M |_O
49
50 Then the sequence will be
51 G M H I O J A B K N L C D E F
52 */
53 void make_list(struct active_list *head) {
54 struct active_test *A = active_test_new("A");
55 struct active_test *B = active_test_new("B");
56 struct active_test *C = active_test_new("C");
57 struct active_test *D = active_test_new("D");
58 struct active_test *E = active_test_new("E");
59 struct active_test *F = active_test_new("F");
60 struct active_test *G = active_test_new("G");
61 struct active_test *H = active_test_new("H");
62 struct active_test *I = active_test_new("I");
63 struct active_test *J = active_test_new("J");
64 struct active_test *K = active_test_new("K");
65 struct active_test *L = active_test_new("L");
66 struct active_test *M = active_test_new("M");
67 struct active_test *N = active_test_new("N");
68 struct active_test *O = active_test_new("O");
69
70 active_test_add(head, A);
71 active_test_add(head, B);
72 active_test_add(head, C);
73 active_test_add(head, D);
74 active_test_add(head, E);
75 active_test_add(head, F);
76 active_test_add(head, G);
77 active_test_add(head, H);
78 active_test_add(head, I);
79 active_test_add(head, J);
80 active_test_add(head, K);
81 active_test_add(head, L);
82 active_test_add(head, M);
83 active_test_add(head, N);
84 active_test_add(head, O);
85 active_test_add_depend(H, M);
86 active_test_add_depend(A, G);
87 active_test_add_depend(A, H);
88 active_test_add_depend(A, I);
89 active_test_add_depend(A, J);
90 active_test_add_depend(J, O);
91 active_test_add_depend(C, K);
92 active_test_add_depend(C, L);
93 active_test_add_depend(L, N);
94 }
95
96 int main (void) {
97 struct active_list head;
98 struct active_list *ptr;
99 struct active_test *test;
100 active_list_init(&head);
101 make_list(&head);
102
103 for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) {
104 test = list_entry(ptr, struct active_test, list);
105 printf ("%s ",test->str);
106 }
107 printf("\n");
108 for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) {
109 test = list_entry(ptr, struct active_test, list);
110 printf ("%s ",test->str);
111 }
112 printf("\n");
113 for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) {
114 test = list_entry(ptr, struct active_test, list);
115 printf ("%s ",test->str);
116 }
117 printf("\n");
118
119
120 }