Commit | Line | Data |
---|---|---|
1479465f GJ |
1 | /* |
2 | * libdpkg - Debian packaging suite library routines | |
3 | * t-pkg-queue.c - test pkg-queue implementation | |
4 | * | |
5 | * Copyright © 2010,2012 Guillem Jover <guillem@debian.org> | |
6 | * | |
7 | * This is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
19 | */ | |
20 | ||
21 | #include <config.h> | |
22 | #include <compat.h> | |
23 | ||
24 | #include <dpkg/test.h> | |
25 | #include <dpkg/dpkg-db.h> | |
26 | #include <dpkg/pkg-queue.h> | |
27 | ||
28 | static void | |
29 | test_pkg_queue_init(void) | |
30 | { | |
31 | struct pkg_queue q = PKG_QUEUE_INIT; | |
32 | struct pkg_list l; | |
33 | ||
34 | test_pass(q.length == 0); | |
35 | test_pass(q.head == NULL); | |
36 | test_pass(q.tail == NULL); | |
37 | ||
38 | test_pass(pkg_queue_is_empty(&q)); | |
39 | ||
40 | q = (struct pkg_queue){ .length = 10, .head = &l, .tail = &l }; | |
41 | ||
42 | pkg_queue_init(&q); | |
43 | test_pass(q.length == 0); | |
44 | test_pass(q.head == NULL); | |
45 | test_pass(q.tail == NULL); | |
46 | ||
47 | test_pass(pkg_queue_is_empty(&q)); | |
48 | } | |
49 | ||
50 | static void | |
51 | test_pkg_queue_push_pop(void) | |
52 | { | |
53 | struct pkg_queue q = PKG_QUEUE_INIT; | |
54 | struct pkg_list *l1, *l2, *l3; | |
55 | struct pkginfo *pkgp, pkg1, pkg2, pkg3; | |
56 | ||
57 | test_pass(pkg_queue_is_empty(&q)); | |
58 | ||
59 | /* Test push operations. */ | |
60 | ||
61 | l1 = pkg_queue_push(&q, &pkg1); | |
62 | test_pass(l1 != NULL); | |
63 | test_pass(q.head == l1); | |
64 | test_pass(q.tail == l1); | |
65 | test_pass(q.length == 1); | |
66 | ||
67 | l2 = pkg_queue_push(&q, &pkg2); | |
68 | test_pass(l2 != NULL); | |
69 | test_pass(q.head == l1); | |
70 | test_pass(q.tail == l2); | |
71 | test_pass(q.length == 2); | |
72 | ||
73 | l3 = pkg_queue_push(&q, &pkg3); | |
74 | test_pass(l3 != NULL); | |
75 | test_pass(q.head == l1); | |
76 | test_pass(q.tail == l3); | |
77 | test_pass(q.length == 3); | |
78 | ||
79 | /* Test pop operations. */ | |
80 | ||
81 | pkgp = pkg_queue_pop(&q); | |
82 | test_pass(pkgp == &pkg1); | |
83 | test_pass(q.head == l2); | |
84 | test_pass(q.tail == l3); | |
85 | test_pass(q.length == 2); | |
86 | ||
87 | pkgp = pkg_queue_pop(&q); | |
88 | test_pass(pkgp == &pkg2); | |
89 | test_pass(q.head == l3); | |
90 | test_pass(q.tail == l3); | |
91 | test_pass(q.length == 1); | |
92 | ||
93 | pkgp = pkg_queue_pop(&q); | |
94 | test_pass(pkgp == &pkg3); | |
95 | test_pass(q.head == NULL); | |
96 | test_pass(q.tail == NULL); | |
97 | test_pass(q.length == 0); | |
98 | ||
99 | test_pass(pkg_queue_is_empty(&q)); | |
100 | ||
101 | pkgp = pkg_queue_pop(&q); | |
102 | test_pass(pkgp == NULL); | |
103 | test_pass(q.head == NULL); | |
104 | test_pass(q.tail == NULL); | |
105 | test_pass(q.length == 0); | |
106 | ||
107 | pkg_queue_destroy(&q); | |
108 | } | |
109 | ||
110 | TEST_ENTRY(test) | |
111 | { | |
112 | test_plan(38); | |
113 | ||
114 | test_pkg_queue_init(); | |
115 | test_pkg_queue_push_pop(); | |
116 | } |