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

Unified Diff: dbus/values_util_unittest.cc

Issue 221393004: dbus/values_util.h: Add functions to append collection type values to message. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/values_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « dbus/values_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698