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

Side by Side Diff: mojo/edk/system/raw_channel_unittest.cc

Issue 1353683005: EDK: Convert remaining scoped_ptr -> std::unique_ptr in //mojo/edk/system. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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 | « mojo/edk/system/raw_channel_posix.cc ('k') | mojo/edk/system/remote_consumer_data_pipe_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory>
11 #include <utility>
10 #include <vector> 12 #include <vector>
11 13
12 #include "base/bind.h" 14 #include "base/bind.h"
13 #include "base/location.h" 15 #include "base/location.h"
14 #include "base/logging.h" 16 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
17 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
18 #include "base/threading/simple_thread.h" 19 #include "base/threading/simple_thread.h"
19 #include "mojo/edk/embedder/platform_channel_pair.h" 20 #include "mojo/edk/embedder/platform_channel_pair.h"
20 #include "mojo/edk/embedder/platform_handle.h" 21 #include "mojo/edk/embedder/platform_handle.h"
21 #include "mojo/edk/embedder/scoped_platform_handle.h" 22 #include "mojo/edk/embedder/scoped_platform_handle.h"
22 #include "mojo/edk/system/message_in_transit.h" 23 #include "mojo/edk/system/message_in_transit.h"
23 #include "mojo/edk/system/mutex.h" 24 #include "mojo/edk/system/mutex.h"
24 #include "mojo/edk/system/test_utils.h" 25 #include "mojo/edk/system/test_utils.h"
25 #include "mojo/edk/system/transport_data.h" 26 #include "mojo/edk/system/transport_data.h"
26 #include "mojo/edk/test/scoped_test_dir.h" 27 #include "mojo/edk/test/scoped_test_dir.h"
27 #include "mojo/edk/test/test_io_thread.h" 28 #include "mojo/edk/test/test_io_thread.h"
28 #include "mojo/edk/test/test_utils.h" 29 #include "mojo/edk/test/test_utils.h"
29 #include "mojo/edk/util/make_unique.h" 30 #include "mojo/edk/util/make_unique.h"
30 #include "mojo/edk/util/scoped_file.h" 31 #include "mojo/edk/util/scoped_file.h"
31 #include "mojo/public/cpp/system/macros.h" 32 #include "mojo/public/cpp/system/macros.h"
32 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
33 34
34 namespace mojo { 35 namespace mojo {
35 namespace system { 36 namespace system {
36 namespace { 37 namespace {
37 38
38 scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) { 39 std::unique_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) {
39 std::vector<unsigned char> bytes(num_bytes, 0); 40 std::vector<unsigned char> bytes(num_bytes, 0);
40 for (size_t i = 0; i < num_bytes; i++) 41 for (size_t i = 0; i < num_bytes; i++)
41 bytes[i] = static_cast<unsigned char>(i + num_bytes); 42 bytes[i] = static_cast<unsigned char>(i + num_bytes);
42 return make_scoped_ptr( 43 return util::MakeUnique<MessageInTransit>(
43 new MessageInTransit(MessageInTransit::Type::ENDPOINT_CLIENT, 44 MessageInTransit::Type::ENDPOINT_CLIENT,
44 MessageInTransit::Subtype::ENDPOINT_CLIENT_DATA, 45 MessageInTransit::Subtype::ENDPOINT_CLIENT_DATA, num_bytes,
45 num_bytes, bytes.empty() ? nullptr : &bytes[0])); 46 bytes.empty() ? nullptr : &bytes[0]);
46 } 47 }
47 48
48 bool CheckMessageData(const void* bytes, uint32_t num_bytes) { 49 bool CheckMessageData(const void* bytes, uint32_t num_bytes) {
49 const unsigned char* b = static_cast<const unsigned char*>(bytes); 50 const unsigned char* b = static_cast<const unsigned char*>(bytes);
50 for (uint32_t i = 0; i < num_bytes; i++) { 51 for (uint32_t i = 0; i < num_bytes; i++) {
51 if (b[i] != static_cast<unsigned char>(i + num_bytes)) 52 if (b[i] != static_cast<unsigned char>(i + num_bytes))
52 return false; 53 return false;
53 } 54 }
54 return true; 55 return true;
55 } 56 }
56 57
57 void InitOnIOThread(RawChannel* raw_channel, RawChannel::Delegate* delegate) { 58 void InitOnIOThread(RawChannel* raw_channel, RawChannel::Delegate* delegate) {
58 raw_channel->Init(delegate); 59 raw_channel->Init(delegate);
59 } 60 }
60 61
61 bool WriteTestMessageToHandle(const embedder::PlatformHandle& handle, 62 bool WriteTestMessageToHandle(const embedder::PlatformHandle& handle,
62 uint32_t num_bytes) { 63 uint32_t num_bytes) {
63 scoped_ptr<MessageInTransit> message(MakeTestMessage(num_bytes)); 64 std::unique_ptr<MessageInTransit> message(MakeTestMessage(num_bytes));
64 65
65 size_t write_size = 0; 66 size_t write_size = 0;
66 mojo::test::BlockingWrite(handle, message->main_buffer(), 67 mojo::test::BlockingWrite(handle, message->main_buffer(),
67 message->main_buffer_size(), &write_size); 68 message->main_buffer_size(), &write_size);
68 return write_size == message->main_buffer_size(); 69 return write_size == message->main_buffer_size();
69 } 70 }
70 71
71 // ----------------------------------------------------------------------------- 72 // -----------------------------------------------------------------------------
72 73
73 class RawChannelTest : public testing::Test { 74 class RawChannelTest : public testing::Test {
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 815
815 { 816 {
816 const char kHello[] = "hello"; 817 const char kHello[] = "hello";
817 embedder::ScopedPlatformHandleVectorPtr platform_handles( 818 embedder::ScopedPlatformHandleVectorPtr platform_handles(
818 new embedder::PlatformHandleVector()); 819 new embedder::PlatformHandleVector());
819 platform_handles->push_back( 820 platform_handles->push_back(
820 mojo::test::PlatformHandleFromFILE(fp1.Pass()).release()); 821 mojo::test::PlatformHandleFromFILE(fp1.Pass()).release());
821 platform_handles->push_back( 822 platform_handles->push_back(
822 mojo::test::PlatformHandleFromFILE(fp2.Pass()).release()); 823 mojo::test::PlatformHandleFromFILE(fp2.Pass()).release());
823 824
824 scoped_ptr<MessageInTransit> message( 825 std::unique_ptr<MessageInTransit> message(
825 new MessageInTransit(MessageInTransit::Type::ENDPOINT_CLIENT, 826 new MessageInTransit(MessageInTransit::Type::ENDPOINT_CLIENT,
826 MessageInTransit::Subtype::ENDPOINT_CLIENT_DATA, 827 MessageInTransit::Subtype::ENDPOINT_CLIENT_DATA,
827 sizeof(kHello), kHello)); 828 sizeof(kHello), kHello));
828 message->SetTransportData(util::MakeUnique<TransportData>( 829 message->SetTransportData(util::MakeUnique<TransportData>(
829 platform_handles.Pass(), rc_write->GetSerializedPlatformHandleSize())); 830 platform_handles.Pass(), rc_write->GetSerializedPlatformHandleSize()));
830 EXPECT_TRUE(rc_write->WriteMessage(message.Pass())); 831 EXPECT_TRUE(rc_write->WriteMessage(std::move(message)));
831 } 832 }
832 833
833 read_delegate.Wait(); 834 read_delegate.Wait();
834 835
835 io_thread()->PostTaskAndWait( 836 io_thread()->PostTaskAndWait(
836 FROM_HERE, 837 FROM_HERE,
837 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get()))); 838 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get())));
838 io_thread()->PostTaskAndWait( 839 io_thread()->PostTaskAndWait(
839 FROM_HERE, 840 FROM_HERE,
840 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get()))); 841 base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get())));
841 } 842 }
842 843
843 } // namespace 844 } // namespace
844 } // namespace system 845 } // namespace system
845 } // namespace mojo 846 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/raw_channel_posix.cc ('k') | mojo/edk/system/remote_consumer_data_pipe_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698