Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
scoped_temp_dir_unittest.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 "filesystem/scoped_temp_dir.h"
6#include "filesystem/directory.h"
7#include "filesystem/path.h"
8#include "gtest/gtest.h"
9
10namespace filesystem {
11
12TEST(ScopedTempDir, Creation) {
13 ScopedTempDir dir;
14
15 EXPECT_TRUE(IsDirectory(dir.path()));
16}
17
18TEST(ScopedTempDir, Deletion) {
19 std::string path;
20 {
21 ScopedTempDir dir;
22 path = dir.path();
23 }
24
25 EXPECT_FALSE(IsDirectory(path));
26}
27
28TEST(ScopedTempDir, NewTempFile) {
29 ScopedTempDir dir;
30 std::string path;
31 EXPECT_TRUE(dir.NewTempFile(&path));
32 EXPECT_FALSE(path.empty());
33}
34
35TEST(ScopedTempDir, CustomParent) {
36 ScopedTempDir root_dir;
37 std::string parent = root_dir.path() + "/a/b/c";
38 std::string path;
39 {
40 ScopedTempDir dir(parent);
41 path = dir.path();
42 EXPECT_TRUE(IsDirectory(path));
43 EXPECT_EQ(path.substr(0, parent.size()), parent);
44 EXPECT_NE("temp_dir_XXXXXX", GetBaseName(path));
45
46 // Regression test - don't create temp_dir_XXXXXX dir next to the temp one.
47 EXPECT_FALSE(
48 files::IsDirectory(GetDirectoryName(path) + "/temp_dir_XXXXXX"));
49 }
50
51 // Verify that the tmp directory itself was deleted, but not the parent.
52 EXPECT_FALSE(IsDirectory(path));
53 EXPECT_TRUE(IsDirectory(parent));
54}
55
56} // namespace filesystem
#define TEST(S, s, D, expected)
const SkPath & path() const
Definition path.h:117
std::string GetBaseName(const std::string &path)
std::string GetDirectoryName(const std::string &path)
#define EXPECT_TRUE(handle)
Definition unit_test.h:685