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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 TEST(IPCMessageTest, ListValue) { | 29 TEST(IPCMessageTest, ListValue) { |
30 base::ListValue input; | 30 base::ListValue input; |
31 input.Set(0, new base::FundamentalValue(42.42)); | 31 input.Set(0, new base::FundamentalValue(42.42)); |
32 input.Set(1, new base::StringValue("forty")); | 32 input.Set(1, new base::StringValue("forty")); |
33 input.Set(2, base::Value::CreateNullValue()); | 33 input.Set(2, base::Value::CreateNullValue()); |
34 | 34 |
35 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 35 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
36 IPC::WriteParam(&msg, input); | 36 IPC::WriteParam(&msg, input); |
37 | 37 |
38 base::ListValue output; | 38 base::ListValue output; |
39 PickleIterator iter(msg); | 39 base::PickleIterator iter(msg); |
40 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 40 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
41 | 41 |
42 EXPECT_TRUE(input.Equals(&output)); | 42 EXPECT_TRUE(input.Equals(&output)); |
43 | 43 |
44 // Also test the corrupt case. | 44 // Also test the corrupt case. |
45 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 45 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
46 bad_msg.WriteInt(99); | 46 bad_msg.WriteInt(99); |
47 iter = PickleIterator(bad_msg); | 47 iter = base::PickleIterator(bad_msg); |
48 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); | 48 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); |
49 } | 49 } |
50 | 50 |
51 TEST(IPCMessageTest, DictionaryValue) { | 51 TEST(IPCMessageTest, DictionaryValue) { |
52 base::DictionaryValue input; | 52 base::DictionaryValue input; |
53 input.Set("null", base::Value::CreateNullValue()); | 53 input.Set("null", base::Value::CreateNullValue()); |
54 input.Set("bool", new base::FundamentalValue(true)); | 54 input.Set("bool", new base::FundamentalValue(true)); |
55 input.Set("int", new base::FundamentalValue(42)); | 55 input.Set("int", new base::FundamentalValue(42)); |
56 input.SetWithoutPathExpansion("int.with.dot", new base::FundamentalValue(43)); | 56 input.SetWithoutPathExpansion("int.with.dot", new base::FundamentalValue(43)); |
57 | 57 |
58 scoped_ptr<base::DictionaryValue> subdict(new base::DictionaryValue()); | 58 scoped_ptr<base::DictionaryValue> subdict(new base::DictionaryValue()); |
59 subdict->Set("str", new base::StringValue("forty two")); | 59 subdict->Set("str", new base::StringValue("forty two")); |
60 subdict->Set("bool", new base::FundamentalValue(false)); | 60 subdict->Set("bool", new base::FundamentalValue(false)); |
61 | 61 |
62 scoped_ptr<base::ListValue> sublist(new base::ListValue()); | 62 scoped_ptr<base::ListValue> sublist(new base::ListValue()); |
63 sublist->Set(0, new base::FundamentalValue(42.42)); | 63 sublist->Set(0, new base::FundamentalValue(42.42)); |
64 sublist->Set(1, new base::StringValue("forty")); | 64 sublist->Set(1, new base::StringValue("forty")); |
65 sublist->Set(2, new base::StringValue("two")); | 65 sublist->Set(2, new base::StringValue("two")); |
66 subdict->Set("list", sublist.release()); | 66 subdict->Set("list", sublist.release()); |
67 | 67 |
68 input.Set("dict", subdict.release()); | 68 input.Set("dict", subdict.release()); |
69 | 69 |
70 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 70 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
71 IPC::WriteParam(&msg, input); | 71 IPC::WriteParam(&msg, input); |
72 | 72 |
73 base::DictionaryValue output; | 73 base::DictionaryValue output; |
74 PickleIterator iter(msg); | 74 base::PickleIterator iter(msg); |
75 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 75 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
76 | 76 |
77 EXPECT_TRUE(input.Equals(&output)); | 77 EXPECT_TRUE(input.Equals(&output)); |
78 | 78 |
79 // Also test the corrupt case. | 79 // Also test the corrupt case. |
80 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 80 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
81 bad_msg.WriteInt(99); | 81 bad_msg.WriteInt(99); |
82 iter = PickleIterator(bad_msg); | 82 iter = base::PickleIterator(bad_msg); |
83 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); | 83 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); |
84 } | 84 } |
85 | 85 |
86 class IPCMessageParameterTest : public testing::Test { | 86 class IPCMessageParameterTest : public testing::Test { |
87 public: | 87 public: |
88 IPCMessageParameterTest() : extra_param_("extra_param"), called_(false) {} | 88 IPCMessageParameterTest() : extra_param_("extra_param"), called_(false) {} |
89 | 89 |
90 bool OnMessageReceived(const IPC::Message& message) { | 90 bool OnMessageReceived(const IPC::Message& message) { |
91 bool handled = true; | 91 bool handled = true; |
92 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(IPCMessageParameterTest, message, | 92 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(IPCMessageParameterTest, message, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 /* TODO: handle sync IPCs | 143 /* TODO: handle sync IPCs |
144 TEST_F(IPCMessageParameterTest, Sync) { | 144 TEST_F(IPCMessageParameterTest, Sync) { |
145 std::string output; | 145 std::string output; |
146 TestMsgClassIS message(42, &output); | 146 TestMsgClassIS message(42, &output); |
147 EXPECT_TRUE(OnMessageReceived(message)); | 147 EXPECT_TRUE(OnMessageReceived(message)); |
148 EXPECT_TRUE(called_); | 148 EXPECT_TRUE(called_); |
149 EXPECT_EQ(output, std::string("out")); | 149 EXPECT_EQ(output, std::string("out")); |
150 }*/ | 150 }*/ |
151 | 151 |
152 } // namespace | 152 } // namespace |
OLD | NEW |