| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "mojo/file_utils/file_util.h" | 8 #include "mojo/file_utils/file_util.h" |
| 9 #include "mojo/file_utils/tests/file_util_test_base.h" | |
| 10 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
| 11 #include "mojo/public/cpp/application/application_test_base.h" | 10 #include "mojo/public/cpp/application/application_test_base.h" |
| 12 #include "mojo/public/cpp/utility/run_loop.h" | 11 #include "mojo/public/cpp/utility/run_loop.h" |
| 13 #include "mojo/services/files/interfaces/directory.mojom.h" | 12 #include "mojo/services/files/interfaces/directory.mojom.h" |
| 14 #include "mojo/services/files/interfaces/file.mojom.h" | 13 #include "mojo/services/files/interfaces/file.mojom.h" |
| 15 #include "mojo/services/files/interfaces/files.mojom.h" | 14 #include "mojo/services/files/interfaces/files.mojom.h" |
| 16 | 15 |
| 17 namespace file_utils { | 16 namespace file_utils { |
| 18 namespace test { | 17 namespace test { |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 using FileUtilTest = file_utils::test::FileUtilTestBase; | 20 using FileUtilTest = mojo::test::ApplicationTestBase; |
| 22 | 21 |
| 23 // TODO(smklein): Stuff copied from mojo/services/files/c/lib/template_util.h | 22 // TODO(smklein): Stuff copied from mojo/services/files/c/lib/template_util.h |
| 24 typedef char YesType; | 23 typedef char YesType; |
| 25 | 24 |
| 26 struct NoType { | 25 struct NoType { |
| 27 YesType dummy[2]; | 26 YesType dummy[2]; |
| 28 }; | 27 }; |
| 29 | 28 |
| 30 template <typename T> | 29 template <typename T> |
| 31 struct IsMoveOnlyType { | 30 struct IsMoveOnlyType { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 127 |
| 129 // Close the FilePtr |file| and verify that no error occurs. | 128 // Close the FilePtr |file| and verify that no error occurs. |
| 130 void CloseFileHelper(mojo::files::FilePtr* file) { | 129 void CloseFileHelper(mojo::files::FilePtr* file) { |
| 131 mojo::files::Error error = mojo::files::Error::INTERNAL; | 130 mojo::files::Error error = mojo::files::Error::INTERNAL; |
| 132 (*file)->Close(Capture(&error)); | 131 (*file)->Close(Capture(&error)); |
| 133 ASSERT_TRUE(file->WaitForIncomingResponse()); | 132 ASSERT_TRUE(file->WaitForIncomingResponse()); |
| 134 EXPECT_EQ(mojo::files::Error::OK, error); | 133 EXPECT_EQ(mojo::files::Error::OK, error); |
| 135 } | 134 } |
| 136 | 135 |
| 137 TEST_F(FileUtilTest, BasicCreateTemporaryFile) { | 136 TEST_F(FileUtilTest, BasicCreateTemporaryFile) { |
| 137 mojo::files::FilesPtr files; |
| 138 application_impl()->ConnectToService("mojo:files", &files); |
| 139 |
| 138 mojo::files::Error error = mojo::files::Error::INTERNAL; | 140 mojo::files::Error error = mojo::files::Error::INTERNAL; |
| 139 mojo::files::DirectoryPtr directory; | 141 mojo::files::DirectoryPtr directory; |
| 140 files()->OpenFileSystem(nullptr, mojo::GetProxy(&directory), Capture(&error)); | 142 files->OpenFileSystem(nullptr, mojo::GetProxy(&directory), Capture(&error)); |
| 141 | 143 |
| 142 ASSERT_TRUE(files().WaitForIncomingResponse()); | 144 ASSERT_TRUE(files.WaitForIncomingResponse()); |
| 143 EXPECT_EQ(mojo::files::Error::OK, error); | 145 EXPECT_EQ(mojo::files::Error::OK, error); |
| 144 | 146 |
| 145 std::string filename1, filename2, filename3; | 147 std::string filename1, filename2, filename3; |
| 146 mojo::files::FilePtr file1, file2, file3; | 148 mojo::files::FilePtr file1, file2, file3; |
| 147 file1 = CreateTemporaryFileInDir(&directory, &filename1); | 149 file1 = CreateTemporaryFileInDir(&directory, &filename1); |
| 148 ASSERT_TRUE(file1); | 150 ASSERT_TRUE(file1); |
| 149 file2 = CreateTemporaryFileInDir(&directory, &filename2); | 151 file2 = CreateTemporaryFileInDir(&directory, &filename2); |
| 150 ASSERT_TRUE(file2); | 152 ASSERT_TRUE(file2); |
| 151 file3 = CreateTemporaryFileInDir(&directory, &filename3); | 153 file3 = CreateTemporaryFileInDir(&directory, &filename3); |
| 152 ASSERT_TRUE(file3); | 154 ASSERT_TRUE(file3); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 190 |
| 189 // Test that the files can be closed once more. | 191 // Test that the files can be closed once more. |
| 190 CloseFileHelper(&file1); | 192 CloseFileHelper(&file1); |
| 191 CloseFileHelper(&file2); | 193 CloseFileHelper(&file2); |
| 192 CloseFileHelper(&file3); | 194 CloseFileHelper(&file3); |
| 193 } | 195 } |
| 194 | 196 |
| 195 } // namespace | 197 } // namespace |
| 196 } // namespace test | 198 } // namespace test |
| 197 } // namespace file_utils | 199 } // namespace file_utils |
| OLD | NEW |