Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1025)

Side by Side Diff: runtime/bin/directory_test.cc

Issue 2277883005: Adds some tests for dart::bin::Directory. (Closed)
Patch Set: Add EXPECT around Delete Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/builtin_impl_sources.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/isolate.h"
9 #include "vm/thread.h"
10 #include "vm/unit_test.h"
11
12 namespace dart {
13
14 UNIT_TEST_CASE(DirectoryCurrentNoScope) {
15 char* current_dir = dart::bin::Directory::CurrentNoScope();
16 EXPECT_NOTNULL(current_dir);
17 free(current_dir);
18 }
19
20
21 UNIT_TEST_CASE(DirectoryExists) {
22 char* current_dir = dart::bin::Directory::CurrentNoScope();
23 EXPECT_NOTNULL(current_dir);
24
25 dart::bin::Directory::ExistsResult r =
26 dart::bin::Directory::Exists(current_dir);
27 EXPECT_EQ(dart::bin::Directory::EXISTS, r);
28
29 free(current_dir);
30 }
31
32
33 TEST_CASE(DirectoryCurrent) {
34 const char* current = dart::bin::Directory::Current();
35 EXPECT_NOTNULL(current);
36 }
37
38
39 TEST_CASE(DirectorySystemTemp) {
40 const char* system_temp = dart::bin::Directory::SystemTemp();
41 EXPECT_NOTNULL(system_temp);
42 }
43
44
45 TEST_CASE(DirectoryCreateTemp) {
46 const char* kTempPrefix = "test_prefix";
47 const char* system_temp = dart::bin::Directory::SystemTemp();
48 EXPECT_NOTNULL(system_temp);
49
50 const char* temp_dir = dart::bin::Directory::CreateTemp(kTempPrefix);
51 EXPECT_NOTNULL(temp_dir);
52
53 // Make sure temp_dir contains test_prefix.
54 EXPECT_NOTNULL(strstr(temp_dir, kTempPrefix));
55
56 // Cleanup.
57 EXPECT(dart::bin::Directory::Delete(temp_dir, false));
58 }
59
60
61 TEST_CASE(DirectorySetCurrent) {
62 const char* current = dart::bin::Directory::Current();
63 EXPECT_NOTNULL(current);
64
65 const char* system_temp = dart::bin::Directory::SystemTemp();
66 EXPECT_NOTNULL(system_temp);
67
68 EXPECT(dart::bin::Directory::SetCurrent(system_temp));
69
70 const char* new_current = dart::bin::Directory::Current();
71 EXPECT_NOTNULL(new_current);
72
73 EXPECT_EQ(0, strcmp(system_temp, new_current));
74
75 EXPECT(dart::bin::Directory::SetCurrent(current));
76 }
77
78
79 TEST_CASE(DirectoryCreateDelete) {
80 const char* kTempDirName = "test_name";
81
82 const char* system_temp = dart::bin::Directory::SystemTemp();
83 EXPECT_NOTNULL(system_temp);
84
85 const intptr_t name_len =
86 snprintf(NULL, 0, "%s/%s", system_temp, kTempDirName);
87 ASSERT(name_len > 0);
88 char* name = new char[name_len + 1];
89 snprintf(name, name_len + 1, "%s/%s", system_temp, kTempDirName);
90
91 // Make a directory.
92 EXPECT(dart::bin::Directory::Create(name));
93
94 // Make sure it exists.
95 dart::bin::Directory::ExistsResult r = dart::bin::Directory::Exists(name);
96 EXPECT_EQ(dart::bin::Directory::EXISTS, r);
97
98 // Cleanup.
99 EXPECT(dart::bin::Directory::Delete(name, false));
100 delete[] name;
101 }
102
103
104 TEST_CASE(DirectoryRename) {
105 const char* kTempDirName = "test_name";
106
107 const char* system_temp = dart::bin::Directory::SystemTemp();
108 EXPECT_NOTNULL(system_temp);
109
110 const intptr_t name_len =
111 snprintf(NULL, 0, "%s/%s", system_temp, kTempDirName);
112 ASSERT(name_len > 0);
113 char* name = new char[name_len + 1];
114 snprintf(name, name_len + 1, "%s/%s", system_temp, kTempDirName);
115
116 // Make a directory.
117 EXPECT(dart::bin::Directory::Create(name));
118
119 // Make sure it exists.
120 dart::bin::Directory::ExistsResult r = dart::bin::Directory::Exists(name);
121 EXPECT_EQ(dart::bin::Directory::EXISTS, r);
122
123 const intptr_t new_name_len =
124 snprintf(NULL, 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",
128 system_temp, kTempDirName);
129
130 EXPECT(dart::bin::Directory::Rename(name, new_name));
131
132 r = dart::bin::Directory::Exists(new_name);
133 EXPECT_EQ(dart::bin::Directory::EXISTS, r);
134
135 r = dart::bin::Directory::Exists(name);
136 EXPECT_EQ(dart::bin::Directory::DOES_NOT_EXIST, r);
137
138 EXPECT(dart::bin::Directory::Delete(new_name, false));
139 delete[] name;
140 delete[] new_name;
141 }
142
143 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/builtin_impl_sources.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698