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

Side by Side Diff: ipc/ipc_message_utils_unittest.cc

Issue 1154283003: Change most uses of Pickle to base::Pickle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « ipc/ipc_message_utils.cc ('k') | ipc/ipc_perftest_support.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 11 matching lines...) Expand all
22 ParamTraits<int>::Write(&nested_msg, nested_content); 22 ParamTraits<int>::Write(&nested_msg, nested_content);
23 23
24 // Outer message contains the nested one as its parameter. 24 // Outer message contains the nested one as its parameter.
25 int32 outer_routing = 91; 25 int32 outer_routing = 91;
26 uint32 outer_type = 88; 26 uint32 outer_type = 88;
27 Message::PriorityValue outer_priority = Message::PRIORITY_NORMAL; 27 Message::PriorityValue outer_priority = Message::PRIORITY_NORMAL;
28 Message outer_msg(outer_routing, outer_type, outer_priority); 28 Message outer_msg(outer_routing, outer_type, outer_priority);
29 ParamTraits<Message>::Write(&outer_msg, nested_msg); 29 ParamTraits<Message>::Write(&outer_msg, nested_msg);
30 30
31 // Read back the nested message. 31 // Read back the nested message.
32 PickleIterator iter(outer_msg); 32 base::PickleIterator iter(outer_msg);
33 IPC::Message result_msg; 33 IPC::Message result_msg;
34 ASSERT_TRUE(ParamTraits<Message>::Read(&outer_msg, &iter, &result_msg)); 34 ASSERT_TRUE(ParamTraits<Message>::Read(&outer_msg, &iter, &result_msg));
35 35
36 // Verify nested message headers. 36 // Verify nested message headers.
37 EXPECT_EQ(nested_msg.routing_id(), result_msg.routing_id()); 37 EXPECT_EQ(nested_msg.routing_id(), result_msg.routing_id());
38 EXPECT_EQ(nested_msg.type(), result_msg.type()); 38 EXPECT_EQ(nested_msg.type(), result_msg.type());
39 EXPECT_EQ(nested_msg.priority(), result_msg.priority()); 39 EXPECT_EQ(nested_msg.priority(), result_msg.priority());
40 EXPECT_EQ(nested_msg.flags(), result_msg.flags()); 40 EXPECT_EQ(nested_msg.flags(), result_msg.flags());
41 41
42 // Verify nested message content 42 // Verify nested message content
43 PickleIterator nested_iter(nested_msg); 43 base::PickleIterator nested_iter(nested_msg);
44 int result_content = 0; 44 int result_content = 0;
45 ASSERT_TRUE(ParamTraits<int>::Read(&nested_msg, &nested_iter, 45 ASSERT_TRUE(ParamTraits<int>::Read(&nested_msg, &nested_iter,
46 &result_content)); 46 &result_content));
47 EXPECT_EQ(nested_content, result_content); 47 EXPECT_EQ(nested_content, result_content);
48 48
49 // Try reading past the ends for both messages and make sure it fails. 49 // Try reading past the ends for both messages and make sure it fails.
50 IPC::Message dummy; 50 IPC::Message dummy;
51 ASSERT_FALSE(ParamTraits<Message>::Read(&outer_msg, &iter, &dummy)); 51 ASSERT_FALSE(ParamTraits<Message>::Read(&outer_msg, &iter, &dummy));
52 ASSERT_FALSE(ParamTraits<int>::Read(&nested_msg, &nested_iter, 52 ASSERT_FALSE(ParamTraits<int>::Read(&nested_msg, &nested_iter,
53 &result_content)); 53 &result_content));
54 } 54 }
55 55
56 // Tests that detection of various bad parameters is working correctly. 56 // Tests that detection of various bad parameters is working correctly.
57 TEST(IPCMessageUtilsTest, ParameterValidation) { 57 TEST(IPCMessageUtilsTest, ParameterValidation) {
58 base::FilePath::StringType ok_string(FILE_PATH_LITERAL("hello"), 5); 58 base::FilePath::StringType ok_string(FILE_PATH_LITERAL("hello"), 5);
59 base::FilePath::StringType bad_string(FILE_PATH_LITERAL("hel\0o"), 5); 59 base::FilePath::StringType bad_string(FILE_PATH_LITERAL("hel\0o"), 5);
60 60
61 // Change this if ParamTraits<FilePath>::Write() changes. 61 // Change this if ParamTraits<FilePath>::Write() changes.
62 IPC::Message message; 62 IPC::Message message;
63 ParamTraits<base::FilePath::StringType>::Write(&message, ok_string); 63 ParamTraits<base::FilePath::StringType>::Write(&message, ok_string);
64 ParamTraits<base::FilePath::StringType>::Write(&message, bad_string); 64 ParamTraits<base::FilePath::StringType>::Write(&message, bad_string);
65 65
66 PickleIterator iter(message); 66 base::PickleIterator iter(message);
67 base::FilePath ok_path; 67 base::FilePath ok_path;
68 base::FilePath bad_path; 68 base::FilePath bad_path;
69 ASSERT_TRUE(ParamTraits<base::FilePath>::Read(&message, &iter, &ok_path)); 69 ASSERT_TRUE(ParamTraits<base::FilePath>::Read(&message, &iter, &ok_path));
70 ASSERT_FALSE(ParamTraits<base::FilePath>::Read(&message, &iter, &bad_path)); 70 ASSERT_FALSE(ParamTraits<base::FilePath>::Read(&message, &iter, &bad_path));
71 } 71 }
72 72
73 } // namespace 73 } // namespace
74 } // namespace IPC 74 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message_utils.cc ('k') | ipc/ipc_perftest_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698