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
3 // found in the LICENSE file.
5 #include "ipc/ipc_message.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h"
11 #include "ipc/ipc_message_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 TEST(IPCMessageTest
, ListValue
) {
16 input
.Set(0, Value::CreateDoubleValue(42.42));
17 input
.Set(1, Value::CreateStringValue("forty"));
18 input
.Set(2, Value::CreateNullValue());
20 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
21 IPC::WriteParam(&msg
, input
);
24 PickleIterator
iter(msg
);
25 EXPECT_TRUE(IPC::ReadParam(&msg
, &iter
, &output
));
27 EXPECT_TRUE(input
.Equals(&output
));
29 // Also test the corrupt case.
30 IPC::Message
bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
32 iter
= PickleIterator(bad_msg
);
33 EXPECT_FALSE(IPC::ReadParam(&bad_msg
, &iter
, &output
));
36 TEST(IPCMessageTest
, DictionaryValue
) {
37 DictionaryValue input
;
38 input
.Set("null", Value::CreateNullValue());
39 input
.Set("bool", Value::CreateBooleanValue(true));
40 input
.Set("int", Value::CreateIntegerValue(42));
41 input
.SetWithoutPathExpansion("int.with.dot", Value::CreateIntegerValue(43));
43 scoped_ptr
<DictionaryValue
> subdict(new DictionaryValue());
44 subdict
->Set("str", Value::CreateStringValue("forty two"));
45 subdict
->Set("bool", Value::CreateBooleanValue(false));
47 scoped_ptr
<ListValue
> sublist(new ListValue());
48 sublist
->Set(0, Value::CreateDoubleValue(42.42));
49 sublist
->Set(1, Value::CreateStringValue("forty"));
50 sublist
->Set(2, Value::CreateStringValue("two"));
51 subdict
->Set("list", sublist
.release());
53 input
.Set("dict", subdict
.release());
55 IPC::Message
msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
56 IPC::WriteParam(&msg
, input
);
58 DictionaryValue output
;
59 PickleIterator
iter(msg
);
60 EXPECT_TRUE(IPC::ReadParam(&msg
, &iter
, &output
));
62 EXPECT_TRUE(input
.Equals(&output
));
64 // Also test the corrupt case.
65 IPC::Message
bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL
);
67 iter
= PickleIterator(bad_msg
);
68 EXPECT_FALSE(IPC::ReadParam(&bad_msg
, &iter
, &output
));