chiark / gitweb /
dpkg (1.18.25) stretch; urgency=medium
[dpkg] / lib / dpkg / t / c-trigdeferred.c
1 /*
2  * libdpkg - Debian packaging suite library routines
3  * c-trigdeferred.c - test triggered deferred file parser
4  *
5  * Copyright © 2016 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 <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22 #include <compat.h>
23
24 #include <string.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27
28 #include <dpkg/dpkg-db.h>
29 #include <dpkg/ehandle.h>
30 #include <dpkg/trigdeferred.h>
31
32 static void
33 test_tdm_begin(const char *trig)
34 {
35         printf("<T='%s'", trig);
36 }
37
38 static void
39 test_tdm_package(const char *awname)
40 {
41         printf(" P='%s'", awname);
42 }
43
44 static void
45 test_tdm_end(void)
46 {
47         printf(" E>\n");
48 }
49
50 static const struct trigdefmeths test_tdm = {
51         .trig_begin = test_tdm_begin,
52         .package = test_tdm_package,
53         .trig_end = test_tdm_end,
54 };
55
56 static int
57 test_trigdeferred_parser(const char *admindir)
58 {
59         enum trigdef_update_flags tduf;
60         enum trigdef_update_status tdus;
61
62         dpkg_db_set_dir(admindir);
63
64         trigdef_set_methods(&test_tdm);
65
66         tduf = TDUF_NO_LOCK | TDUF_WRITE_IF_EMPTY | TDUF_WRITE_IF_ENOENT;
67         tdus = trigdef_update_start(tduf);
68         if (tdus < TDUS_OK)
69                 return -tdus + TDUS_OK;
70
71         trigdef_parse();
72
73         trigdef_process_done();
74
75         return 0;
76 }
77
78 int
79 main(int argc, char **argv)
80 {
81         const char *admindir = argv[1];
82         int ret;
83
84         setvbuf(stdout, NULL, _IOLBF, 0);
85
86         push_error_context();
87
88         if (admindir == NULL)
89                 ohshit("missing triggers deferred admindir");
90
91         ret = test_trigdeferred_parser(admindir);
92
93         pop_error_context(ehflag_normaltidy);
94
95         return ret;
96 }