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.h" | 5 #include "ipc/ipc_message.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
11 #include <limits> | 11 #include <limits> |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
| 14 #include "base/memory/ptr_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
17 #include "ipc/ipc_message_utils.h" | 18 #include "ipc/ipc_message_utils.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 // IPC messages for testing ---------------------------------------------------- | 21 // IPC messages for testing ---------------------------------------------------- |
21 | 22 |
22 #define IPC_MESSAGE_IMPL | 23 #define IPC_MESSAGE_IMPL |
23 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // should fail | 61 // should fail |
61 EXPECT_FALSE(iter.ReadInt(&vi)); | 62 EXPECT_FALSE(iter.ReadInt(&vi)); |
62 EXPECT_FALSE(iter.ReadString(&vs)); | 63 EXPECT_FALSE(iter.ReadString(&vs)); |
63 EXPECT_FALSE(iter.ReadString16(&vs16)); | 64 EXPECT_FALSE(iter.ReadString16(&vs16)); |
64 } | 65 } |
65 | 66 |
66 TEST(IPCMessageTest, ListValue) { | 67 TEST(IPCMessageTest, ListValue) { |
67 base::ListValue input; | 68 base::ListValue input; |
68 input.Set(0, new base::Value(42.42)); | 69 input.Set(0, new base::Value(42.42)); |
69 input.Set(1, new base::Value("forty")); | 70 input.Set(1, new base::Value("forty")); |
70 input.Set(2, base::Value::CreateNullValue()); | 71 input.Set(2, base::MakeUnique<base::Value>()); |
71 | 72 |
72 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 73 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
73 IPC::WriteParam(&msg, input); | 74 IPC::WriteParam(&msg, input); |
74 | 75 |
75 base::ListValue output; | 76 base::ListValue output; |
76 base::PickleIterator iter(msg); | 77 base::PickleIterator iter(msg); |
77 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 78 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
78 | 79 |
79 EXPECT_TRUE(input.Equals(&output)); | 80 EXPECT_TRUE(input.Equals(&output)); |
80 | 81 |
81 // Also test the corrupt case. | 82 // Also test the corrupt case. |
82 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 83 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
83 bad_msg.WriteInt(99); | 84 bad_msg.WriteInt(99); |
84 iter = base::PickleIterator(bad_msg); | 85 iter = base::PickleIterator(bad_msg); |
85 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); | 86 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); |
86 } | 87 } |
87 | 88 |
88 TEST(IPCMessageTest, DictionaryValue) { | 89 TEST(IPCMessageTest, DictionaryValue) { |
89 base::DictionaryValue input; | 90 base::DictionaryValue input; |
90 input.Set("null", base::Value::CreateNullValue()); | 91 input.Set("null", base::MakeUnique<base::Value>()); |
91 input.Set("bool", new base::Value(true)); | 92 input.Set("bool", new base::Value(true)); |
92 input.Set("int", new base::Value(42)); | 93 input.Set("int", new base::Value(42)); |
93 input.SetWithoutPathExpansion("int.with.dot", new base::Value(43)); | 94 input.SetWithoutPathExpansion("int.with.dot", new base::Value(43)); |
94 | 95 |
95 std::unique_ptr<base::DictionaryValue> subdict(new base::DictionaryValue()); | 96 std::unique_ptr<base::DictionaryValue> subdict(new base::DictionaryValue()); |
96 subdict->Set("str", new base::Value("forty two")); | 97 subdict->Set("str", new base::Value("forty two")); |
97 subdict->Set("bool", new base::Value(false)); | 98 subdict->Set("bool", new base::Value(false)); |
98 | 99 |
99 std::unique_ptr<base::ListValue> sublist(new base::ListValue()); | 100 std::unique_ptr<base::ListValue> sublist(new base::ListValue()); |
100 sublist->Set(0, new base::Value(42.42)); | 101 sublist->Set(0, new base::Value(42.42)); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 /* TODO: handle sync IPCs | 271 /* TODO: handle sync IPCs |
271 TEST_F(IPCMessageParameterTest, Sync) { | 272 TEST_F(IPCMessageParameterTest, Sync) { |
272 std::string output; | 273 std::string output; |
273 TestMsgClassIS message(42, &output); | 274 TestMsgClassIS message(42, &output); |
274 EXPECT_TRUE(OnMessageReceived(message)); | 275 EXPECT_TRUE(OnMessageReceived(message)); |
275 EXPECT_TRUE(called_); | 276 EXPECT_TRUE(called_); |
276 EXPECT_EQ(output, std::string("out")); | 277 EXPECT_EQ(output, std::string("out")); |
277 }*/ | 278 }*/ |
278 | 279 |
279 } // namespace IPC | 280 } // namespace IPC |
OLD | NEW |