OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/pickle.h" | 14 #include "base/pickle.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
17 #include "ipc/ipc_test_base.h" | 17 #include "ipc/ipc_test_base.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const size_t kLongMessageStringNumBytes = 50000; | 21 const size_t kLongMessageStringNumBytes = 50000; |
22 | 22 |
23 static void Send(IPC::Sender* sender, const char* text) { | 23 static void Send(IPC::Sender* sender, const char* text) { |
24 static int message_index = 0; | 24 static int message_index = 0; |
25 | 25 |
26 IPC::Message* message = new IPC::Message(0, | 26 IPC::Message* message = new IPC::Message(0, 2); |
27 2, | |
28 IPC::Message::PRIORITY_NORMAL); | |
29 message->WriteInt(message_index++); | 27 message->WriteInt(message_index++); |
30 message->WriteString(std::string(text)); | 28 message->WriteString(std::string(text)); |
31 | 29 |
32 // Make sure we can handle large messages. | 30 // Make sure we can handle large messages. |
33 char junk[kLongMessageStringNumBytes]; | 31 char junk[kLongMessageStringNumBytes]; |
34 memset(junk, 'a', sizeof(junk)-1); | 32 memset(junk, 'a', sizeof(junk)-1); |
35 junk[sizeof(junk)-1] = 0; | 33 junk[sizeof(junk)-1] = 0; |
36 message->WriteString(std::string(junk)); | 34 message->WriteString(std::string(junk)); |
37 | 35 |
38 // DEBUG: printf("[%u] sending message [%s]\n", GetCurrentProcessId(), text); | 36 // DEBUG: printf("[%u] sending message [%s]\n", GetCurrentProcessId(), text); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 85 |
88 class IPCChannelTest : public IPCTestBase { | 86 class IPCChannelTest : public IPCTestBase { |
89 }; | 87 }; |
90 | 88 |
91 // TODO(viettrungluu): Move to a separate IPCMessageTest. | 89 // TODO(viettrungluu): Move to a separate IPCMessageTest. |
92 TEST_F(IPCChannelTest, BasicMessageTest) { | 90 TEST_F(IPCChannelTest, BasicMessageTest) { |
93 int v1 = 10; | 91 int v1 = 10; |
94 std::string v2("foobar"); | 92 std::string v2("foobar"); |
95 std::wstring v3(L"hello world"); | 93 std::wstring v3(L"hello world"); |
96 | 94 |
97 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); | 95 IPC::Message m(0, 1); |
98 EXPECT_TRUE(m.WriteInt(v1)); | 96 EXPECT_TRUE(m.WriteInt(v1)); |
99 EXPECT_TRUE(m.WriteString(v2)); | 97 EXPECT_TRUE(m.WriteString(v2)); |
100 EXPECT_TRUE(m.WriteWString(v3)); | 98 EXPECT_TRUE(m.WriteWString(v3)); |
101 | 99 |
102 PickleIterator iter(m); | 100 PickleIterator iter(m); |
103 | 101 |
104 int vi; | 102 int vi; |
105 std::string vs; | 103 std::string vs; |
106 std::wstring vw; | 104 std::wstring vw; |
107 | 105 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 &listener); | 257 &listener); |
260 CHECK(channel.Connect()); | 258 CHECK(channel.Connect()); |
261 listener.Init(&channel); | 259 listener.Init(&channel); |
262 Send(&channel, "hello from child"); | 260 Send(&channel, "hello from child"); |
263 | 261 |
264 base::MessageLoop::current()->Run(); | 262 base::MessageLoop::current()->Run(); |
265 return 0; | 263 return 0; |
266 } | 264 } |
267 | 265 |
268 } // namespace | 266 } // namespace |
OLD | NEW |