diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-29 00:05:04 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-29 00:05:04 +0000 |
commit | 34d4861069f6528aac208a3268f8c4946d301a16 (patch) | |
tree | 0efd4735b9912a93b220f9e312d7ca14cf281360 /ipc/ipc_message_utils_unittest.cc | |
parent | b9ef2965a07ca50fd94f1ab1d22ffcfdf62a2b6d (diff) | |
download | chromium_src-34d4861069f6528aac208a3268f8c4946d301a16.zip chromium_src-34d4861069f6528aac208a3268f8c4946d301a16.tar.gz chromium_src-34d4861069f6528aac208a3268f8c4946d301a16.tar.bz2 |
Make the serialization of IPC::Messages inside other IPC::Messages independent
of the platform.
This is necessary for sending nested messages between nacl (which the IPC
system thinks is posix and so has extra header goo) and a Windows client app
(which doesn't have this stuff).
BUG=
Review URL: https://chromiumcodereview.appspot.com/10667002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144840 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_message_utils_unittest.cc')
-rw-r--r-- | ipc/ipc_message_utils_unittest.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/ipc/ipc_message_utils_unittest.cc b/ipc/ipc_message_utils_unittest.cc new file mode 100644 index 0000000..19726a0 --- /dev/null +++ b/ipc/ipc_message_utils_unittest.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ipc/ipc_message.h" +#include "ipc/ipc_message_utils.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace IPC { + +// Tests nesting of messages as parameters to other messages. +TEST(IPCMessageUtilsTest, NestedMessages) { + int32 nested_routing = 12; + uint32 nested_type = 78; + int nested_content = 456789; + Message::PriorityValue nested_priority = Message::PRIORITY_HIGH; + Message nested_msg(nested_routing, nested_type, nested_priority); + nested_msg.set_sync(); + ParamTraits<int>::Write(&nested_msg, nested_content); + + // Outer message contains the nested one as its parameter. + int32 outer_routing = 91; + uint32 outer_type = 88; + Message::PriorityValue outer_priority = Message::PRIORITY_NORMAL; + Message outer_msg(outer_routing, outer_type, outer_priority); + ParamTraits<Message>::Write(&outer_msg, nested_msg); + + // Read back the nested message. + PickleIterator iter(outer_msg); + IPC::Message result_msg; + ASSERT_TRUE(ParamTraits<Message>::Read(&outer_msg, &iter, &result_msg)); + + // Verify nested message headers. + EXPECT_EQ(nested_msg.routing_id(), result_msg.routing_id()); + EXPECT_EQ(nested_msg.type(), result_msg.type()); + EXPECT_EQ(nested_msg.priority(), result_msg.priority()); + EXPECT_EQ(nested_msg.flags(), result_msg.flags()); + + // Verify nested message content + PickleIterator nested_iter(nested_msg); + int result_content = 0; + ASSERT_TRUE(ParamTraits<int>::Read(&nested_msg, &nested_iter, + &result_content)); + EXPECT_EQ(nested_content, result_content); + + // Try reading past the ends for both messages and make sure it fails. + IPC::Message dummy; + ASSERT_FALSE(ParamTraits<Message>::Read(&outer_msg, &iter, &dummy)); + ASSERT_FALSE(ParamTraits<int>::Read(&nested_msg, &nested_iter, + &result_content)); +} + +} // namespace IPC |