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

Unified Diff: ipc/ipc_message_utils_unittest.cc

Issue 2098823003: Add IPC serialization support for base::Optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comment Created 4 years, 6 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 | « ipc/ipc_message_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_message_utils_unittest.cc
diff --git a/ipc/ipc_message_utils_unittest.cc b/ipc/ipc_message_utils_unittest.cc
index 7b77c52d563cc8f4da34a7ea5e48b3bce4202657..8ad690dfb4d82664c2f15e8e3b1676ea64bea422 100644
--- a/ipc/ipc_message_utils_unittest.cc
+++ b/ipc/ipc_message_utils_unittest.cc
@@ -158,5 +158,46 @@ TEST(IPCMessageUtilsTest, MojoChannelHandle) {
EXPECT_EQ(channel_handle.mojo_handle, result_handle.mojo_handle);
}
+TEST(IPCMessageUtilsTest, OptionalUnset) {
+ base::Optional<int> opt;
+ base::Pickle pickle;
+ IPC::WriteParam(&pickle, opt);
+
+ base::PickleSizer sizer;
+ IPC::GetParamSize(&sizer, opt);
+
+ EXPECT_EQ(sizer.payload_size(), pickle.payload_size());
+
+ std::string log;
+ IPC::LogParam(opt, &log);
+ EXPECT_EQ("(unset)", log);
+
+ base::Optional<int> unserialized_opt;
+ base::PickleIterator iter(pickle);
+ EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &unserialized_opt));
+ EXPECT_FALSE(unserialized_opt);
+}
+
+TEST(IPCMessageUtilsTest, OptionalSet) {
+ base::Optional<int> opt(10);
+ base::Pickle pickle;
+ IPC::WriteParam(&pickle, opt);
+
+ base::PickleSizer sizer;
+ IPC::GetParamSize(&sizer, opt);
+
+ EXPECT_EQ(sizer.payload_size(), pickle.payload_size());
+
+ std::string log;
+ IPC::LogParam(opt, &log);
+ EXPECT_EQ("10", log);
+
+ base::Optional<int> unserialized_opt;
+ base::PickleIterator iter(pickle);
+ EXPECT_TRUE(IPC::ReadParam(&pickle, &iter, &unserialized_opt));
+ EXPECT_TRUE(unserialized_opt);
+ EXPECT_EQ(opt.value(), unserialized_opt.value());
+}
+
} // namespace
} // namespace IPC
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698