| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_ptr.h" | 9 #include "base/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 TEST(IPCMessageTest, ListValue) { | 14 TEST(IPCMessageTest, ListValue) { |
| 15 ListValue input; | 15 ListValue input; |
| 16 input.Set(0, Value::CreateRealValue(42.42)); | 16 input.Set(0, Value::CreateDoubleValue(42.42)); |
| 17 input.Set(1, Value::CreateStringValue("forty")); | 17 input.Set(1, Value::CreateStringValue("forty")); |
| 18 input.Set(2, Value::CreateNullValue()); | 18 input.Set(2, Value::CreateNullValue()); |
| 19 | 19 |
| 20 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 20 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 21 IPC::WriteParam(&msg, input); | 21 IPC::WriteParam(&msg, input); |
| 22 | 22 |
| 23 ListValue output; | 23 ListValue output; |
| 24 void* iter = NULL; | 24 void* iter = NULL; |
| 25 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 25 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
| 26 | 26 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 DictionaryValue input; | 37 DictionaryValue input; |
| 38 input.Set("null", Value::CreateNullValue()); | 38 input.Set("null", Value::CreateNullValue()); |
| 39 input.Set("bool", Value::CreateBooleanValue(true)); | 39 input.Set("bool", Value::CreateBooleanValue(true)); |
| 40 input.Set("int", Value::CreateIntegerValue(42)); | 40 input.Set("int", Value::CreateIntegerValue(42)); |
| 41 | 41 |
| 42 scoped_ptr<DictionaryValue> subdict(new DictionaryValue()); | 42 scoped_ptr<DictionaryValue> subdict(new DictionaryValue()); |
| 43 subdict->Set("str", Value::CreateStringValue("forty two")); | 43 subdict->Set("str", Value::CreateStringValue("forty two")); |
| 44 subdict->Set("bool", Value::CreateBooleanValue(false)); | 44 subdict->Set("bool", Value::CreateBooleanValue(false)); |
| 45 | 45 |
| 46 scoped_ptr<ListValue> sublist(new ListValue()); | 46 scoped_ptr<ListValue> sublist(new ListValue()); |
| 47 sublist->Set(0, Value::CreateRealValue(42.42)); | 47 sublist->Set(0, Value::CreateDoubleValue(42.42)); |
| 48 sublist->Set(1, Value::CreateStringValue("forty")); | 48 sublist->Set(1, Value::CreateStringValue("forty")); |
| 49 sublist->Set(2, Value::CreateStringValue("two")); | 49 sublist->Set(2, Value::CreateStringValue("two")); |
| 50 subdict->Set("list", sublist.release()); | 50 subdict->Set("list", sublist.release()); |
| 51 | 51 |
| 52 input.Set("dict", subdict.release()); | 52 input.Set("dict", subdict.release()); |
| 53 | 53 |
| 54 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 54 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 55 IPC::WriteParam(&msg, input); | 55 IPC::WriteParam(&msg, input); |
| 56 | 56 |
| 57 DictionaryValue output; | 57 DictionaryValue output; |
| 58 void* iter = NULL; | 58 void* iter = NULL; |
| 59 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 59 EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
| 60 | 60 |
| 61 EXPECT_TRUE(input.Equals(&output)); | 61 EXPECT_TRUE(input.Equals(&output)); |
| 62 | 62 |
| 63 // Also test the corrupt case. | 63 // Also test the corrupt case. |
| 64 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 64 IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
| 65 bad_msg.WriteInt(99); | 65 bad_msg.WriteInt(99); |
| 66 iter = NULL; | 66 iter = NULL; |
| 67 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); | 67 EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); |
| 68 } | 68 } |
| OLD | NEW |