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

Side by Side Diff: mojo/public/tests/bindings_connector_unittest.cc

Issue 68973006: Mojo: Make bindings_connector_unittest.cc not depend on base. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "mojo/public/bindings/lib/bindings_support.h" 8 #include "mojo/public/bindings/lib/bindings_support.h"
11 #include "mojo/public/bindings/lib/connector.h" 9 #include "mojo/public/bindings/lib/connector.h"
12 #include "mojo/public/bindings/lib/message_queue.h" 10 #include "mojo/public/bindings/lib/message_queue.h"
11 #include "mojo/public/system/macros.h"
13 #include "mojo/public/tests/simple_bindings_support.h" 12 #include "mojo/public/tests/simple_bindings_support.h"
14 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
15 14
16 namespace mojo { 15 namespace mojo {
17 namespace test { 16 namespace test {
18 17
19 class MessageAccumulator : public MessageReceiver { 18 class MessageAccumulator : public MessageReceiver {
20 public: 19 public:
21 MessageAccumulator() { 20 MessageAccumulator() {
22 } 21 }
(...skipping 15 matching lines...) Expand all
38 MessageQueue queue_; 37 MessageQueue queue_;
39 }; 38 };
40 39
41 class BindingsConnectorTest : public testing::Test { 40 class BindingsConnectorTest : public testing::Test {
42 public: 41 public:
43 BindingsConnectorTest() 42 BindingsConnectorTest()
44 : handle0_(kInvalidHandle), 43 : handle0_(kInvalidHandle),
45 handle1_(kInvalidHandle) { 44 handle1_(kInvalidHandle) {
46 } 45 }
47 46
48 virtual void SetUp() OVERRIDE { 47 virtual void SetUp() MOJO_OVERRIDE {
49 CreateMessagePipe(&handle0_, &handle1_); 48 CreateMessagePipe(&handle0_, &handle1_);
50 } 49 }
51 50
52 virtual void TearDown() OVERRIDE { 51 virtual void TearDown() MOJO_OVERRIDE {
53 Close(handle0_); 52 Close(handle0_);
54 Close(handle1_); 53 Close(handle1_);
55 } 54 }
56 55
57 void AllocMessage(const char* text, Message* message) { 56 void AllocMessage(const char* text, Message* message) {
58 size_t payload_size = strlen(text) + 1; // Plus null terminator. 57 size_t payload_size = strlen(text) + 1; // Plus null terminator.
59 size_t num_bytes = sizeof(MessageHeader) + payload_size; 58 size_t num_bytes = sizeof(MessageHeader) + payload_size;
60 message->data = static_cast<MessageData*>(malloc(num_bytes)); 59 message->data = static_cast<MessageData*>(malloc(num_bytes));
61 message->data->header.num_bytes = num_bytes; 60 message->data->header.num_bytes = num_bytes;
62 message->data->header.name = 1; 61 message->data->header.name = 1;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 std::string( 125 std::string(
127 reinterpret_cast<char*>(message_received.data->payload))); 126 reinterpret_cast<char*>(message_received.data->payload)));
128 } 127 }
129 128
130 TEST_F(BindingsConnectorTest, Basic_TwoMessages) { 129 TEST_F(BindingsConnectorTest, Basic_TwoMessages) {
131 Connector connector0(handle0_); 130 Connector connector0(handle0_);
132 Connector connector1(handle1_); 131 Connector connector1(handle1_);
133 132
134 const char* kText[] = { "hello", "world" }; 133 const char* kText[] = { "hello", "world" };
135 134
136 for (size_t i = 0; i < arraysize(kText); ++i) { 135 for (size_t i = 0; i < sizeof(kText) / sizeof(kText[0]); ++i) {
137 Message message; 136 Message message;
138 AllocMessage(kText[i], &message); 137 AllocMessage(kText[i], &message);
139 138
140 connector0.Accept(&message); 139 connector0.Accept(&message);
141 } 140 }
142 141
143 MessageAccumulator accumulator; 142 MessageAccumulator accumulator;
144 connector1.SetIncomingReceiver(&accumulator); 143 connector1.SetIncomingReceiver(&accumulator);
145 144
146 PumpMessages(); 145 PumpMessages();
147 146
148 for (size_t i = 0; i < arraysize(kText); ++i) { 147 for (size_t i = 0; i < sizeof(kText) / sizeof(kText[0]); ++i) {
149 ASSERT_FALSE(accumulator.IsEmpty()); 148 ASSERT_FALSE(accumulator.IsEmpty());
150 149
151 Message message_received; 150 Message message_received;
152 accumulator.Pop(&message_received); 151 accumulator.Pop(&message_received);
153 152
154 EXPECT_EQ(std::string(kText[i]), 153 EXPECT_EQ(std::string(kText[i]),
155 std::string( 154 std::string(
156 reinterpret_cast<char*>(message_received.data->payload))); 155 reinterpret_cast<char*>(message_received.data->payload)));
157 } 156 }
158 } 157 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 std::string( 208 std::string(
210 reinterpret_cast<char*>(message_received.data->payload))); 209 reinterpret_cast<char*>(message_received.data->payload)));
211 ASSERT_EQ(2U, message_received.handles.size()); 210 ASSERT_EQ(2U, message_received.handles.size());
212 EXPECT_EQ(handles[0].value, message_received.handles[0].value); 211 EXPECT_EQ(handles[0].value, message_received.handles[0].value);
213 EXPECT_EQ(handles[1].value, message_received.handles[1].value); 212 EXPECT_EQ(handles[1].value, message_received.handles[1].value);
214 } 213 }
215 #endif 214 #endif
216 215
217 } // namespace test 216 } // namespace test
218 } // namespace mojo 217 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698