summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dbus/values_util.cc43
-rw-r--r--dbus/values_util_unittest.cc104
2 files changed, 76 insertions, 71 deletions
diff --git a/dbus/values_util.cc b/dbus/values_util.cc
index ccd7651..2e2d8e3 100644
--- a/dbus/values_util.cc
+++ b/dbus/values_util.cc
@@ -21,9 +21,9 @@ bool IsExactlyRepresentableByDouble(T value) {
}
// Pops values from |reader| and appends them to |list_value|.
-bool PopListElements(MessageReader* reader, ListValue* list_value) {
+bool PopListElements(MessageReader* reader, base::ListValue* list_value) {
while (reader->HasMoreData()) {
- Value* element_value = PopDataAsValue(reader);
+ base::Value* element_value = PopDataAsValue(reader);
if (!element_value)
return false;
list_value->Append(element_value);
@@ -33,7 +33,7 @@ bool PopListElements(MessageReader* reader, ListValue* list_value) {
// Pops dict-entries from |reader| and sets them to |dictionary_value|
bool PopDictionaryEntries(MessageReader* reader,
- DictionaryValue* dictionary_value) {
+ base::DictionaryValue* dictionary_value) {
while (reader->HasMoreData()) {
DCHECK_EQ(Message::DICT_ENTRY, reader->GetDataType());
MessageReader entry_reader(NULL);
@@ -47,14 +47,14 @@ bool PopDictionaryEntries(MessageReader* reader,
return false;
} else {
// If the type of keys is not STRING, convert it to string.
- scoped_ptr<Value> key(PopDataAsValue(&entry_reader));
+ scoped_ptr<base::Value> key(PopDataAsValue(&entry_reader));
if (!key.get())
return false;
// Use JSONWriter to convert an arbitrary value to a string.
base::JSONWriter::Write(key.get(), &key_string);
}
// Get the value and set the key-value pair.
- Value* value = PopDataAsValue(&entry_reader);
+ base::Value* value = PopDataAsValue(&entry_reader);
if (!value)
return false;
dictionary_value->SetWithoutPathExpansion(key_string, value);
@@ -85,8 +85,8 @@ std::string GetTypeSignature(const base::Value& value) {
} // namespace
-Value* PopDataAsValue(MessageReader* reader) {
- Value* result = NULL;
+base::Value* PopDataAsValue(MessageReader* reader) {
+ base::Value* result = NULL;
switch (reader->GetDataType()) {
case Message::INVALID_DATA:
// Do nothing.
@@ -94,37 +94,37 @@ Value* PopDataAsValue(MessageReader* reader) {
case Message::BYTE: {
uint8 value = 0;
if (reader->PopByte(&value))
- result = Value::CreateIntegerValue(value);
+ result = new base::FundamentalValue(value);
break;
}
case Message::BOOL: {
bool value = false;
if (reader->PopBool(&value))
- result = Value::CreateBooleanValue(value);
+ result = new base::FundamentalValue(value);
break;
}
case Message::INT16: {
int16 value = 0;
if (reader->PopInt16(&value))
- result = Value::CreateIntegerValue(value);
+ result = new base::FundamentalValue(value);
break;
}
case Message::UINT16: {
uint16 value = 0;
if (reader->PopUint16(&value))
- result = Value::CreateIntegerValue(value);
+ result = new base::FundamentalValue(value);
break;
}
case Message::INT32: {
int32 value = 0;
if (reader->PopInt32(&value))
- result = Value::CreateIntegerValue(value);
+ result = new base::FundamentalValue(value);
break;
}
case Message::UINT32: {
uint32 value = 0;
if (reader->PopUint32(&value))
- result = Value::CreateDoubleValue(value);
+ result = new base::FundamentalValue(static_cast<double>(value));
break;
}
case Message::INT64: {
@@ -132,7 +132,7 @@ Value* PopDataAsValue(MessageReader* reader) {
if (reader->PopInt64(&value)) {
DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) <<
value << " is not exactly representable by double";
- result = Value::CreateDoubleValue(value);
+ result = new base::FundamentalValue(static_cast<double>(value));
}
break;
}
@@ -141,26 +141,26 @@ Value* PopDataAsValue(MessageReader* reader) {
if (reader->PopUint64(&value)) {
DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) <<
value << " is not exactly representable by double";
- result = Value::CreateDoubleValue(value);
+ result = new base::FundamentalValue(static_cast<double>(value));
}
break;
}
case Message::DOUBLE: {
double value = 0;
if (reader->PopDouble(&value))
- result = Value::CreateDoubleValue(value);
+ result = new base::FundamentalValue(value);
break;
}
case Message::STRING: {
std::string value;
if (reader->PopString(&value))
- result = Value::CreateStringValue(value);
+ result = new base::StringValue(value);
break;
}
case Message::OBJECT_PATH: {
ObjectPath value;
if (reader->PopObjectPath(&value))
- result = Value::CreateStringValue(value.value());
+ result = new base::StringValue(value.value());
break;
}
case Message::UNIX_FD: {
@@ -174,11 +174,12 @@ Value* PopDataAsValue(MessageReader* reader) {
// If the type of the array's element is DICT_ENTRY, create a
// DictionaryValue, otherwise create a ListValue.
if (sub_reader.GetDataType() == Message::DICT_ENTRY) {
- scoped_ptr<DictionaryValue> dictionary_value(new DictionaryValue);
+ scoped_ptr<base::DictionaryValue> dictionary_value(
+ new base::DictionaryValue);
if (PopDictionaryEntries(&sub_reader, dictionary_value.get()))
result = dictionary_value.release();
} else {
- scoped_ptr<ListValue> list_value(new ListValue);
+ scoped_ptr<base::ListValue> list_value(new base::ListValue);
if (PopListElements(&sub_reader, list_value.get()))
result = list_value.release();
}
@@ -188,7 +189,7 @@ Value* PopDataAsValue(MessageReader* reader) {
case Message::STRUCT: {
MessageReader sub_reader(NULL);
if (reader->PopStruct(&sub_reader)) {
- scoped_ptr<ListValue> list_value(new ListValue);
+ scoped_ptr<base::ListValue> list_value(new base::ListValue);
if (PopListElements(&sub_reader, list_value.get()))
result = list_value.release();
}
diff --git a/dbus/values_util_unittest.cc b/dbus/values_util_unittest.cc
index eef60a6..9e98bb9 100644
--- a/dbus/values_util_unittest.cc
+++ b/dbus/values_util_unittest.cc
@@ -43,68 +43,70 @@ TEST(ValuesUtilTest, PopBasicTypes) {
writer.AppendObjectPath(kObjectPathValue);
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value;
- scoped_ptr<Value> expected_value;
+ scoped_ptr<base::Value> value;
+ scoped_ptr<base::Value> expected_value;
// Pop a byte.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateIntegerValue(kByteValue));
+ expected_value.reset(new base::FundamentalValue(kByteValue));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop a bool.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateBooleanValue(kBoolValue));
+ expected_value.reset(new base::FundamentalValue(kBoolValue));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop an int16.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateIntegerValue(kInt16Value));
+ expected_value.reset(new base::FundamentalValue(kInt16Value));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop a uint16.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateIntegerValue(kUint16Value));
+ expected_value.reset(new base::FundamentalValue(kUint16Value));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop an int32.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateIntegerValue(kInt32Value));
+ expected_value.reset(new base::FundamentalValue(kInt32Value));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop a uint32.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateDoubleValue(kUint32Value));
+ expected_value.reset(
+ new base::FundamentalValue(static_cast<double>(kUint32Value)));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop an int64.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateDoubleValue(kInt64Value));
+ expected_value.reset(
+ new base::FundamentalValue(static_cast<double>(kInt64Value)));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop a uint64.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateDoubleValue(kUint64Value));
+ expected_value.reset(
+ new base::FundamentalValue(static_cast<double>(kUint64Value)));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop a double.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateDoubleValue(kDoubleValue));
+ expected_value.reset(new base::FundamentalValue(kDoubleValue));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop a string.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateStringValue(kStringValue));
+ expected_value.reset(new base::StringValue(kStringValue));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop an empty string.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateStringValue(kEmptyStringValue));
+ expected_value.reset(new base::StringValue(kEmptyStringValue));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop an object path.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateStringValue(
- kObjectPathValue.value()));
+ expected_value.reset(new base::StringValue(kObjectPathValue.value()));
EXPECT_TRUE(value->Equals(expected_value.get()));
}
@@ -122,27 +124,27 @@ TEST(ValuesUtilTest, PopVariant) {
writer.AppendVariantOfString(kStringValue);
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value;
- scoped_ptr<Value> expected_value;
+ scoped_ptr<base::Value> value;
+ scoped_ptr<base::Value> expected_value;
// Pop a bool.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateBooleanValue(kBoolValue));
+ expected_value.reset(new base::FundamentalValue(kBoolValue));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop an int32.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateIntegerValue(kInt32Value));
+ expected_value.reset(new base::FundamentalValue(kInt32Value));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop a double.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateDoubleValue(kDoubleValue));
+ expected_value.reset(new base::FundamentalValue(kDoubleValue));
EXPECT_TRUE(value->Equals(expected_value.get()));
// Pop a string.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateStringValue(kStringValue));
+ expected_value.reset(new base::StringValue(kStringValue));
EXPECT_TRUE(value->Equals(expected_value.get()));
}
@@ -158,20 +160,22 @@ TEST(ValuesUtilTest, PopExtremelyLargeIntegers) {
writer.AppendUint64(kUint64Value);
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value;
- scoped_ptr<Value> expected_value;
+ scoped_ptr<base::Value> value;
+ scoped_ptr<base::Value> expected_value;
double double_value = 0;
// Pop an int64.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateDoubleValue(kInt64Value));
+ expected_value.reset(
+ new base::FundamentalValue(static_cast<double>(kInt64Value)));
EXPECT_TRUE(value->Equals(expected_value.get()));
ASSERT_TRUE(value->GetAsDouble(&double_value));
EXPECT_NE(kInt64Value, static_cast<int64>(double_value));
// Pop a uint64.
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
- expected_value.reset(Value::CreateDoubleValue(kUint64Value));
+ expected_value.reset(
+ new base::FundamentalValue(static_cast<double>(kUint64Value)));
EXPECT_TRUE(value->Equals(expected_value.get()));
ASSERT_TRUE(value->GetAsDouble(&double_value));
EXPECT_NE(kUint64Value, static_cast<uint64>(double_value));
@@ -192,13 +196,13 @@ TEST(ValuesUtilTest, PopIntArray) {
writer.CloseContainer(&sub_writer);
// Create the expected value.
- scoped_ptr<ListValue> list_value(new ListValue);
+ scoped_ptr<base::ListValue> list_value(new base::ListValue);
for (size_t i = 0; i != data.size(); ++i)
- list_value->Append(Value::CreateIntegerValue(data[i]));
+ list_value->Append(new base::FundamentalValue(data[i]));
// Pop an int32 array.
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value(dbus::PopDataAsValue(&reader));
+ scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
EXPECT_TRUE(value->Equals(list_value.get()));
}
@@ -215,13 +219,13 @@ TEST(ValuesUtilTest, PopStringArray) {
writer.AppendArrayOfStrings(data);
// Create the expected value.
- scoped_ptr<ListValue> list_value(new ListValue);
+ scoped_ptr<base::ListValue> list_value(new base::ListValue);
for (size_t i = 0; i != data.size(); ++i)
- list_value->Append(Value::CreateStringValue(data[i]));
+ list_value->Append(new base::StringValue(data[i]));
// Pop a string array.
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value(dbus::PopDataAsValue(&reader));
+ scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
EXPECT_TRUE(value->Equals(list_value.get()));
}
@@ -243,15 +247,15 @@ TEST(ValuesUtilTest, PopStruct) {
writer.CloseContainer(&sub_writer);
// Create the expected value.
- ListValue list_value;
- list_value.Append(Value::CreateBooleanValue(kBoolValue));
- list_value.Append(Value::CreateIntegerValue(kInt32Value));
- list_value.Append(Value::CreateDoubleValue(kDoubleValue));
- list_value.Append(Value::CreateStringValue(kStringValue));
+ base::ListValue list_value;
+ list_value.Append(new base::FundamentalValue(kBoolValue));
+ list_value.Append(new base::FundamentalValue(kInt32Value));
+ list_value.Append(new base::FundamentalValue(kDoubleValue));
+ list_value.Append(new base::StringValue(kStringValue));
// Pop a struct.
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value(dbus::PopDataAsValue(&reader));
+ scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
EXPECT_TRUE(value->Equals(&list_value));
}
@@ -290,7 +294,7 @@ TEST(ValuesUtilTest, PopStringToVariantDictionary) {
writer.CloseContainer(&sub_writer);
// Create the expected value.
- DictionaryValue dictionary_value;
+ base::DictionaryValue dictionary_value;
dictionary_value.SetBoolean(kKey1, kBoolValue);
dictionary_value.SetInteger(kKey2, kInt32Value);
dictionary_value.SetDouble(kKey3, kDoubleValue);
@@ -298,7 +302,7 @@ TEST(ValuesUtilTest, PopStringToVariantDictionary) {
// Pop a dictinoary.
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value(dbus::PopDataAsValue(&reader));
+ scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
EXPECT_TRUE(value->Equals(&dictionary_value));
}
@@ -331,17 +335,17 @@ TEST(ValuesUtilTest, PopDictionaryWithDottedStringKey) {
writer.CloseContainer(&sub_writer);
// Create the expected value.
- DictionaryValue dictionary_value;
+ base::DictionaryValue dictionary_value;
dictionary_value.SetWithoutPathExpansion(
- kKey1, Value::CreateBooleanValue(kBoolValue));
+ kKey1, new base::FundamentalValue(kBoolValue));
dictionary_value.SetWithoutPathExpansion(
- kKey2, Value::CreateIntegerValue(kInt32Value));
+ kKey2, new base::FundamentalValue(kInt32Value));
dictionary_value.SetWithoutPathExpansion(
- kKey3, Value::CreateDoubleValue(kDoubleValue));
+ kKey3, new base::FundamentalValue(kDoubleValue));
// Pop a dictinoary.
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value(dbus::PopDataAsValue(&reader));
+ scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
EXPECT_TRUE(value->Equals(&dictionary_value));
}
@@ -369,18 +373,18 @@ TEST(ValuesUtilTest, PopDoubleToIntDictionary) {
writer.CloseContainer(&sub_writer);
// Create the expected value.
- DictionaryValue dictionary_value;
+ base::DictionaryValue dictionary_value;
for (size_t i = 0; i != values.size(); ++i) {
- scoped_ptr<Value> key_value(Value::CreateDoubleValue(keys[i]));
+ scoped_ptr<base::Value> key_value(new base::FundamentalValue(keys[i]));
std::string key_string;
base::JSONWriter::Write(key_value.get(), &key_string);
dictionary_value.SetWithoutPathExpansion(
- key_string, Value::CreateIntegerValue(values[i]));
+ key_string, new base::FundamentalValue(values[i]));
}
// Pop a dictionary.
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value(dbus::PopDataAsValue(&reader));
+ scoped_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
EXPECT_TRUE(value->Equals(&dictionary_value));
}
@@ -399,7 +403,7 @@ TEST(ValuesUtilTest, AppendBasicTypes) {
AppendBasicTypeValueData(&writer, kStringValue);
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value;
+ scoped_ptr<base::Value> value;
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
EXPECT_TRUE(value->Equals(&kBoolValue));
@@ -428,7 +432,7 @@ TEST(ValuesUtilTest, AppendBasicTypesAsVariant) {
AppendBasicTypeValueDataAsVariant(&writer, kStringValue);
dbus::MessageReader reader(response.get());
- scoped_ptr<Value> value;
+ scoped_ptr<base::Value> value;
value.reset(dbus::PopDataAsValue(&reader));
ASSERT_TRUE(value.get() != NULL);
EXPECT_TRUE(value->Equals(&kBoolValue));