file_utils_unittest.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // 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. #include "base/fuchsia/file_utils.h"
  5. #include "base/files/file_util.h"
  6. #include "base/files/scoped_temp_dir.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace base {
  9. class OpenDirectoryTest : public testing::Test {
  10. protected:
  11. void SetUp() override {
  12. EXPECT_TRUE(temp_dir.CreateUniqueTempDirUnderPath(
  13. base::FilePath(kPersistedDataDirectoryPath)));
  14. }
  15. ScopedTempDir temp_dir;
  16. };
  17. TEST_F(OpenDirectoryTest, Open) {
  18. auto dir = OpenDirectoryHandle(temp_dir.GetPath());
  19. ASSERT_TRUE(dir);
  20. }
  21. // OpenDirectoryHandle() should fail when opening a directory that doesn't
  22. // exist.
  23. TEST_F(OpenDirectoryTest, OpenNonExistent) {
  24. auto dir =
  25. OpenDirectoryHandle(temp_dir.GetPath().AppendASCII("non_existent"));
  26. ASSERT_FALSE(dir);
  27. }
  28. // OpenDirectoryHandle() should open only directories.
  29. TEST_F(OpenDirectoryTest, OpenFile) {
  30. auto file_path = temp_dir.GetPath().AppendASCII("test_file");
  31. ASSERT_TRUE(WriteFile(file_path, "foo"));
  32. auto dir = OpenDirectoryHandle(file_path);
  33. ASSERT_FALSE(dir);
  34. }
  35. } // namespace base