Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: ipc/ipc_message_unittest.cc

Issue 57783006: Revert https://src.chromium.org/viewvc/chrome?view=rev&revision=231330 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile (cc perftest). Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_message_macros.h ('k') | ipc/ipc_message_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "ipc/ipc_message_utils.h" 11 #include "ipc/ipc_message_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace { 14 namespace {
15 15
16 TEST(IPCMessageTest, ListValue) { 16 TEST(IPCMessageTest, ListValue) {
17 base::ListValue input; 17 base::ListValue input;
18 input.Set(0, new base::FundamentalValue(42.42)); 18 input.Set(0, new base::FundamentalValue(42.42));
19 input.Set(1, new base::StringValue("forty")); 19 input.Set(1, new base::StringValue("forty"));
20 input.Set(2, base::Value::CreateNullValue()); 20 input.Set(2, base::Value::CreateNullValue());
21 21
22 IPC::Message msg(1, 2); 22 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
23 IPC::WriteParam(&msg, input); 23 IPC::WriteParam(&msg, input);
24 24
25 base::ListValue output; 25 base::ListValue output;
26 PickleIterator iter(msg); 26 PickleIterator iter(msg);
27 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); 27 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
28 28
29 EXPECT_TRUE(input.Equals(&output)); 29 EXPECT_TRUE(input.Equals(&output));
30 30
31 // Also test the corrupt case. 31 // Also test the corrupt case.
32 IPC::Message bad_msg(1, 2); 32 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
33 bad_msg.WriteInt(99); 33 bad_msg.WriteInt(99);
34 iter = PickleIterator(bad_msg); 34 iter = PickleIterator(bad_msg);
35 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); 35 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
36 } 36 }
37 37
38 TEST(IPCMessageTest, DictionaryValue) { 38 TEST(IPCMessageTest, DictionaryValue) {
39 base::DictionaryValue input; 39 base::DictionaryValue input;
40 input.Set("null", base::Value::CreateNullValue()); 40 input.Set("null", base::Value::CreateNullValue());
41 input.Set("bool", new base::FundamentalValue(true)); 41 input.Set("bool", new base::FundamentalValue(true));
42 input.Set("int", new base::FundamentalValue(42)); 42 input.Set("int", new base::FundamentalValue(42));
43 input.SetWithoutPathExpansion("int.with.dot", new base::FundamentalValue(43)); 43 input.SetWithoutPathExpansion("int.with.dot", new base::FundamentalValue(43));
44 44
45 scoped_ptr<base::DictionaryValue> subdict(new base::DictionaryValue()); 45 scoped_ptr<base::DictionaryValue> subdict(new base::DictionaryValue());
46 subdict->Set("str", new base::StringValue("forty two")); 46 subdict->Set("str", new base::StringValue("forty two"));
47 subdict->Set("bool", new base::FundamentalValue(false)); 47 subdict->Set("bool", new base::FundamentalValue(false));
48 48
49 scoped_ptr<base::ListValue> sublist(new base::ListValue()); 49 scoped_ptr<base::ListValue> sublist(new base::ListValue());
50 sublist->Set(0, new base::FundamentalValue(42.42)); 50 sublist->Set(0, new base::FundamentalValue(42.42));
51 sublist->Set(1, new base::StringValue("forty")); 51 sublist->Set(1, new base::StringValue("forty"));
52 sublist->Set(2, new base::StringValue("two")); 52 sublist->Set(2, new base::StringValue("two"));
53 subdict->Set("list", sublist.release()); 53 subdict->Set("list", sublist.release());
54 54
55 input.Set("dict", subdict.release()); 55 input.Set("dict", subdict.release());
56 56
57 IPC::Message msg(1, 2); 57 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
58 IPC::WriteParam(&msg, input); 58 IPC::WriteParam(&msg, input);
59 59
60 base::DictionaryValue output; 60 base::DictionaryValue output;
61 PickleIterator iter(msg); 61 PickleIterator iter(msg);
62 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); 62 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
63 63
64 EXPECT_TRUE(input.Equals(&output)); 64 EXPECT_TRUE(input.Equals(&output));
65 65
66 // Also test the corrupt case. 66 // Also test the corrupt case.
67 IPC::Message bad_msg(1, 2); 67 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
68 bad_msg.WriteInt(99); 68 bad_msg.WriteInt(99);
69 iter = PickleIterator(bad_msg); 69 iter = PickleIterator(bad_msg);
70 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); 70 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
71 } 71 }
72 72
73 } // namespace 73 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_message_macros.h ('k') | ipc/ipc_message_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698