blob: 11bb1a250278c78c2585d45ae668bca82f5ace79 [file] [log] [blame]
Sergey Ulanov713b77772019-03-14 22:53:321// Copyright 2019 The Chromium 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 "base/fuchsia/file_utils.h"
6
7#include "base/files/file_util.h"
8#include "base/files/scoped_temp_dir.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace base {
12namespace fuchsia {
13
14class OpenDirectoryTest : public testing::Test {
15 protected:
16 void SetUp() override {
17 EXPECT_TRUE(temp_dir.CreateUniqueTempDirUnderPath(
18 base::FilePath(kPersistedDataDirectoryPath)));
19 }
20
21 ScopedTempDir temp_dir;
22};
23
24TEST_F(OpenDirectoryTest, Open) {
25 auto dir = OpenDirectory(temp_dir.GetPath());
26 ASSERT_TRUE(dir);
27}
28
29// OpenDirectory() should fail when opening a directory that doesn't exist.
30TEST_F(OpenDirectoryTest, OpenNonExistent) {
31 auto dir = OpenDirectory(temp_dir.GetPath().AppendASCII("non_existent"));
32 ASSERT_FALSE(dir);
33}
34
35// OpenDirectory() should open only directories.
36TEST_F(OpenDirectoryTest, OpenFile) {
37 auto file_path = temp_dir.GetPath().AppendASCII("test_file");
38 ASSERT_TRUE(WriteFile(file_path, "foo", 3));
39 auto dir = OpenDirectory(file_path);
40 ASSERT_FALSE(dir);
41}
42
43} // namespace fuchsia
44} // namespace base