/*
* Automated Testing Framework (atf)
*
* Copyright (c) 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <atf-c.h>
#include "fs.h"
#include "test_helpers.h"
#include "user.h"
/* ---------------------------------------------------------------------
* Auxiliary functions.
* --------------------------------------------------------------------- */
static
void
{
int ret;
if (ret == -1)
atf_tc_fail("Could not create helper directory %s", p);
}
static
void
{
int fd;
if (fd == -1)
atf_tc_fail("Could not create helper file %s", p);
}
static
bool
{
}
static
{
int fd;
if (!atf_is_error(err))
return err;
}
/* ---------------------------------------------------------------------
* Test cases for the "atf_fs_path" type.
* --------------------------------------------------------------------- */
{
}
{
struct test {
const char *in;
const char *out;
} tests[] = {
{ ".", ".", },
{ "..", "..", },
{ "/", "/", },
{ "//", "/", }, /* NO_CHECK_STYLE */
{ "///", "/", }, /* NO_CHECK_STYLE */
{ "foo", "foo", },
{ "foo/", "foo", },
{ "/foo", "/foo", },
{ "///foo", "/foo", }, /* NO_CHECK_STYLE */
};
struct test *t;
atf_fs_path_fini(&p);
printf("\n");
}
}
{
}
{
}
{
}
{
struct test {
const char *in;
bool abs;
} tests[] = {
{ "/", true },
{ "////", true }, /* NO_CHECK_STYLE */
{ "////a", true }, /* NO_CHECK_STYLE */
{ "//a//", true }, /* NO_CHECK_STYLE */
{ "a////", false }, /* NO_CHECK_STYLE */
{ "../foo", false },
{ NULL, false },
};
struct test *t;
printf("Result : %s\n",
if (t->abs)
else
atf_fs_path_fini(&p);
printf("\n");
}
}
{
}
{
struct test {
const char *in;
bool root;
} tests[] = {
{ "/", true },
{ "////", true }, /* NO_CHECK_STYLE */
{ "////a", false }, /* NO_CHECK_STYLE */
{ "//a//", false }, /* NO_CHECK_STYLE */
{ "a////", false }, /* NO_CHECK_STYLE */
{ "../foo", false },
{ NULL, false },
};
struct test *t;
printf("Result : %s\n",
if (t->root)
else
ATF_REQUIRE(!atf_fs_path_is_root(&p));
atf_fs_path_fini(&p);
printf("\n");
}
}
{
"function");
}
{
struct test {
const char *in;
const char *branch;
} tests[] = {
{ ".", "." },
{ "foo", "." },
{ "/foo", "/" },
};
struct test *t;
atf_fs_path_fini(&p);
printf("\n");
}
}
{
"function");
}
{
struct test {
const char *in;
const char *leaf;
} tests[] = {
{ ".", "." },
{ "foo", "foo" },
{ "/foo", "foo" },
};
struct test *t;
atf_fs_path_fini(&p);
printf("\n");
}
}
{
"paths");
}
{
struct test {
const char *in;
const char *ap;
const char *out;
} tests[] = {
};
struct test *t;
atf_fs_path_fini(&p);
printf("\n");
}
}
{
"function");
}
{
const char **n;
atf_fs_path_fini(&p);
printf("\n");
}
}
{
}
{
}
/* ---------------------------------------------------------------------
* Test cases for the "atf_fs_stat" type.
* --------------------------------------------------------------------- */
{
"and, indirectly, the constructor");
}
{
atf_fs_path_fini(&p);
atf_fs_path_fini(&p);
}
{
"and, indirectly, the constructor");
}
{
atf_fs_path_fini(&p);
atf_fs_path_fini(&p);
}
{
}
{
create_file("reg", 0);
{ \
atf_fs_stat_fini(&st); \
}
chmod("reg", 0000);
perms(false, false, false, false, false, false, false, false, false);
perms(false, false, false, false, false, false, false, false, true);
perms(false, false, false, false, false, true, false, false, false);
perms(false, false, true, false, false, false, false, false, false);
perms(false, false, false, false, false, false, false, true, false);
perms(false, false, false, false, true, false, false, false, false);
perms(false, true, false, false, false, false, false, false, false);
perms(false, false, false, false, false, false, true, false, false);
perms(false, false, false, true, false, false, false, false, false);
perms(true, false, false, false, false, false, false, false, false);
perms(true, true, false, true, false, false, true, false, false);
perms(true, true, true, true, false, true, true, false, true);
perms(true, true, true, true, true, true, true, true, true);
atf_fs_path_fini(&p);
}
/* ---------------------------------------------------------------------
* Test cases for the free functions.
* --------------------------------------------------------------------- */
{
}
{
bool b;
printf("Checking existence of a directory\n");
ATF_REQUIRE(b);
printf("Checking existence of a file\n");
ATF_REQUIRE(b);
/* XXX: This should probably be a separate test case to let the user
* be aware that some tests were skipped because privileges were not
* correct. */
if (!atf_user_is_root()) {
printf("Checking existence of a file inside a directory without "
"permissions\n");
}
printf("Checking existence of a non-existent file\n");
ATF_REQUIRE(!b);
}
{
}
{
atf_fs_access_x, 0 };
const int *m;
struct tests {
int amode;
int uerror;
int rerror;
} tests[] = {
{ 0000, atf_fs_access_r, EACCES, 0 },
{ 0000, atf_fs_access_w, EACCES, 0 },
{ 0010, atf_fs_access_x, 0, 0 },
{ 0020, atf_fs_access_w, 0, 0 },
{ 0040, atf_fs_access_r, 0, 0 },
{ 0100, atf_fs_access_x, 0, 0 },
{ 0200, atf_fs_access_w, 0, 0 },
{ 0400, atf_fs_access_r, 0, 0 },
{ 0, 0, 0, 0 }
};
struct tests *t;
printf("Non-existent file checks\n");
for (m = &modes[0]; *m != 0; m++) {
err = atf_fs_eaccess(&p, *m);
}
create_file(atf_fs_path_cstring(&p), 0000);
printf("\n");
/* First, existence check. */
/* Now do the specific test case. */
if (atf_is_error(err)) {
else
printf("Error : Non-libc error\n");
} else
printf("Error : None\n");
if (experr == 0) {
} else {
}
}
atf_fs_path_fini(&p);
}
{
}
{
}
{
}
{
ATF_REQUIRE(exists(&p));
RE(atf_fs_rmdir(&p));
ATF_REQUIRE(!exists(&p));
atf_fs_path_fini(&p);
}
{
}
{
ATF_REQUIRE(exists(&p));
err = atf_fs_rmdir(&p);
atf_fs_path_fini(&p);
}
{
}
{
ATF_REQUIRE(exists(&p));
err = atf_fs_rmdir(&p);
if (atf_user_is_root()) {
} else {
}
atf_fs_path_fini(&p);
}
{
"successful execution");
}
{
}
{
"error conditions");
}
{
err = atf_fs_mkdtemp(&p);
atf_fs_path_fini(&p);
}
static
void
{
int old_umask;
}
{
"causing an error due to a too strict umask");
}
{
atf_fs_path_fini(&p);
}
{
"successful execution");
}
{
}
{
"error conditions");
}
{
int fd;
fd = 1234;
atf_fs_path_fini(&p);
}
{
"causing an error due to a too strict umask");
}
{
atf_fs_path_fini(&p);
}
/* ---------------------------------------------------------------------
* Main.
* --------------------------------------------------------------------- */
{
/* Add the tests for the "atf_fs_path" type. */
/* Add the tests for the "atf_fs_stat" type. */
/* Add the tests for the free functions. */
return atf_no_error();
}