]> git.ipfire.org Git - pakfire.git/blob - tests/libpakfire/dependencies.c
test: Add simple dependency pasing tests
[pakfire.git] / tests / libpakfire / dependencies.c
1 /*#############################################################################
2 # #
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2021 Pakfire development team #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 #############################################################################*/
20
21 #include <errno.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include <pakfire/parser.h>
26 #include <pakfire/util.h>
27
28 #include "../testsuite.h"
29
30 static const char* relations[] = {
31 // Simple packages
32 "beep",
33 "bash",
34 "kernel-devel",
35
36 // Packages with a specific version
37 "beep = 1",
38 "bash = 2",
39 "kernel-devel = 3",
40
41 // Packages with version and release
42 "beep = 1-1.ip3",
43 "bash = 2-2.ip3",
44 "kernel-devel = 3-3.ip3",
45
46 // Packages with version, release and arch
47 "beep = 1-1.ip3.x86_64",
48 "bash = 2-2.ip3.aarch64",
49 "kernel-devel = 3-3.x86_64",
50
51 // Packages with a version greater/smaller/greater or equal/smaller or equal than
52 "beep > 1",
53 "bash > 2",
54 "kernel-devel > 3",
55 "beep < 1",
56 "bash < 2",
57 "kernel-devel < 3",
58 "beep >= 1",
59 "bash >= 2",
60 "kernel-devel >= 3",
61 "beep >= 1",
62 "bash >= 2",
63 "kernel-devel >= 3",
64
65 // Namespaces
66 "pakfire(test)",
67
68 NULL,
69 };
70
71 static int test_dependencies(const struct test* t) {
72 Id dep = 0;
73 const char* result = NULL;
74
75 for (const char** relation = relations; *relation; relation++) {
76 printf("Parsing '%s'...\n", *relation);
77
78 // Parse relation
79 dep = pakfire_str2dep(t->pakfire, *relation);
80
81 // Convert it back to string
82 result = pakfire_dep2str(t->pakfire, dep);
83 ASSERT(result);
84
85 // Check if the output matches the input
86 ASSERT_STRING_EQUALS(*relation, result);
87 }
88
89 return EXIT_SUCCESS;
90
91 FAIL:
92 return EXIT_FAILURE;
93 }
94
95 int main(int argc, char** argv) {
96 testsuite_add_test(test_dependencies);
97
98 return testsuite_run();
99 }