Chromium Code Reviews| Index: dbus/values_util_unittest.cc |
| diff --git a/dbus/values_util_unittest.cc b/dbus/values_util_unittest.cc |
| index 2de12d793ad45e7de75bbee835af1d3405c57099..53b1980de1b41ec59534634a47d58b8c42dcbc42 100644 |
| --- a/dbus/values_util_unittest.cc |
| +++ b/dbus/values_util_unittest.cc |
| @@ -449,4 +449,164 @@ TEST(ValuesUtilTest, AppendBasicTypesAsVariant) { |
| EXPECT_TRUE(value->Equals(&kStringValue)); |
| } |
| +TEST(ValuesUtilTest, AppendDictionary) { |
|
keybuk
2014/04/03 16:32:23
You need test cases for the basic values too
armansito
2014/04/03 17:20:05
Done.
|
| + // Set up the input dictionary. |
| + const std::string kKey1 = "one"; |
| + const std::string kKey2 = "two"; |
| + const std::string kKey3 = "three"; |
| + const std::string kKey4 = "four"; |
| + const std::string kKey5 = "five"; |
| + const std::string kKey6 = "six"; |
| + |
| + const bool kBoolValue = true; |
| + const int32 kInt32Value = -45; |
| + const double kDoubleValue = 4.9; |
| + const std::string kStringValue = "fifty"; |
| + |
| + base::ListValue* list_value = new base::ListValue(); |
| + list_value->AppendBoolean(kBoolValue); |
| + list_value->AppendInteger(kInt32Value); |
| + |
| + base::DictionaryValue* dictionary_value = new base::DictionaryValue(); |
| + dictionary_value->SetBoolean(kKey1, kBoolValue); |
| + dictionary_value->SetInteger(kKey2, kDoubleValue); |
| + |
| + base::DictionaryValue test_dictionary; |
| + test_dictionary.SetBoolean(kKey1, kBoolValue); |
| + test_dictionary.SetInteger(kKey2, kInt32Value); |
| + test_dictionary.SetDouble(kKey3, kDoubleValue); |
| + test_dictionary.SetString(kKey4, kStringValue); |
| + test_dictionary.Set(kKey5, list_value); // takes ownership |
| + test_dictionary.Set(kKey6, dictionary_value); // takes ownership |
| + |
| + scoped_ptr<Response> response(Response::CreateEmpty()); |
| + MessageWriter writer(response.get()); |
| + AppendValueData(&writer, test_dictionary); |
| + |
| + // Read the data. |
| + MessageReader reader(response.get()); |
| + scoped_ptr<base::Value> value; |
| + value.reset(PopDataAsValue(&reader)); |
| + ASSERT_TRUE(value.get() != NULL); |
| + EXPECT_TRUE(value->Equals(&test_dictionary)); |
| +} |
| + |
| +TEST(ValuesUtilTest, AppendDictionaryAsVariant) { |
| + // Set up the input dictionary. |
| + const std::string kKey1 = "one"; |
| + const std::string kKey2 = "two"; |
| + const std::string kKey3 = "three"; |
| + const std::string kKey4 = "four"; |
| + const std::string kKey5 = "five"; |
| + const std::string kKey6 = "six"; |
| + |
| + const bool kBoolValue = true; |
| + const int32 kInt32Value = -45; |
| + const double kDoubleValue = 4.9; |
| + const std::string kStringValue = "fifty"; |
| + |
| + base::ListValue* list_value = new base::ListValue(); |
| + list_value->AppendBoolean(kBoolValue); |
| + list_value->AppendInteger(kInt32Value); |
| + |
| + base::DictionaryValue* dictionary_value = new base::DictionaryValue(); |
| + dictionary_value->SetBoolean(kKey1, kBoolValue); |
| + dictionary_value->SetInteger(kKey2, kDoubleValue); |
| + |
| + base::DictionaryValue test_dictionary; |
| + test_dictionary.SetBoolean(kKey1, kBoolValue); |
| + test_dictionary.SetInteger(kKey2, kInt32Value); |
| + test_dictionary.SetDouble(kKey3, kDoubleValue); |
| + test_dictionary.SetString(kKey4, kStringValue); |
| + test_dictionary.Set(kKey5, list_value); // takes ownership |
| + test_dictionary.Set(kKey6, dictionary_value); // takes ownership |
| + |
| + scoped_ptr<Response> response(Response::CreateEmpty()); |
| + MessageWriter writer(response.get()); |
| + AppendValueDataAsVariant(&writer, test_dictionary); |
| + |
| + // Read the data. |
| + MessageReader reader(response.get()); |
| + scoped_ptr<base::Value> value; |
| + value.reset(PopDataAsValue(&reader)); |
| + ASSERT_TRUE(value.get() != NULL); |
| + EXPECT_TRUE(value->Equals(&test_dictionary)); |
| +} |
| + |
| +TEST(ValuesUtilTest, AppendList) { |
| + // Set up the input list. |
| + const std::string kKey1 = "one"; |
| + const std::string kKey2 = "two"; |
| + |
| + const bool kBoolValue = true; |
| + const int32 kInt32Value = -45; |
| + const double kDoubleValue = 4.9; |
| + const std::string kStringValue = "fifty"; |
| + |
| + base::ListValue* list_value = new base::ListValue(); |
| + list_value->AppendBoolean(kBoolValue); |
| + list_value->AppendInteger(kInt32Value); |
| + |
| + base::DictionaryValue* dictionary_value = new base::DictionaryValue(); |
| + dictionary_value->SetBoolean(kKey1, kBoolValue); |
| + dictionary_value->SetInteger(kKey2, kDoubleValue); |
| + |
| + base::ListValue test_list; |
| + test_list.AppendBoolean(kBoolValue); |
| + test_list.AppendInteger(kInt32Value); |
| + test_list.AppendDouble(kDoubleValue); |
| + test_list.AppendString(kStringValue); |
| + test_list.Append(list_value); // takes ownership |
| + test_list.Append(dictionary_value); // takes ownership |
| + |
| + scoped_ptr<Response> response(Response::CreateEmpty()); |
| + MessageWriter writer(response.get()); |
| + AppendValueData(&writer, test_list); |
| + |
| + // Read the data. |
| + MessageReader reader(response.get()); |
| + scoped_ptr<base::Value> value; |
| + value.reset(PopDataAsValue(&reader)); |
| + ASSERT_TRUE(value.get() != NULL); |
| + EXPECT_TRUE(value->Equals(&test_list)); |
| +} |
| + |
| +TEST(ValuesUtilTest, AppendListAsVariant) { |
| + // Set up the input list. |
| + const std::string kKey1 = "one"; |
| + const std::string kKey2 = "two"; |
| + |
| + const bool kBoolValue = true; |
| + const int32 kInt32Value = -45; |
| + const double kDoubleValue = 4.9; |
| + const std::string kStringValue = "fifty"; |
| + |
| + base::ListValue* list_value = new base::ListValue(); |
| + list_value->AppendBoolean(kBoolValue); |
| + list_value->AppendInteger(kInt32Value); |
| + |
| + base::DictionaryValue* dictionary_value = new base::DictionaryValue(); |
| + dictionary_value->SetBoolean(kKey1, kBoolValue); |
| + dictionary_value->SetInteger(kKey2, kDoubleValue); |
| + |
| + base::ListValue test_list; |
| + test_list.AppendBoolean(kBoolValue); |
| + test_list.AppendInteger(kInt32Value); |
| + test_list.AppendDouble(kDoubleValue); |
| + test_list.AppendString(kStringValue); |
| + test_list.Append(list_value); // takes ownership |
| + test_list.Append(dictionary_value); // takes ownership |
| + |
| + scoped_ptr<Response> response(Response::CreateEmpty()); |
| + MessageWriter writer(response.get()); |
| + AppendValueDataAsVariant(&writer, test_list); |
| + |
| + // Read the data. |
| + MessageReader reader(response.get()); |
| + scoped_ptr<base::Value> value; |
| + value.reset(PopDataAsValue(&reader)); |
| + ASSERT_TRUE(value.get() != NULL); |
| + EXPECT_TRUE(value->Equals(&test_list)); |
| +} |
| + |
| } // namespace dbus |