]>
git.ipfire.org Git - pakfire.git/blob - tests/libpakfire/dependencies.c
1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2021 Pakfire development team #
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. #
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. #
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/>. #
19 #############################################################################*/
25 #include <pakfire/dependencies.h>
26 #include <pakfire/parser.h>
27 #include <pakfire/util.h>
29 #include "../testsuite.h"
31 static const char* relations
[] = {
37 // Packages with a specific version
42 // Packages with version and release
45 "kernel-devel = 3-3.ip3",
47 // Packages with version, release and arch
48 "beep = 1-1.ip3.x86_64",
49 "bash = 2-2.ip3.aarch64",
50 "kernel-devel = 3-3.x86_64",
52 // Packages with a version greater/smaller/greater or equal/smaller or equal than
70 "(foo if bar else baz)",
71 "(foo if bar else baz >= 2)",
72 "(foo >= 1.0 with foo < 2.0)",
73 "(kernel with flavor = desktop)",
74 "(beep or bash or kernel)",
75 "((pkg1 with feature2) or (pkg2 without feature1))",
76 "(foo or (bar and baz))",
78 // Nested rich dependencies
79 "(beep or (bash and kernel))",
80 "(beep or (bash and kernel) or foo)",
85 static const char* invalid_relations
[] = {
86 "beep something-else",
87 "beep >= 1 something else",
95 // Broken nested rich deps
101 static int test_dependencies(const struct test
* t
) {
103 const char* result
= NULL
;
105 // Check some invalid inputs
106 ASSERT_ERRNO(pakfire_str2dep(t
->pakfire
, NULL
) == 0, EINVAL
);
107 ASSERT_ERRNO(pakfire_str2dep(t
->pakfire
, "") == 0, EINVAL
);
109 // Check some valid inputs
110 for (const char** relation
= relations
; *relation
; relation
++) {
111 printf("Parsing '%s'...\n", *relation
);
114 dep
= pakfire_str2dep(t
->pakfire
, *relation
);
116 // Convert it back to string
117 result
= pakfire_dep2str(t
->pakfire
, dep
);
120 // Check if the output matches the input
121 ASSERT_STRING_EQUALS(*relation
, result
);
124 // Check invalid inputs
125 for (const char** relation
= invalid_relations
; *relation
; relation
++) {
126 printf("Parsing '%s'...\n", *relation
);
129 dep
= pakfire_str2dep(t
->pakfire
, *relation
);
131 // The return value must be ID_NULL
132 ASSERT(dep
== ID_NULL
);
141 int main(int argc
, const char* argv
[]) {
142 testsuite_add_test(test_dependencies
);
144 return testsuite_run(argc
, argv
);