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

Side by Side Diff: ipc/ipc_message_unittest.cc

Issue 155905: Separates ipc code from common (http://crbug.com/16829) (Closed)
Patch Set: Fixes reference to 'common_message_traits' it's actually 'common_param_traits' Created 11 years, 5 months 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
« no previous file with comments | « ipc/ipc_message_macros.h ('k') | ipc/ipc_message_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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.
4
5 #include <string.h>
6
7 #include "base/scoped_ptr.h"
8 #include "base/values.h"
9 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_message_utils.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 TEST(IPCMessageTest, ListValue) {
14 ListValue input;
15 input.Set(0, Value::CreateRealValue(42.42));
16 input.Set(1, Value::CreateStringValue("forty"));
17 input.Set(2, Value::CreateNullValue());
18
19 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
20 IPC::WriteParam(&msg, input);
21
22 ListValue output;
23 void* iter = NULL;
24 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
25
26 EXPECT_TRUE(input.Equals(&output));
27
28 // Also test the corrupt case.
29 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
30 bad_msg.WriteInt(99);
31 iter = NULL;
32 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
33 }
34
35 TEST(IPCMessageTest, DictionaryValue) {
36 DictionaryValue input;
37 input.Set(L"null", Value::CreateNullValue());
38 input.Set(L"bool", Value::CreateBooleanValue(true));
39 input.Set(L"int", Value::CreateIntegerValue(42));
40
41 scoped_ptr<DictionaryValue> subdict(new DictionaryValue());
42 subdict->Set(L"str", Value::CreateStringValue("forty two"));
43 subdict->Set(L"bool", Value::CreateBooleanValue(false));
44
45 scoped_ptr<ListValue> sublist(new ListValue());
46 sublist->Set(0, Value::CreateRealValue(42.42));
47 sublist->Set(1, Value::CreateStringValue("forty"));
48 sublist->Set(2, Value::CreateStringValue("two"));
49 subdict->Set(L"list", sublist.release());
50
51 input.Set(L"dict", subdict.release());
52
53 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
54 IPC::WriteParam(&msg, input);
55
56 DictionaryValue output;
57 void* iter = NULL;
58 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
59
60 EXPECT_TRUE(input.Equals(&output));
61
62 // Also test the corrupt case.
63 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL);
64 bad_msg.WriteInt(99);
65 iter = NULL;
66 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output));
67 }
OLDNEW
« no previous file with comments | « ipc/ipc_message_macros.h ('k') | ipc/ipc_message_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698