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 "ipc/ipc_message_utils.h" | 5 #include "ipc/ipc_message_utils.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "ipc/ipc_message.h" | 8 #include "ipc/ipc_message.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace IPC { | 11 namespace IPC { |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Tests nesting of messages as parameters to other messages. | 14 // Tests nesting of messages as parameters to other messages. |
15 TEST(IPCMessageUtilsTest, NestedMessages) { | 15 TEST(IPCMessageUtilsTest, NestedMessages) { |
16 int32 nested_routing = 12; | 16 int32 nested_routing = 12; |
17 uint32 nested_type = 78; | 17 uint32 nested_type = 78; |
18 int nested_content = 456789; | 18 int nested_content = 456789; |
19 Message::PriorityValue nested_priority = Message::PRIORITY_HIGH; | 19 Message nested_msg(nested_routing, nested_type); |
20 Message nested_msg(nested_routing, nested_type, nested_priority); | |
21 nested_msg.set_sync(); | 20 nested_msg.set_sync(); |
22 ParamTraits<int>::Write(&nested_msg, nested_content); | 21 ParamTraits<int>::Write(&nested_msg, nested_content); |
23 | 22 |
24 // Outer message contains the nested one as its parameter. | 23 // Outer message contains the nested one as its parameter. |
25 int32 outer_routing = 91; | 24 int32 outer_routing = 91; |
26 uint32 outer_type = 88; | 25 uint32 outer_type = 88; |
27 Message::PriorityValue outer_priority = Message::PRIORITY_NORMAL; | 26 Message outer_msg(outer_routing, outer_type); |
28 Message outer_msg(outer_routing, outer_type, outer_priority); | |
29 ParamTraits<Message>::Write(&outer_msg, nested_msg); | 27 ParamTraits<Message>::Write(&outer_msg, nested_msg); |
30 | 28 |
31 // Read back the nested message. | 29 // Read back the nested message. |
32 PickleIterator iter(outer_msg); | 30 PickleIterator iter(outer_msg); |
33 IPC::Message result_msg; | 31 IPC::Message result_msg; |
34 ASSERT_TRUE(ParamTraits<Message>::Read(&outer_msg, &iter, &result_msg)); | 32 ASSERT_TRUE(ParamTraits<Message>::Read(&outer_msg, &iter, &result_msg)); |
35 | 33 |
36 // Verify nested message headers. | 34 // Verify nested message headers. |
37 EXPECT_EQ(nested_msg.routing_id(), result_msg.routing_id()); | 35 EXPECT_EQ(nested_msg.routing_id(), result_msg.routing_id()); |
38 EXPECT_EQ(nested_msg.type(), result_msg.type()); | 36 EXPECT_EQ(nested_msg.type(), result_msg.type()); |
39 EXPECT_EQ(nested_msg.priority(), result_msg.priority()); | |
40 EXPECT_EQ(nested_msg.flags(), result_msg.flags()); | 37 EXPECT_EQ(nested_msg.flags(), result_msg.flags()); |
41 | 38 |
42 // Verify nested message content | 39 // Verify nested message content |
43 PickleIterator nested_iter(nested_msg); | 40 PickleIterator nested_iter(nested_msg); |
44 int result_content = 0; | 41 int result_content = 0; |
45 ASSERT_TRUE(ParamTraits<int>::Read(&nested_msg, &nested_iter, | 42 ASSERT_TRUE(ParamTraits<int>::Read(&nested_msg, &nested_iter, |
46 &result_content)); | 43 &result_content)); |
47 EXPECT_EQ(nested_content, result_content); | 44 EXPECT_EQ(nested_content, result_content); |
48 | 45 |
49 // Try reading past the ends for both messages and make sure it fails. | 46 // Try reading past the ends for both messages and make sure it fails. |
(...skipping 15 matching lines...) Expand all Loading... |
65 | 62 |
66 PickleIterator iter(message); | 63 PickleIterator iter(message); |
67 base::FilePath ok_path; | 64 base::FilePath ok_path; |
68 base::FilePath bad_path; | 65 base::FilePath bad_path; |
69 ASSERT_TRUE(ParamTraits<base::FilePath>::Read(&message, &iter, &ok_path)); | 66 ASSERT_TRUE(ParamTraits<base::FilePath>::Read(&message, &iter, &ok_path)); |
70 ASSERT_FALSE(ParamTraits<base::FilePath>::Read(&message, &iter, &bad_path)); | 67 ASSERT_FALSE(ParamTraits<base::FilePath>::Read(&message, &iter, &bad_path)); |
71 } | 68 } |
72 | 69 |
73 } // namespace | 70 } // namespace |
74 } // namespace IPC | 71 } // namespace IPC |
OLD | NEW |