OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "bin/directory.h" | 5 #include "bin/directory.h" |
6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
9 #include "vm/thread.h" | 9 #include "vm/thread.h" |
10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 VM_UNIT_TEST_CASE(DirectoryCurrentNoScope) { | 14 VM_UNIT_TEST_CASE(DirectoryCurrentNoScope) { |
15 char* current_dir = dart::bin::Directory::CurrentNoScope(); | 15 char* current_dir = dart::bin::Directory::CurrentNoScope(); |
16 EXPECT_NOTNULL(current_dir); | 16 EXPECT_NOTNULL(current_dir); |
17 free(current_dir); | 17 free(current_dir); |
18 } | 18 } |
19 | 19 |
20 | |
21 TEST_CASE(DirectoryCurrent) { | 20 TEST_CASE(DirectoryCurrent) { |
22 const char* current = dart::bin::Directory::Current(); | 21 const char* current = dart::bin::Directory::Current(); |
23 EXPECT_NOTNULL(current); | 22 EXPECT_NOTNULL(current); |
24 } | 23 } |
25 | 24 |
26 | |
27 TEST_CASE(DirectoryExists) { | 25 TEST_CASE(DirectoryExists) { |
28 const char* current = dart::bin::Directory::Current(); | 26 const char* current = dart::bin::Directory::Current(); |
29 EXPECT_NOTNULL(current); | 27 EXPECT_NOTNULL(current); |
30 | 28 |
31 dart::bin::Directory::ExistsResult r = dart::bin::Directory::Exists(current); | 29 dart::bin::Directory::ExistsResult r = dart::bin::Directory::Exists(current); |
32 EXPECT_EQ(dart::bin::Directory::EXISTS, r); | 30 EXPECT_EQ(dart::bin::Directory::EXISTS, r); |
33 } | 31 } |
34 | 32 |
35 | |
36 TEST_CASE(DirectorySystemTemp) { | 33 TEST_CASE(DirectorySystemTemp) { |
37 const char* system_temp = dart::bin::Directory::SystemTemp(); | 34 const char* system_temp = dart::bin::Directory::SystemTemp(); |
38 EXPECT_NOTNULL(system_temp); | 35 EXPECT_NOTNULL(system_temp); |
39 } | 36 } |
40 | 37 |
41 | |
42 TEST_CASE(DirectorySystemTempExists) { | 38 TEST_CASE(DirectorySystemTempExists) { |
43 const char* system_temp = dart::bin::Directory::SystemTemp(); | 39 const char* system_temp = dart::bin::Directory::SystemTemp(); |
44 EXPECT_NOTNULL(system_temp); | 40 EXPECT_NOTNULL(system_temp); |
45 | 41 |
46 dart::bin::Directory::ExistsResult r = | 42 dart::bin::Directory::ExistsResult r = |
47 dart::bin::Directory::Exists(system_temp); | 43 dart::bin::Directory::Exists(system_temp); |
48 EXPECT_EQ(dart::bin::Directory::EXISTS, r); | 44 EXPECT_EQ(dart::bin::Directory::EXISTS, r); |
49 } | 45 } |
50 | 46 |
51 | |
52 TEST_CASE(DirectoryCreateTemp) { | 47 TEST_CASE(DirectoryCreateTemp) { |
53 const char* kTempPrefix = "test_prefix"; | 48 const char* kTempPrefix = "test_prefix"; |
54 const char* system_temp = dart::bin::Directory::SystemTemp(); | 49 const char* system_temp = dart::bin::Directory::SystemTemp(); |
55 EXPECT_NOTNULL(system_temp); | 50 EXPECT_NOTNULL(system_temp); |
56 | 51 |
57 const char* temp_dir = dart::bin::Directory::CreateTemp(kTempPrefix); | 52 const char* temp_dir = dart::bin::Directory::CreateTemp(kTempPrefix); |
58 EXPECT_NOTNULL(temp_dir); | 53 EXPECT_NOTNULL(temp_dir); |
59 | 54 |
60 // Make sure temp_dir contains test_prefix. | 55 // Make sure temp_dir contains test_prefix. |
61 EXPECT_NOTNULL(strstr(temp_dir, kTempPrefix)); | 56 EXPECT_NOTNULL(strstr(temp_dir, kTempPrefix)); |
62 | 57 |
63 // Cleanup. | 58 // Cleanup. |
64 EXPECT(dart::bin::Directory::Delete(temp_dir, false)); | 59 EXPECT(dart::bin::Directory::Delete(temp_dir, false)); |
65 } | 60 } |
66 | 61 |
67 | |
68 TEST_CASE(DirectorySetCurrent) { | 62 TEST_CASE(DirectorySetCurrent) { |
69 const char* current = dart::bin::Directory::Current(); | 63 const char* current = dart::bin::Directory::Current(); |
70 EXPECT_NOTNULL(current); | 64 EXPECT_NOTNULL(current); |
71 | 65 |
72 const char* system_temp = dart::bin::Directory::SystemTemp(); | 66 const char* system_temp = dart::bin::Directory::SystemTemp(); |
73 EXPECT_NOTNULL(system_temp); | 67 EXPECT_NOTNULL(system_temp); |
74 | 68 |
75 EXPECT(dart::bin::Directory::SetCurrent(system_temp)); | 69 EXPECT(dart::bin::Directory::SetCurrent(system_temp)); |
76 | 70 |
77 const char* new_current = dart::bin::Directory::Current(); | 71 const char* new_current = dart::bin::Directory::Current(); |
78 EXPECT_NOTNULL(new_current); | 72 EXPECT_NOTNULL(new_current); |
79 | 73 |
80 EXPECT_NOTNULL(strstr(new_current, system_temp)); | 74 EXPECT_NOTNULL(strstr(new_current, system_temp)); |
81 | 75 |
82 EXPECT(dart::bin::Directory::SetCurrent(current)); | 76 EXPECT(dart::bin::Directory::SetCurrent(current)); |
83 } | 77 } |
84 | 78 |
85 | |
86 TEST_CASE(DirectoryCreateDelete) { | 79 TEST_CASE(DirectoryCreateDelete) { |
87 const char* kTempDirName = "create_delete_test_name"; | 80 const char* kTempDirName = "create_delete_test_name"; |
88 | 81 |
89 const char* system_temp = dart::bin::Directory::SystemTemp(); | 82 const char* system_temp = dart::bin::Directory::SystemTemp(); |
90 EXPECT_NOTNULL(system_temp); | 83 EXPECT_NOTNULL(system_temp); |
91 | 84 |
92 const intptr_t name_len = | 85 const intptr_t name_len = |
93 snprintf(NULL, 0, "%s/%s", system_temp, kTempDirName); | 86 snprintf(NULL, 0, "%s/%s", system_temp, kTempDirName); |
94 ASSERT(name_len > 0); | 87 ASSERT(name_len > 0); |
95 char* name = new char[name_len + 1]; | 88 char* name = new char[name_len + 1]; |
96 snprintf(name, name_len + 1, "%s/%s", system_temp, kTempDirName); | 89 snprintf(name, name_len + 1, "%s/%s", system_temp, kTempDirName); |
97 | 90 |
98 // Make a directory. | 91 // Make a directory. |
99 EXPECT(dart::bin::Directory::Create(name)); | 92 EXPECT(dart::bin::Directory::Create(name)); |
100 | 93 |
101 // Make sure it exists. | 94 // Make sure it exists. |
102 dart::bin::Directory::ExistsResult r = dart::bin::Directory::Exists(name); | 95 dart::bin::Directory::ExistsResult r = dart::bin::Directory::Exists(name); |
103 EXPECT_EQ(dart::bin::Directory::EXISTS, r); | 96 EXPECT_EQ(dart::bin::Directory::EXISTS, r); |
104 | 97 |
105 // Cleanup. | 98 // Cleanup. |
106 EXPECT(dart::bin::Directory::Delete(name, false)); | 99 EXPECT(dart::bin::Directory::Delete(name, false)); |
107 delete[] name; | 100 delete[] name; |
108 } | 101 } |
109 | 102 |
110 | |
111 TEST_CASE(DirectoryRename) { | 103 TEST_CASE(DirectoryRename) { |
112 const char* kTempDirName = "rename_test_name"; | 104 const char* kTempDirName = "rename_test_name"; |
113 | 105 |
114 const char* system_temp = dart::bin::Directory::SystemTemp(); | 106 const char* system_temp = dart::bin::Directory::SystemTemp(); |
115 EXPECT_NOTNULL(system_temp); | 107 EXPECT_NOTNULL(system_temp); |
116 | 108 |
117 const intptr_t name_len = | 109 const intptr_t name_len = |
118 snprintf(NULL, 0, "%s/%s", system_temp, kTempDirName); | 110 snprintf(NULL, 0, "%s/%s", system_temp, kTempDirName); |
119 ASSERT(name_len > 0); | 111 ASSERT(name_len > 0); |
120 char* name = new char[name_len + 1]; | 112 char* name = new char[name_len + 1]; |
(...skipping 20 matching lines...) Expand all Loading... |
141 | 133 |
142 r = dart::bin::Directory::Exists(name); | 134 r = dart::bin::Directory::Exists(name); |
143 EXPECT_EQ(dart::bin::Directory::DOES_NOT_EXIST, r); | 135 EXPECT_EQ(dart::bin::Directory::DOES_NOT_EXIST, r); |
144 | 136 |
145 EXPECT(dart::bin::Directory::Delete(new_name, false)); | 137 EXPECT(dart::bin::Directory::Delete(new_name, false)); |
146 delete[] name; | 138 delete[] name; |
147 delete[] new_name; | 139 delete[] new_name; |
148 } | 140 } |
149 | 141 |
150 } // namespace dart | 142 } // namespace dart |
OLD | NEW |