]>
git.ipfire.org Git - pakfire.git/blob - tests/libpakfire/jail.c
1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2022 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 #############################################################################*/
21 #include <pakfire/jail.h>
23 #include "../testsuite.h"
25 static const char* cmd
[2] = {
26 "/usr/bin/does-not-exist",
29 static int test_create(const struct test
* t
) {
30 struct pakfire_jail
* jail
= NULL
;
33 ASSERT_SUCCESS(pakfire_jail_create(&jail
, t
->pakfire
, 0));
36 ASSERT_NULL(pakfire_jail_unref(jail
));
38 // Create an interactive jail
39 ASSERT_SUCCESS(pakfire_jail_create(&jail
, t
->pakfire
, PAKFIRE_JAIL_INTERACTIVE
));
42 ASSERT_NULL(pakfire_jail_unref(jail
));
50 static int test_env(const struct test
* t
) {
51 struct pakfire_jail
* jail
= NULL
;
54 ASSERT_SUCCESS(pakfire_jail_create(&jail
, t
->pakfire
, 0));
56 // Check if the default variables are set
57 ASSERT(pakfire_jail_get_env(jail
, "LANG"));
58 ASSERT(pakfire_jail_get_env(jail
, "TERM"));
60 // Fetch a non-existing environment variable
61 ASSERT_NULL(pakfire_jail_get_env(jail
, "VARIABLE"));
64 ASSERT_SUCCESS(pakfire_jail_set_env(jail
, "VARIABLE", "VALUE"));
66 // Read the value back
67 ASSERT_STRING_EQUALS(pakfire_jail_get_env(jail
, "VARIABLE"), "VALUE");
70 ASSERT_NULL(pakfire_jail_unref(jail
));
79 int main(int argc
, char** argv
) {
80 testsuite_add_test(test_create
);
81 testsuite_add_test(test_env
);
83 return testsuite_run();