OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/edk/system/raw_channel.h" | 5 #include "mojo/edk/system/raw_channel.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/files/scoped_file.h" | |
16 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
17 #include "base/location.h" | 16 #include "base/location.h" |
18 #include "base/logging.h" | 17 #include "base/logging.h" |
19 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
20 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
21 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
22 #include "base/threading/simple_thread.h" | 21 #include "base/threading/simple_thread.h" |
23 #include "build/build_config.h" // TODO(vtl): Remove this. | 22 #include "build/build_config.h" // TODO(vtl): Remove this. |
24 #include "mojo/edk/embedder/platform_channel_pair.h" | 23 #include "mojo/edk/embedder/platform_channel_pair.h" |
25 #include "mojo/edk/embedder/platform_handle.h" | 24 #include "mojo/edk/embedder/platform_handle.h" |
26 #include "mojo/edk/embedder/scoped_platform_handle.h" | 25 #include "mojo/edk/embedder/scoped_platform_handle.h" |
27 #include "mojo/edk/system/message_in_transit.h" | 26 #include "mojo/edk/system/message_in_transit.h" |
28 #include "mojo/edk/system/mutex.h" | 27 #include "mojo/edk/system/mutex.h" |
29 #include "mojo/edk/system/test_utils.h" | 28 #include "mojo/edk/system/test_utils.h" |
30 #include "mojo/edk/system/transport_data.h" | 29 #include "mojo/edk/system/transport_data.h" |
31 #include "mojo/edk/test/test_io_thread.h" | 30 #include "mojo/edk/test/test_io_thread.h" |
32 #include "mojo/edk/test/test_utils.h" | 31 #include "mojo/edk/test/test_utils.h" |
| 32 #include "mojo/edk/util/scoped_file.h" |
33 #include "mojo/public/cpp/system/macros.h" | 33 #include "mojo/public/cpp/system/macros.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
35 | 35 |
36 namespace mojo { | 36 namespace mojo { |
37 namespace system { | 37 namespace system { |
38 namespace { | 38 namespace { |
39 | 39 |
40 scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) { | 40 scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) { |
41 std::vector<unsigned char> bytes(num_bytes, 0); | 41 std::vector<unsigned char> bytes(num_bytes, 0); |
42 for (size_t i = 0; i < num_bytes; i++) | 42 for (size_t i = 0; i < num_bytes; i++) |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 ASSERT_EQ(2u, platform_handles->size()); | 756 ASSERT_EQ(2u, platform_handles->size()); |
757 embedder::ScopedPlatformHandle h1(platform_handles->at(0)); | 757 embedder::ScopedPlatformHandle h1(platform_handles->at(0)); |
758 EXPECT_TRUE(h1.is_valid()); | 758 EXPECT_TRUE(h1.is_valid()); |
759 embedder::ScopedPlatformHandle h2(platform_handles->at(1)); | 759 embedder::ScopedPlatformHandle h2(platform_handles->at(1)); |
760 EXPECT_TRUE(h2.is_valid()); | 760 EXPECT_TRUE(h2.is_valid()); |
761 platform_handles->clear(); | 761 platform_handles->clear(); |
762 | 762 |
763 { | 763 { |
764 char buffer[100] = {}; | 764 char buffer[100] = {}; |
765 | 765 |
766 base::ScopedFILE fp(mojo::test::FILEFromPlatformHandle(h1.Pass(), "rb")); | 766 util::ScopedFILE fp(mojo::test::FILEFromPlatformHandle(h1.Pass(), "rb")); |
767 EXPECT_TRUE(fp); | 767 EXPECT_TRUE(fp); |
768 rewind(fp.get()); | 768 rewind(fp.get()); |
769 EXPECT_EQ(1u, fread(buffer, 1, sizeof(buffer), fp.get())); | 769 EXPECT_EQ(1u, fread(buffer, 1, sizeof(buffer), fp.get())); |
770 EXPECT_EQ('1', buffer[0]); | 770 EXPECT_EQ('1', buffer[0]); |
771 } | 771 } |
772 | 772 |
773 { | 773 { |
774 char buffer[100] = {}; | 774 char buffer[100] = {}; |
775 base::ScopedFILE fp(mojo::test::FILEFromPlatformHandle(h2.Pass(), "rb")); | 775 util::ScopedFILE fp(mojo::test::FILEFromPlatformHandle(h2.Pass(), "rb")); |
776 EXPECT_TRUE(fp); | 776 EXPECT_TRUE(fp); |
777 rewind(fp.get()); | 777 rewind(fp.get()); |
778 EXPECT_EQ(1u, fread(buffer, 1, sizeof(buffer), fp.get())); | 778 EXPECT_EQ(1u, fread(buffer, 1, sizeof(buffer), fp.get())); |
779 EXPECT_EQ('2', buffer[0]); | 779 EXPECT_EQ('2', buffer[0]); |
780 } | 780 } |
781 | 781 |
782 done_event_.Signal(); | 782 done_event_.Signal(); |
783 } | 783 } |
784 void OnError(Error error) override { | 784 void OnError(Error error) override { |
785 // We'll get a read (shutdown) error when the connection is closed. | 785 // We'll get a read (shutdown) error when the connection is closed. |
(...skipping 24 matching lines...) Expand all Loading... |
810 base::Bind(&InitOnIOThread, rc_write.get(), | 810 base::Bind(&InitOnIOThread, rc_write.get(), |
811 base::Unretained(&write_delegate))); | 811 base::Unretained(&write_delegate))); |
812 | 812 |
813 ReadPlatformHandlesCheckerRawChannelDelegate read_delegate; | 813 ReadPlatformHandlesCheckerRawChannelDelegate read_delegate; |
814 scoped_ptr<RawChannel> rc_read(RawChannel::Create(handles[1].Pass())); | 814 scoped_ptr<RawChannel> rc_read(RawChannel::Create(handles[1].Pass())); |
815 io_thread()->PostTaskAndWait(FROM_HERE, | 815 io_thread()->PostTaskAndWait(FROM_HERE, |
816 base::Bind(&InitOnIOThread, rc_read.get(), | 816 base::Bind(&InitOnIOThread, rc_read.get(), |
817 base::Unretained(&read_delegate))); | 817 base::Unretained(&read_delegate))); |
818 | 818 |
819 base::FilePath unused; | 819 base::FilePath unused; |
820 base::ScopedFILE fp1( | 820 util::ScopedFILE fp1( |
821 base::CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); | 821 base::CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); |
822 EXPECT_EQ(1u, fwrite("1", 1, 1, fp1.get())); | 822 EXPECT_EQ(1u, fwrite("1", 1, 1, fp1.get())); |
823 base::ScopedFILE fp2( | 823 util::ScopedFILE fp2( |
824 base::CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); | 824 base::CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); |
825 EXPECT_EQ(1u, fwrite("2", 1, 1, fp2.get())); | 825 EXPECT_EQ(1u, fwrite("2", 1, 1, fp2.get())); |
826 | 826 |
827 { | 827 { |
828 const char kHello[] = "hello"; | 828 const char kHello[] = "hello"; |
829 embedder::ScopedPlatformHandleVectorPtr platform_handles( | 829 embedder::ScopedPlatformHandleVectorPtr platform_handles( |
830 new embedder::PlatformHandleVector()); | 830 new embedder::PlatformHandleVector()); |
831 platform_handles->push_back( | 831 platform_handles->push_back( |
832 mojo::test::PlatformHandleFromFILE(fp1.Pass()).release()); | 832 mojo::test::PlatformHandleFromFILE(fp1.Pass()).release()); |
833 platform_handles->push_back( | 833 platform_handles->push_back( |
(...skipping 14 matching lines...) Expand all Loading... |
848 FROM_HERE, | 848 FROM_HERE, |
849 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get()))); | 849 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get()))); |
850 io_thread()->PostTaskAndWait( | 850 io_thread()->PostTaskAndWait( |
851 FROM_HERE, | 851 FROM_HERE, |
852 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get()))); | 852 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get()))); |
853 } | 853 } |
854 | 854 |
855 } // namespace | 855 } // namespace |
856 } // namespace system | 856 } // namespace system |
857 } // namespace mojo | 857 } // namespace mojo |
OLD | NEW |