Make touch-resizing windows to screen edge possible
[chromium-blink-merge.git] / ipc / ipc_message_unittest.cc
blob971314a290c06414722135ca08b281f419ca1ee8
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"
7 #include <string.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 namespace {
16 TEST(IPCMessageTest, ListValue) {
17 base::ListValue input;
18 input.Set(0, new base::FundamentalValue(42.42));
19 input.Set(1, new base::StringValue("forty"));
20 input.Set(2, base::Value::CreateNullValue());
22 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
23 IPC::WriteParam(&msg, input);
25 base::ListValue output;
26 PickleIterator iter(msg);
27 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
29 EXPECT_TRUE(input.Equals(&output));
31 // Also test the corrupt case.
32 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
33 bad_msg.WriteInt(99);
34 iter = PickleIterator(bad_msg);
35 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
38 TEST(IPCMessageTest, DictionaryValue) {
39 base::DictionaryValue input;
40 input.Set("null", base::Value::CreateNullValue());
41 input.Set("bool", new base::FundamentalValue(true));
42 input.Set("int", new base::FundamentalValue(42));
43 input.SetWithoutPathExpansion("int.with.dot", new base::FundamentalValue(43));
45 scoped_ptr<base::DictionaryValue> subdict(new base::DictionaryValue());
46 subdict->Set("str", new base::StringValue("forty two"));
47 subdict->Set("bool", new base::FundamentalValue(false));
49 scoped_ptr<base::ListValue> sublist(new base::ListValue());
50 sublist->Set(0, new base::FundamentalValue(42.42));
51 sublist->Set(1, new base::StringValue("forty"));
52 sublist->Set(2, new base::StringValue("two"));
53 subdict->Set("list", sublist.release());
55 input.Set("dict", subdict.release());
57 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
58 IPC::WriteParam(&msg, input);
60 base::DictionaryValue output;
61 PickleIterator iter(msg);
62 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
64 EXPECT_TRUE(input.Equals(&output));
66 // Also test the corrupt case.
67 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
68 bad_msg.WriteInt(99);
69 iter = PickleIterator(bad_msg);
70 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
73 } // namespace