| 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 TEST_CASE(DirectoryCurrent) { | 20 TEST_CASE(DirectoryCurrent) { |
| 21 const char* current = dart::bin::Directory::Current(); | 21 const char* current = dart::bin::Directory::Current(NULL); |
| 22 EXPECT_NOTNULL(current); | 22 EXPECT_NOTNULL(current); |
| 23 } | 23 } |
| 24 | 24 |
| 25 TEST_CASE(DirectoryExists) { | 25 TEST_CASE(DirectoryExists) { |
| 26 const char* current = dart::bin::Directory::Current(); | 26 const char* current = dart::bin::Directory::Current(NULL); |
| 27 EXPECT_NOTNULL(current); | 27 EXPECT_NOTNULL(current); |
| 28 | 28 |
| 29 dart::bin::Directory::ExistsResult r = dart::bin::Directory::Exists(current); | 29 dart::bin::Directory::ExistsResult r = |
| 30 dart::bin::Directory::Exists(NULL, current); |
| 30 EXPECT_EQ(dart::bin::Directory::EXISTS, r); | 31 EXPECT_EQ(dart::bin::Directory::EXISTS, r); |
| 31 } | 32 } |
| 32 | 33 |
| 33 TEST_CASE(DirectorySystemTemp) { | 34 TEST_CASE(DirectorySystemTemp) { |
| 34 const char* system_temp = dart::bin::Directory::SystemTemp(); | 35 const char* system_temp = dart::bin::Directory::SystemTemp(NULL); |
| 35 EXPECT_NOTNULL(system_temp); | 36 EXPECT_NOTNULL(system_temp); |
| 36 } | 37 } |
| 37 | 38 |
| 38 TEST_CASE(DirectorySystemTempExists) { | 39 TEST_CASE(DirectorySystemTempExists) { |
| 39 const char* system_temp = dart::bin::Directory::SystemTemp(); | 40 const char* system_temp = dart::bin::Directory::SystemTemp(NULL); |
| 40 EXPECT_NOTNULL(system_temp); | 41 EXPECT_NOTNULL(system_temp); |
| 41 | 42 |
| 42 dart::bin::Directory::ExistsResult r = | 43 dart::bin::Directory::ExistsResult r = |
| 43 dart::bin::Directory::Exists(system_temp); | 44 dart::bin::Directory::Exists(NULL, system_temp); |
| 44 EXPECT_EQ(dart::bin::Directory::EXISTS, r); | 45 EXPECT_EQ(dart::bin::Directory::EXISTS, r); |
| 45 } | 46 } |
| 46 | 47 |
| 47 TEST_CASE(DirectoryCreateTemp) { | 48 TEST_CASE(DirectoryCreateTemp) { |
| 48 const char* kTempPrefix = "test_prefix"; | 49 const char* kTempPrefix = "test_prefix"; |
| 49 const char* system_temp = dart::bin::Directory::SystemTemp(); | 50 const char* system_temp = dart::bin::Directory::SystemTemp(NULL); |
| 50 EXPECT_NOTNULL(system_temp); | 51 EXPECT_NOTNULL(system_temp); |
| 51 | 52 |
| 52 const char* temp_dir = dart::bin::Directory::CreateTemp(kTempPrefix); | 53 const char* temp_dir = dart::bin::Directory::CreateTemp(NULL, kTempPrefix); |
| 53 EXPECT_NOTNULL(temp_dir); | 54 EXPECT_NOTNULL(temp_dir); |
| 54 | 55 |
| 55 // Make sure temp_dir contains test_prefix. | 56 // Make sure temp_dir contains test_prefix. |
| 56 EXPECT_NOTNULL(strstr(temp_dir, kTempPrefix)); | 57 EXPECT_NOTNULL(strstr(temp_dir, kTempPrefix)); |
| 57 | 58 |
| 58 // Cleanup. | 59 // Cleanup. |
| 59 EXPECT(dart::bin::Directory::Delete(temp_dir, false)); | 60 EXPECT(dart::bin::Directory::Delete(NULL, temp_dir, false)); |
| 60 } | 61 } |
| 61 | 62 |
| 62 TEST_CASE(DirectorySetCurrent) { | 63 TEST_CASE(DirectorySetCurrent) { |
| 63 const char* current = dart::bin::Directory::Current(); | 64 const char* current = dart::bin::Directory::Current(NULL); |
| 64 EXPECT_NOTNULL(current); | 65 EXPECT_NOTNULL(current); |
| 65 | 66 |
| 66 const char* system_temp = dart::bin::Directory::SystemTemp(); | 67 const char* system_temp = dart::bin::Directory::SystemTemp(NULL); |
| 67 EXPECT_NOTNULL(system_temp); | 68 EXPECT_NOTNULL(system_temp); |
| 68 | 69 |
| 69 EXPECT(dart::bin::Directory::SetCurrent(system_temp)); | 70 EXPECT(dart::bin::Directory::SetCurrent(NULL, system_temp)); |
| 70 | 71 |
| 71 const char* new_current = dart::bin::Directory::Current(); | 72 const char* new_current = dart::bin::Directory::Current(NULL); |
| 72 EXPECT_NOTNULL(new_current); | 73 EXPECT_NOTNULL(new_current); |
| 73 | 74 |
| 74 EXPECT_NOTNULL(strstr(new_current, system_temp)); | 75 EXPECT_NOTNULL(strstr(new_current, system_temp)); |
| 75 | 76 |
| 76 EXPECT(dart::bin::Directory::SetCurrent(current)); | 77 EXPECT(dart::bin::Directory::SetCurrent(NULL, current)); |
| 77 } | 78 } |
| 78 | 79 |
| 79 TEST_CASE(DirectoryCreateDelete) { | 80 TEST_CASE(DirectoryCreateDelete) { |
| 80 const char* kTempDirName = "create_delete_test_name"; | 81 const char* kTempDirName = "create_delete_test_name"; |
| 81 | 82 |
| 82 const char* system_temp = dart::bin::Directory::SystemTemp(); | 83 const char* system_temp = dart::bin::Directory::SystemTemp(NULL); |
| 83 EXPECT_NOTNULL(system_temp); | 84 EXPECT_NOTNULL(system_temp); |
| 84 | 85 |
| 85 const intptr_t name_len = | 86 const intptr_t name_len = |
| 86 snprintf(NULL, 0, "%s/%s", system_temp, kTempDirName); | 87 snprintf(NULL, 0, "%s/%s", system_temp, kTempDirName); |
| 87 ASSERT(name_len > 0); | 88 ASSERT(name_len > 0); |
| 88 char* name = new char[name_len + 1]; | 89 char* name = new char[name_len + 1]; |
| 89 snprintf(name, name_len + 1, "%s/%s", system_temp, kTempDirName); | 90 snprintf(name, name_len + 1, "%s/%s", system_temp, kTempDirName); |
| 90 | 91 |
| 91 // Make a directory. | 92 // Make a directory. |
| 92 EXPECT(dart::bin::Directory::Create(name)); | 93 EXPECT(dart::bin::Directory::Create(NULL, name)); |
| 93 | 94 |
| 94 // Make sure it exists. | 95 // Make sure it exists. |
| 95 dart::bin::Directory::ExistsResult r = dart::bin::Directory::Exists(name); | 96 dart::bin::Directory::ExistsResult r = |
| 97 dart::bin::Directory::Exists(NULL, name); |
| 96 EXPECT_EQ(dart::bin::Directory::EXISTS, r); | 98 EXPECT_EQ(dart::bin::Directory::EXISTS, r); |
| 97 | 99 |
| 98 // Cleanup. | 100 // Cleanup. |
| 99 EXPECT(dart::bin::Directory::Delete(name, false)); | 101 EXPECT(dart::bin::Directory::Delete(NULL, name, false)); |
| 100 delete[] name; | 102 delete[] name; |
| 101 } | 103 } |
| 102 | 104 |
| 103 TEST_CASE(DirectoryRename) { | 105 TEST_CASE(DirectoryRename) { |
| 104 const char* kTempDirName = "rename_test_name"; | 106 const char* kTempDirName = "rename_test_name"; |
| 105 | 107 |
| 106 const char* system_temp = dart::bin::Directory::SystemTemp(); | 108 const char* system_temp = dart::bin::Directory::SystemTemp(NULL); |
| 107 EXPECT_NOTNULL(system_temp); | 109 EXPECT_NOTNULL(system_temp); |
| 108 | 110 |
| 109 const intptr_t name_len = | 111 const intptr_t name_len = |
| 110 snprintf(NULL, 0, "%s/%s", system_temp, kTempDirName); | 112 snprintf(NULL, 0, "%s/%s", system_temp, kTempDirName); |
| 111 ASSERT(name_len > 0); | 113 ASSERT(name_len > 0); |
| 112 char* name = new char[name_len + 1]; | 114 char* name = new char[name_len + 1]; |
| 113 snprintf(name, name_len + 1, "%s/%s", system_temp, kTempDirName); | 115 snprintf(name, name_len + 1, "%s/%s", system_temp, kTempDirName); |
| 114 | 116 |
| 115 // Make a directory. | 117 // Make a directory. |
| 116 EXPECT(dart::bin::Directory::Create(name)); | 118 EXPECT(dart::bin::Directory::Create(NULL, name)); |
| 117 | 119 |
| 118 // Make sure it exists. | 120 // Make sure it exists. |
| 119 dart::bin::Directory::ExistsResult r = dart::bin::Directory::Exists(name); | 121 dart::bin::Directory::ExistsResult r = |
| 122 dart::bin::Directory::Exists(NULL, name); |
| 120 EXPECT_EQ(dart::bin::Directory::EXISTS, r); | 123 EXPECT_EQ(dart::bin::Directory::EXISTS, r); |
| 121 | 124 |
| 122 const intptr_t new_name_len = | 125 const intptr_t new_name_len = |
| 123 snprintf(NULL, 0, "%s/%snewname", system_temp, kTempDirName); | 126 snprintf(NULL, 0, "%s/%snewname", system_temp, kTempDirName); |
| 124 ASSERT(new_name_len > 0); | 127 ASSERT(new_name_len > 0); |
| 125 char* new_name = new char[new_name_len + 1]; | 128 char* new_name = new char[new_name_len + 1]; |
| 126 snprintf(new_name, new_name_len + 1, "%s/%snewname", system_temp, | 129 snprintf(new_name, new_name_len + 1, "%s/%snewname", system_temp, |
| 127 kTempDirName); | 130 kTempDirName); |
| 128 | 131 |
| 129 EXPECT(dart::bin::Directory::Rename(name, new_name)); | 132 EXPECT(dart::bin::Directory::Rename(NULL, name, new_name)); |
| 130 | 133 |
| 131 r = dart::bin::Directory::Exists(new_name); | 134 r = dart::bin::Directory::Exists(NULL, new_name); |
| 132 EXPECT_EQ(dart::bin::Directory::EXISTS, r); | 135 EXPECT_EQ(dart::bin::Directory::EXISTS, r); |
| 133 | 136 |
| 134 r = dart::bin::Directory::Exists(name); | 137 r = dart::bin::Directory::Exists(NULL, name); |
| 135 EXPECT_EQ(dart::bin::Directory::DOES_NOT_EXIST, r); | 138 EXPECT_EQ(dart::bin::Directory::DOES_NOT_EXIST, r); |
| 136 | 139 |
| 137 EXPECT(dart::bin::Directory::Delete(new_name, false)); | 140 EXPECT(dart::bin::Directory::Delete(NULL, new_name, false)); |
| 138 delete[] name; | 141 delete[] name; |
| 139 delete[] new_name; | 142 delete[] new_name; |
| 140 } | 143 } |
| 141 | 144 |
| 142 } // namespace dart | 145 } // namespace dart |
| OLD | NEW |