test-path-util.c revision bc854dc7cd051e1e5a6ebcca8084b07168051c6c
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Zbigniew Jędrzejewski-Szmek
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include <unistd.h>
#include "path-util.h"
#include "util.h"
#include "macro.h"
#include "strv.h"
static void test_path(void) {
#define test_parent(x, y) { \
_cleanup_free_ char *z = NULL; \
int r = path_get_parent(x, &z); \
}
{
char p2[] = "//aaa/.////ccc";
char p3[] = "/./";
}
}
char *p;
puts(p);
free(p);
puts(p);
free(p);
puts(p);
free(p);
if (!local)
free(p);
}
static void test_prefixes(void) {
unsigned i;
char s[PATH_MAX];
bool b;
i = 0;
PATH_FOREACH_PREFIX_MORE(s, "/a/b/c/d") {
log_error("---%s---", s);
}
i = 1;
PATH_FOREACH_PREFIX(s, "/a/b/c/d") {
log_error("---%s---", s);
}
i = 0;
PATH_FOREACH_PREFIX_MORE(s, "////a////b////c///d///////")
i = 1;
PATH_FOREACH_PREFIX(s, "////a////b////c///d///////")
PATH_FOREACH_PREFIX(s, "////")
assert_not_reached("Wut?");
b = false;
PATH_FOREACH_PREFIX_MORE(s, "////") {
assert_se(!b);
b = true;
}
assert_se(b);
PATH_FOREACH_PREFIX(s, "")
assert_not_reached("wut?");
b = false;
PATH_FOREACH_PREFIX_MORE(s, "") {
assert_se(!b);
b = true;
}
}
static void test_path_join(void) {
_cleanup_free_ char *z = NULL; \
}
}
static void test_fsck_exists(void) {
/* Ensure we use a sane default for PATH. */
unsetenv("PATH");
/* fsck.minix is provided by util-linux and will probably exist. */
}
static void test_make_relative(void) {
char *result;
_cleanup_free_ char *z = NULL; \
}
test("//extra/////slashes///won't////fool///anybody//", "////extra///slashes////are/just///fine///", "../../../are/just/fine");
}
static void test_strv_resolve(void) {
char tmp_dir[] = "/tmp/test-path-util-XXXXXX";
char **d;
STRV_FOREACH(d, search_dirs) {
assert_se(p);
}
}
static void test_path_startswith(void) {
}
test_path();
test_find_binary(argv[0], true);
test_find_binary(argv[0], false);
return 0;
}