dpkg (1.18.25) stretch; urgency=medium
[dpkg] / lib / dpkg / t / t-pkg-list.c
CommitLineData
1479465f
GJ
1/*
2 * libdpkg - Debian packaging suite library routines
3 * t-pkg-list.c - test pkg-list 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-list.h>
27
28static void
29test_pkg_list_new(void)
30{
31 struct pkg_list *l1, *l2, *l3;
32 struct pkginfo pkg1, pkg2, pkg3;
33
34 l1 = pkg_list_new(&pkg1, NULL);
35 test_alloc(l1);
36 test_pass(l1->next == NULL);
37 test_pass(l1->pkg == &pkg1);
38
39 l2 = pkg_list_new(&pkg2, l1);
40 test_alloc(l2);
41 test_pass(l2->next == l1);
42 test_pass(l2->pkg == &pkg2);
43
44 l3 = pkg_list_new(&pkg3, l2);
45 test_alloc(l3);
46 test_pass(l3->next == l2);
47 test_pass(l3->pkg == &pkg3);
48
49 pkg_list_free(l3);
50}
51
52static void
53test_pkg_list_prepend(void)
54{
55 struct pkg_list *head = NULL, *l1, *l2, *l3;
56 struct pkginfo pkg1, pkg2, pkg3, pkg4;
57
58 pkg_list_prepend(&head, &pkg1);
59 test_alloc(head);
60 test_pass(head->next == NULL);
61 test_pass(head->pkg == &pkg1);
62 l1 = head;
63
64 pkg_list_prepend(&head, &pkg2);
65 test_alloc(head);
66 test_pass(head->next == l1);
67 test_pass(head->pkg == &pkg2);
68 l2 = head;
69
70 pkg_list_prepend(&head, &pkg3);
71 test_alloc(head);
72 test_pass(head->next == l2);
73 test_pass(head->pkg == &pkg3);
74 l3 = head;
75
76 pkg_list_prepend(&head, &pkg4);
77 test_alloc(head);
78 test_pass(head->next == l3);
79 test_pass(head->pkg == &pkg4);
80
81 pkg_list_free(head);
82}
83
84TEST_ENTRY(test)
85{
86 test_plan(14);
87
88 test_pkg_list_new();
89 test_pkg_list_prepend();
90}