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 #include <utility> |
13 | 14 |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "ipc/ipc_message_utils.h" | 19 #include "ipc/ipc_message_utils.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 // IPC messages for testing ---------------------------------------------------- | 22 // IPC messages for testing ---------------------------------------------------- |
22 | 23 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Also test the corrupt case. | 83 // Also test the corrupt case. |
83 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 84 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
84 bad_msg.WriteInt(99); | 85 bad_msg.WriteInt(99); |
85 iter = base::PickleIterator(bad_msg); | 86 iter = base::PickleIterator(bad_msg); |
86 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); | 87 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); |
87 } | 88 } |
88 | 89 |
89 TEST(IPCMessageTest, DictionaryValue) { | 90 TEST(IPCMessageTest, DictionaryValue) { |
90 base::DictionaryValue input; | 91 base::DictionaryValue input; |
91 input.Set("null", base::MakeUnique<base::Value>()); | 92 input.Set("null", base::MakeUnique<base::Value>()); |
92 input.Set("bool", new base::Value(true)); | 93 input.SetBoolean("bool", true); |
93 input.Set("int", new base::Value(42)); | 94 input.SetInteger("int", 42); |
94 input.SetIntegerWithoutPathExpansion("int.with.dot", 43); | 95 input.SetIntegerWithoutPathExpansion("int.with.dot", 43); |
95 | 96 |
96 std::unique_ptr<base::DictionaryValue> subdict(new base::DictionaryValue()); | 97 auto subdict = base::MakeUnique<base::DictionaryValue>(); |
97 subdict->Set("str", new base::Value("forty two")); | 98 subdict->SetString("str", "forty two"); |
98 subdict->Set("bool", new base::Value(false)); | 99 subdict->SetBoolean("bool", false); |
99 | 100 |
100 std::unique_ptr<base::ListValue> sublist(new base::ListValue()); | 101 auto sublist = base::MakeUnique<base::ListValue>(); |
101 sublist->AppendDouble(42.42); | 102 sublist->AppendDouble(42.42); |
102 sublist->AppendString("forty"); | 103 sublist->AppendString("forty"); |
103 sublist->AppendString("two"); | 104 sublist->AppendString("two"); |
104 subdict->Set("list", sublist.release()); | 105 subdict->Set("list", std::move(sublist)); |
105 | 106 |
106 input.Set("dict", subdict.release()); | 107 input.Set("dict", std::move(subdict)); |
107 | 108 |
108 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 109 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
109 IPC::WriteParam(&msg, input); | 110 IPC::WriteParam(&msg, input); |
110 | 111 |
111 base::DictionaryValue output; | 112 base::DictionaryValue output; |
112 base::PickleIterator iter(msg); | 113 base::PickleIterator iter(msg); |
113 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 114 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
114 | 115 |
115 EXPECT_TRUE(input.Equals(&output)); | 116 EXPECT_TRUE(input.Equals(&output)); |
116 | 117 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 /* TODO: handle sync IPCs | 272 /* TODO: handle sync IPCs |
272 TEST_F(IPCMessageParameterTest, Sync) { | 273 TEST_F(IPCMessageParameterTest, Sync) { |
273 std::string output; | 274 std::string output; |
274 TestMsgClassIS message(42, &output); | 275 TestMsgClassIS message(42, &output); |
275 EXPECT_TRUE(OnMessageReceived(message)); | 276 EXPECT_TRUE(OnMessageReceived(message)); |
276 EXPECT_TRUE(called_); | 277 EXPECT_TRUE(called_); |
277 EXPECT_EQ(output, std::string("out")); | 278 EXPECT_EQ(output, std::string("out")); |
278 }*/ | 279 }*/ |
279 | 280 |
280 } // namespace IPC | 281 } // namespace IPC |
OLD | NEW |