Flutter Engine
The Flutter Engine
directory_test.cc
Go to the documentation of this file.
1// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "bin/directory.h"
6#include "include/dart_api.h"
7#include "platform/assert.h"
8#include "vm/unit_test.h"
9
10namespace dart {
11
12VM_UNIT_TEST_CASE(DirectoryCurrentNoScope) {
13 char* current_dir = dart::bin::Directory::CurrentNoScope();
14 EXPECT_NOTNULL(current_dir);
15 free(current_dir);
16}
17
18TEST_CASE(DirectoryCurrent) {
19 const char* current = dart::bin::Directory::Current(nullptr);
20 EXPECT_NOTNULL(current);
21}
22
23TEST_CASE(DirectoryExists) {
24 const char* current = dart::bin::Directory::Current(nullptr);
25 EXPECT_NOTNULL(current);
26
28 dart::bin::Directory::Exists(nullptr, current);
29 EXPECT_EQ(dart::bin::Directory::EXISTS, r);
30}
31
32TEST_CASE(DirectorySystemTemp) {
33 const char* system_temp = dart::bin::Directory::SystemTemp(nullptr);
34 EXPECT_NOTNULL(system_temp);
35}
36
37TEST_CASE(DirectorySystemTempExists) {
38 const char* system_temp = dart::bin::Directory::SystemTemp(nullptr);
39 EXPECT_NOTNULL(system_temp);
40
42 dart::bin::Directory::Exists(nullptr, system_temp);
43 EXPECT_EQ(dart::bin::Directory::EXISTS, r);
44}
45
46TEST_CASE(DirectoryCreateTemp) {
47 const char* kTempPrefix = "test_prefix";
48 const char* system_temp = dart::bin::Directory::SystemTemp(nullptr);
49 EXPECT_NOTNULL(system_temp);
50
51 const char* temp_dir = dart::bin::Directory::CreateTemp(nullptr, kTempPrefix);
52 EXPECT_NOTNULL(temp_dir);
53
54 // Make sure temp_dir contains test_prefix.
55 EXPECT_NOTNULL(strstr(temp_dir, kTempPrefix));
56
57 // Cleanup.
58 EXPECT(dart::bin::Directory::Delete(nullptr, temp_dir, false));
59}
60
61TEST_CASE(DirectorySetCurrent) {
62 const char* current = dart::bin::Directory::Current(nullptr);
63 EXPECT_NOTNULL(current);
64
65 const char* system_temp = dart::bin::Directory::SystemTemp(nullptr);
66 EXPECT_NOTNULL(system_temp);
67
68 EXPECT(dart::bin::Directory::SetCurrent(nullptr, system_temp));
69
70 const char* new_current = dart::bin::Directory::Current(nullptr);
71 EXPECT_NOTNULL(new_current);
72
73 EXPECT_NOTNULL(strstr(new_current, system_temp));
74
76}
77
78TEST_CASE(DirectoryCreateDelete) {
79 const char* kTempDirName = "create_delete_test_name";
80
81 const char* system_temp = dart::bin::Directory::SystemTemp(nullptr);
82 EXPECT_NOTNULL(system_temp);
83
84 const intptr_t name_len =
85 snprintf(nullptr, 0, "%s/%s", system_temp, kTempDirName);
86 ASSERT(name_len > 0);
87 char* name = new char[name_len + 1];
88 snprintf(name, name_len + 1, "%s/%s", system_temp, kTempDirName);
89
90 // Make a directory.
92
93 // Make sure it exists.
96 EXPECT_EQ(dart::bin::Directory::EXISTS, r);
97
98 // Cleanup.
100 delete[] name;
101}
102
103TEST_CASE(DirectoryRename) {
104 const char* kTempDirName = "rename_test_name";
105
106 const char* system_temp = dart::bin::Directory::SystemTemp(nullptr);
107 EXPECT_NOTNULL(system_temp);
108
109 const intptr_t name_len =
110 snprintf(nullptr, 0, "%s/%s", system_temp, kTempDirName);
111 ASSERT(name_len > 0);
112 char* name = new char[name_len + 1];
113 snprintf(name, name_len + 1, "%s/%s", system_temp, kTempDirName);
114
115 // Make a directory.
117
118 // Make sure it exists.
121 EXPECT_EQ(dart::bin::Directory::EXISTS, r);
122
123 const intptr_t new_name_len =
124 snprintf(nullptr, 0, "%s/%snewname", system_temp, kTempDirName);
125 ASSERT(new_name_len > 0);
126 char* new_name = new char[new_name_len + 1];
127 snprintf(new_name, new_name_len + 1, "%s/%snewname", system_temp,
128 kTempDirName);
129
130 EXPECT(dart::bin::Directory::Rename(nullptr, name, new_name));
131
132 r = dart::bin::Directory::Exists(nullptr, new_name);
133 EXPECT_EQ(dart::bin::Directory::EXISTS, r);
134
137
138 EXPECT(dart::bin::Directory::Delete(nullptr, new_name, false));
139 delete[] name;
140 delete[] new_name;
141}
142
143} // namespace dart
#define EXPECT(type, expectedAlignment, expectedSize)
static bool SetCurrent(Namespace *namespc, const char *path)
Definition: directory.cc:562
static bool Create(Namespace *namespc, const char *path)
static ExistsResult Exists(Namespace *namespc, const char *path)
static char * CurrentNoScope()
static bool Rename(Namespace *namespc, const char *path, const char *new_path)
static bool Delete(Namespace *namespc, const char *path, bool recursive)
static const char * CreateTemp(Namespace *namespc, const char *path)
static const char * Current(Namespace *namespc)
Definition: directory.cc:558
static const char * SystemTemp(Namespace *namespc)
#define ASSERT(E)
Definition: dart_vm.cc:33
const char *const name
TEST_CASE(DirectoryCurrent)
VM_UNIT_TEST_CASE(DirectoryCurrentNoScope)