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

Side by Side Diff: ipc/ipc_message_utils_unittest.cc

Issue 10667002: Make the serialization of IPC::Messages inside other IPC::Messages independent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_message_utils.cc ('k') | 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ipc/ipc_message.h"
6 #include "ipc/ipc_message_utils.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace IPC {
10
11 // Tests nesting of messages as parameters to other messages.
12 TEST(IPCMessageUtilsTest, NestedMessages) {
13 int32 nested_routing = 12;
14 uint32 nested_type = 78;
15 int nested_content = 456789;
16 Message::PriorityValue nested_priority = Message::PRIORITY_HIGH;
17 Message nested_msg(nested_routing, nested_type, nested_priority);
18 nested_msg.set_sync();
19 ParamTraits<int>::Write(&nested_msg, nested_content);
20
21 // Outer message contains the nested one as its parameter.
22 int32 outer_routing = 91;
23 uint32 outer_type = 88;
24 Message::PriorityValue outer_priority = Message::PRIORITY_NORMAL;
25 Message outer_msg(outer_routing, outer_type, outer_priority);
26 ParamTraits<Message>::Write(&outer_msg, nested_msg);
27
28 // Read back the nested message.
29 PickleIterator iter(outer_msg);
30 IPC::Message result_msg;
31 ASSERT_TRUE(ParamTraits<Message>::Read(&outer_msg, &iter, &result_msg));
32
33 // Verify nested message headers.
34 EXPECT_EQ(nested_msg.routing_id(), result_msg.routing_id());
35 EXPECT_EQ(nested_msg.type(), result_msg.type());
36 EXPECT_EQ(nested_msg.priority(), result_msg.priority());
37 EXPECT_EQ(nested_msg.flags(), result_msg.flags());
38
39 // Verify nested message content
40 PickleIterator nested_iter(nested_msg);
41 int result_content = 0;
42 ASSERT_TRUE(ParamTraits<int>::Read(&nested_msg, &nested_iter,
43 &result_content));
44 EXPECT_EQ(nested_content, result_content);
45
46 // Try reading past the ends for both messages and make sure it fails.
47 IPC::Message dummy;
48 ASSERT_FALSE(ParamTraits<Message>::Read(&outer_msg, &iter, &dummy));
49 ASSERT_FALSE(ParamTraits<int>::Read(&nested_msg, &nested_iter,
50 &result_content));
51 }
52
53 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698