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, 2); | 26 IPC::Message* message = new IPC::Message(0, |
| 27 2, |
| 28 IPC::Message::PRIORITY_NORMAL); |
27 message->WriteInt(message_index++); | 29 message->WriteInt(message_index++); |
28 message->WriteString(std::string(text)); | 30 message->WriteString(std::string(text)); |
29 | 31 |
30 // Make sure we can handle large messages. | 32 // Make sure we can handle large messages. |
31 char junk[kLongMessageStringNumBytes]; | 33 char junk[kLongMessageStringNumBytes]; |
32 memset(junk, 'a', sizeof(junk)-1); | 34 memset(junk, 'a', sizeof(junk)-1); |
33 junk[sizeof(junk)-1] = 0; | 35 junk[sizeof(junk)-1] = 0; |
34 message->WriteString(std::string(junk)); | 36 message->WriteString(std::string(junk)); |
35 | 37 |
36 // DEBUG: printf("[%u] sending message [%s]\n", GetCurrentProcessId(), text); | 38 // DEBUG: printf("[%u] sending message [%s]\n", GetCurrentProcessId(), text); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 87 |
86 class IPCChannelTest : public IPCTestBase { | 88 class IPCChannelTest : public IPCTestBase { |
87 }; | 89 }; |
88 | 90 |
89 // TODO(viettrungluu): Move to a separate IPCMessageTest. | 91 // TODO(viettrungluu): Move to a separate IPCMessageTest. |
90 TEST_F(IPCChannelTest, BasicMessageTest) { | 92 TEST_F(IPCChannelTest, BasicMessageTest) { |
91 int v1 = 10; | 93 int v1 = 10; |
92 std::string v2("foobar"); | 94 std::string v2("foobar"); |
93 std::wstring v3(L"hello world"); | 95 std::wstring v3(L"hello world"); |
94 | 96 |
95 IPC::Message m(0, 1); | 97 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); |
96 EXPECT_TRUE(m.WriteInt(v1)); | 98 EXPECT_TRUE(m.WriteInt(v1)); |
97 EXPECT_TRUE(m.WriteString(v2)); | 99 EXPECT_TRUE(m.WriteString(v2)); |
98 EXPECT_TRUE(m.WriteWString(v3)); | 100 EXPECT_TRUE(m.WriteWString(v3)); |
99 | 101 |
100 PickleIterator iter(m); | 102 PickleIterator iter(m); |
101 | 103 |
102 int vi; | 104 int vi; |
103 std::string vs; | 105 std::string vs; |
104 std::wstring vw; | 106 std::wstring vw; |
105 | 107 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 &listener); | 259 &listener); |
258 CHECK(channel.Connect()); | 260 CHECK(channel.Connect()); |
259 listener.Init(&channel); | 261 listener.Init(&channel); |
260 Send(&channel, "hello from child"); | 262 Send(&channel, "hello from child"); |
261 | 263 |
262 base::MessageLoop::current()->Run(); | 264 base::MessageLoop::current()->Run(); |
263 return 0; | 265 return 0; |
264 } | 266 } |
265 | 267 |
266 } // namespace | 268 } // namespace |
OLD | NEW |