1// Copyright 2017 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <errno.h>
6#include <stdio.h>
7#include <string.h>
8#include <sys/stat.h>
9#include <sys/types.h>
10#include <unistd.h>
11#include <lib/fdio/private.h>
12
13#include <unittest/unittest.h>
14
15// These tests poke at some "global" behavior of fdio
16// that are not easily tested through filesystem tests,
17// since they (for example) rely on a global root.
18//
19// For more comprehensive filesystem tests, refer
20// to utest/fs.
21
22bool stat_test(void) {
23    BEGIN_TEST;
24
25    struct stat buf;
26    ASSERT_EQ(stat("/", &buf), 0, "");
27    ASSERT_EQ(stat("//", &buf), 0, "");
28    ASSERT_EQ(stat("///", &buf), 0, "");
29    ASSERT_EQ(stat("/tmp", &buf), 0, "");
30    ASSERT_EQ(stat("//tmp", &buf), 0, "");
31    ASSERT_EQ(stat("./", &buf), 0, "");
32    ASSERT_EQ(stat("./", &buf), 0, "");
33    ASSERT_EQ(stat(".", &buf), 0, "");
34
35    END_TEST;
36}
37
38bool remove_test(void) {
39    BEGIN_TEST;
40
41    ASSERT_EQ(remove("/"), -1, "");
42    ASSERT_EQ(errno, EBUSY, "");
43
44    ASSERT_EQ(rmdir("/"), -1, "");
45    ASSERT_EQ(errno, EBUSY, "");
46
47    END_TEST;
48}
49
50BEGIN_TEST_CASE(fdio_root_test)
51RUN_TEST(stat_test)
52RUN_TEST(remove_test)
53END_TEST_CASE(fdio_root_test)
54