diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-24 20:37:18 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-24 20:37:18 +0000 |
commit | 6e04d17161b8d53770979fb5a451da8174e255c6 (patch) | |
tree | 3ca941138578159e4059e52f94a105c1242ed609 /dbus/values_util_unittest.cc | |
parent | ffd60e434c0dff91d8cb9251c08d901b12346b2a (diff) | |
download | chromium_src-6e04d17161b8d53770979fb5a451da8174e255c6.zip chromium_src-6e04d17161b8d53770979fb5a451da8174e255c6.tar.gz chromium_src-6e04d17161b8d53770979fb5a451da8174e255c6.tar.bz2 |
Add dbus::AppendBasicTypeValueData
BUG=chromium-os:16557
TEST=dbus_unittests --gtest_filter="ValuesUtilTest.Append*"
Review URL: http://codereview.chromium.org/9826044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128771 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/values_util_unittest.cc')
-rw-r--r-- | dbus/values_util_unittest.cc | 106 |
1 files changed, 82 insertions, 24 deletions
diff --git a/dbus/values_util_unittest.cc b/dbus/values_util_unittest.cc index f97c55a..9dca3ee 100644 --- a/dbus/values_util_unittest.cc +++ b/dbus/values_util_unittest.cc @@ -46,51 +46,51 @@ TEST(ValuesUtilTest, PopBasicTypes) { scoped_ptr<Value> value; // Pop a byte. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateIntegerValue(kByteValue))); // Pop a bool. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateBooleanValue(kBoolValue))); // Pop an int16. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateIntegerValue(kInt16Value))); // Pop a uint16. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateIntegerValue(kUint16Value))); // Pop an int32. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateIntegerValue(kInt32Value))); // Pop a uint32. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateDoubleValue(kUint32Value))); // Pop an int64. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateDoubleValue(kInt64Value))); // Pop a uint64. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateDoubleValue(kUint64Value))); // Pop a double. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateDoubleValue(kDoubleValue))); // Pop a string. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateStringValue(kStringValue))); // Pop an empty string. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateStringValue(kEmptyStringValue))); // Pop an object path. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE( value->Equals(Value::CreateStringValue(kObjectPathValue.value()))); } @@ -112,19 +112,19 @@ TEST(ValuesUtilTest, PopVariant) { scoped_ptr<Value> value; // Pop a bool. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateBooleanValue(kBoolValue))); // Pop an int32. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateIntegerValue(kInt32Value))); // Pop a double. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateDoubleValue(kDoubleValue))); // Pop a string. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateStringValue(kStringValue))); } @@ -144,13 +144,13 @@ TEST(ValuesUtilTest, PopExtremelyLargeIntegers) { double double_value = 0; // Pop an int64. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateDoubleValue(kInt64Value))); ASSERT_TRUE(value->GetAsDouble(&double_value)); EXPECT_NE(kInt64Value, static_cast<int64>(double_value)); // Pop a uint64. value.reset(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(Value::CreateDoubleValue(kUint64Value))); ASSERT_TRUE(value->GetAsDouble(&double_value)); EXPECT_NE(kUint64Value, static_cast<uint64>(double_value)); @@ -178,7 +178,7 @@ TEST(ValuesUtilTest, PopIntArray) { // Pop an int32 array. dbus::MessageReader reader(response.get()); scoped_ptr<Value> value(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(list_value)); } @@ -201,7 +201,7 @@ TEST(ValuesUtilTest, PopStringArray) { // Pop a string array. dbus::MessageReader reader(response.get()); scoped_ptr<Value> value(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(list_value)); } @@ -231,7 +231,7 @@ TEST(ValuesUtilTest, PopStruct) { // Pop a struct. dbus::MessageReader reader(response.get()); scoped_ptr<Value> value(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&list_value)); } @@ -278,7 +278,7 @@ TEST(ValuesUtilTest, PopStringToVariantDictionary) { // Pop a dictinoary. dbus::MessageReader reader(response.get()); scoped_ptr<Value> value(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&dictionary_value)); } @@ -321,7 +321,7 @@ TEST(ValuesUtilTest, PopDictionaryWithDottedStringKey) { // Pop a dictinoary. dbus::MessageReader reader(response.get()); scoped_ptr<Value> value(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&dictionary_value)); } @@ -360,6 +360,64 @@ TEST(ValuesUtilTest, PopDoubleToIntDictionary) { // Pop a dictionary. dbus::MessageReader reader(response.get()); scoped_ptr<Value> value(dbus::PopDataAsValue(&reader)); - EXPECT_TRUE(value.get() != NULL); + ASSERT_TRUE(value.get() != NULL); EXPECT_TRUE(value->Equals(&dictionary_value)); } + +TEST(ValuesUtilTest, AppendBasicTypes) { + const base::FundamentalValue kBoolValue(false); + const base::FundamentalValue kIntegerValue(42); + const base::FundamentalValue kDoubleValue(4.2); + const base::StringValue kStringValue("string"); + + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + dbus::MessageWriter writer(response.get()); + AppendBasicTypeValueData(&writer, kBoolValue); + AppendBasicTypeValueData(&writer, kIntegerValue); + AppendBasicTypeValueData(&writer, kDoubleValue); + AppendBasicTypeValueData(&writer, kStringValue); + + dbus::MessageReader reader(response.get()); + scoped_ptr<Value> value; + value.reset(dbus::PopDataAsValue(&reader)); + ASSERT_TRUE(value.get() != NULL); + EXPECT_TRUE(value->Equals(&kBoolValue)); + value.reset(dbus::PopDataAsValue(&reader)); + ASSERT_TRUE(value.get() != NULL); + EXPECT_TRUE(value->Equals(&kIntegerValue)); + value.reset(dbus::PopDataAsValue(&reader)); + ASSERT_TRUE(value.get() != NULL); + EXPECT_TRUE(value->Equals(&kDoubleValue)); + value.reset(dbus::PopDataAsValue(&reader)); + ASSERT_TRUE(value.get() != NULL); + EXPECT_TRUE(value->Equals(&kStringValue)); +} + +TEST(ValuesUtilTest, AppendBasicTypesAsVariant) { + const base::FundamentalValue kBoolValue(false); + const base::FundamentalValue kIntegerValue(42); + const base::FundamentalValue kDoubleValue(4.2); + const base::StringValue kStringValue("string"); + + scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); + dbus::MessageWriter writer(response.get()); + AppendBasicTypeValueDataAsVariant(&writer, kBoolValue); + AppendBasicTypeValueDataAsVariant(&writer, kIntegerValue); + AppendBasicTypeValueDataAsVariant(&writer, kDoubleValue); + AppendBasicTypeValueDataAsVariant(&writer, kStringValue); + + dbus::MessageReader reader(response.get()); + scoped_ptr<Value> value; + value.reset(dbus::PopDataAsValue(&reader)); + ASSERT_TRUE(value.get() != NULL); + EXPECT_TRUE(value->Equals(&kBoolValue)); + value.reset(dbus::PopDataAsValue(&reader)); + ASSERT_TRUE(value.get() != NULL); + EXPECT_TRUE(value->Equals(&kIntegerValue)); + value.reset(dbus::PopDataAsValue(&reader)); + ASSERT_TRUE(value.get() != NULL); + EXPECT_TRUE(value->Equals(&kDoubleValue)); + value.reset(dbus::PopDataAsValue(&reader)); + ASSERT_TRUE(value.get() != NULL); + EXPECT_TRUE(value->Equals(&kStringValue)); +} |