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

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

Issue 1396783004: Convert mojo::system::ChannelEndpointClient to use our new refcounting stuff (instead of base's). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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/channel_endpoint_client.h ('k') | mojo/edk/system/channel_unittest.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 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 "mojo/edk/system/channel_endpoint.h" 5 #include "mojo/edk/system/channel_endpoint.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 30 matching lines...) Expand all
41 FROM_HERE, &ChannelEndpointTest::ShutdownChannelOnIOThread, 1); 41 FROM_HERE, &ChannelEndpointTest::ShutdownChannelOnIOThread, 1);
42 42
43 test::ChannelTestBase::TearDown(); 43 test::ChannelTestBase::TearDown();
44 } 44 }
45 45
46 private: 46 private:
47 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelEndpointTest); 47 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelEndpointTest);
48 }; 48 };
49 49
50 TEST_F(ChannelEndpointTest, Basic) { 50 TEST_F(ChannelEndpointTest, Basic) {
51 scoped_refptr<test::TestChannelEndpointClient> client0( 51 auto client0 = MakeRefCounted<test::TestChannelEndpointClient>();
52 new test::TestChannelEndpointClient()); 52 auto endpoint0 = MakeRefCounted<ChannelEndpoint>(client0.Clone(), 0);
53 auto endpoint0 = MakeRefCounted<ChannelEndpoint>(client0.get(), 0);
54 client0->Init(0, endpoint0.Clone()); 53 client0->Init(0, endpoint0.Clone());
55 channel(0)->SetBootstrapEndpoint(std::move(endpoint0)); 54 channel(0)->SetBootstrapEndpoint(std::move(endpoint0));
56 55
57 scoped_refptr<test::TestChannelEndpointClient> client1( 56 auto client1 = MakeRefCounted<test::TestChannelEndpointClient>();
58 new test::TestChannelEndpointClient()); 57 auto endpoint1 = MakeRefCounted<ChannelEndpoint>(client1.Clone(), 1);
59 auto endpoint1 = MakeRefCounted<ChannelEndpoint>(client1.get(), 1);
60 client1->Init(1, endpoint1.Clone()); 58 client1->Init(1, endpoint1.Clone());
61 channel(1)->SetBootstrapEndpoint(endpoint1.Clone()); 59 channel(1)->SetBootstrapEndpoint(endpoint1.Clone());
62 60
63 // We'll receive a message on channel/client 0. 61 // We'll receive a message on channel/client 0.
64 base::WaitableEvent read_event(true, false); 62 base::WaitableEvent read_event(true, false);
65 client0->SetReadEvent(&read_event); 63 client0->SetReadEvent(&read_event);
66 64
67 // Make a test message. 65 // Make a test message.
68 unsigned message_id = 0x12345678; 66 unsigned message_id = 0x12345678;
69 std::unique_ptr<MessageInTransit> send_message = 67 std::unique_ptr<MessageInTransit> send_message =
(...skipping 15 matching lines...) Expand all
85 ASSERT_EQ(1u, client0->NumMessages()); 83 ASSERT_EQ(1u, client0->NumMessages());
86 std::unique_ptr<MessageInTransit> read_message = client0->PopMessage(); 84 std::unique_ptr<MessageInTransit> read_message = client0->PopMessage();
87 ASSERT_TRUE(read_message); 85 ASSERT_TRUE(read_message);
88 test::VerifyTestMessage(read_message.get(), message_id); 86 test::VerifyTestMessage(read_message.get(), message_id);
89 } 87 }
90 88
91 // Checks that prequeued messages and messages sent at various stages later on 89 // Checks that prequeued messages and messages sent at various stages later on
92 // are all sent/received (and in the correct order). (Note: Due to the way 90 // are all sent/received (and in the correct order). (Note: Due to the way
93 // bootstrap endpoints work, the receiving side has to be set up first.) 91 // bootstrap endpoints work, the receiving side has to be set up first.)
94 TEST_F(ChannelEndpointTest, Prequeued) { 92 TEST_F(ChannelEndpointTest, Prequeued) {
95 scoped_refptr<test::TestChannelEndpointClient> client0( 93 auto client0 = MakeRefCounted<test::TestChannelEndpointClient>();
96 new test::TestChannelEndpointClient()); 94 auto endpoint0 = MakeRefCounted<ChannelEndpoint>(client0.Clone(), 0);
97 auto endpoint0 = MakeRefCounted<ChannelEndpoint>(client0.get(), 0);
98 client0->Init(0, endpoint0.Clone()); 95 client0->Init(0, endpoint0.Clone());
99 96
100 channel(0)->SetBootstrapEndpoint(std::move(endpoint0)); 97 channel(0)->SetBootstrapEndpoint(std::move(endpoint0));
101 MessageInTransitQueue prequeued_messages; 98 MessageInTransitQueue prequeued_messages;
102 prequeued_messages.AddMessage(test::MakeTestMessage(1)); 99 prequeued_messages.AddMessage(test::MakeTestMessage(1));
103 prequeued_messages.AddMessage(test::MakeTestMessage(2)); 100 prequeued_messages.AddMessage(test::MakeTestMessage(2));
104 101
105 scoped_refptr<test::TestChannelEndpointClient> client1( 102 auto client1 = MakeRefCounted<test::TestChannelEndpointClient>();
106 new test::TestChannelEndpointClient());
107 auto endpoint1 = 103 auto endpoint1 =
108 MakeRefCounted<ChannelEndpoint>(client1.get(), 1, &prequeued_messages); 104 MakeRefCounted<ChannelEndpoint>(client1.Clone(), 1, &prequeued_messages);
109 client1->Init(1, endpoint1.Clone()); 105 client1->Init(1, endpoint1.Clone());
110 106
111 EXPECT_TRUE(endpoint1->EnqueueMessage(test::MakeTestMessage(3))); 107 EXPECT_TRUE(endpoint1->EnqueueMessage(test::MakeTestMessage(3)));
112 EXPECT_TRUE(endpoint1->EnqueueMessage(test::MakeTestMessage(4))); 108 EXPECT_TRUE(endpoint1->EnqueueMessage(test::MakeTestMessage(4)));
113 109
114 channel(1)->SetBootstrapEndpoint(endpoint1.Clone()); 110 channel(1)->SetBootstrapEndpoint(endpoint1.Clone());
115 111
116 EXPECT_TRUE(endpoint1->EnqueueMessage(test::MakeTestMessage(5))); 112 EXPECT_TRUE(endpoint1->EnqueueMessage(test::MakeTestMessage(5)));
117 EXPECT_TRUE(endpoint1->EnqueueMessage(test::MakeTestMessage(6))); 113 EXPECT_TRUE(endpoint1->EnqueueMessage(test::MakeTestMessage(6)));
118 114
(...skipping 11 matching lines...) Expand all
130 for (unsigned message_id = 1; message_id <= 6; message_id++) { 126 for (unsigned message_id = 1; message_id <= 6; message_id++) {
131 std::unique_ptr<MessageInTransit> read_message = client0->PopMessage(); 127 std::unique_ptr<MessageInTransit> read_message = client0->PopMessage();
132 ASSERT_TRUE(read_message); 128 ASSERT_TRUE(read_message);
133 test::VerifyTestMessage(read_message.get(), message_id); 129 test::VerifyTestMessage(read_message.get(), message_id);
134 } 130 }
135 } 131 }
136 132
137 } // namespace 133 } // namespace
138 } // namespace system 134 } // namespace system
139 } // namespace mojo 135 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel_endpoint_client.h ('k') | mojo/edk/system/channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698