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

Unified Diff: mojo/public/libs/message/message_unittest.cc

Issue 23629032: mojo: MessageBuilder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compilation error. Created 7 years, 3 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 | « mojo/public/libs/message/message_builder.cc ('k') | mojo/public/system/core.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/libs/message/message_unittest.cc
diff --git a/mojo/public/libs/message/message_unittest.cc b/mojo/public/libs/message/message_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..209dee8f06a94f473d31f06c1e6ff7c168e57c85
--- /dev/null
+++ b/mojo/public/libs/message/message_unittest.cc
@@ -0,0 +1,83 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/libs/message/message.h"
+
+#include <string>
+
+#include "mojo/public/libs/message/message_builder.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+
+TEST(Message, Empty) {
+ Message message;
+ EXPECT_EQ(0U, message.data().size());
+}
+
+TEST(Message, Builder_Empty) {
+ MessageBuilder builder;
+ EXPECT_TRUE(builder.Initialize(1));
+
+ Message message;
+ EXPECT_TRUE(builder.Finish(&message));
+
+ EXPECT_EQ(message.data().size(), 8U);
+}
+
+TEST(Message, Builder_Basic) {
+ MessageBuilder builder;
+ EXPECT_TRUE(builder.Initialize(1));
+
+ EXPECT_TRUE(builder.Append(1, 2U));
+
+ Message message;
+ EXPECT_TRUE(builder.Finish(&message));
+
+ EXPECT_EQ(message.data().size(), 8U + 8U);
+}
+
+TEST(Message, Builder_BasicPair) {
+ MessageBuilder builder;
+ EXPECT_TRUE(builder.Initialize(1));
+
+ EXPECT_TRUE(builder.Append(1, 100));
+ EXPECT_TRUE(builder.Append(2, 200));
+
+ Message message;
+ EXPECT_TRUE(builder.Finish(&message));
+
+ EXPECT_EQ(message.data().size(), 8U + 8U + 8U);
+}
+
+TEST(Message, Builder_BasicString) {
+ MessageBuilder builder;
+ EXPECT_TRUE(builder.Initialize(1));
+
+ EXPECT_TRUE(builder.Append(1, 100));
+ EXPECT_TRUE(builder.Append(2, 200));
+ EXPECT_TRUE(builder.Append(3, std::string("hello world")));
+
+ Message message;
+ EXPECT_TRUE(builder.Finish(&message));
+
+ EXPECT_EQ(message.data().size(), 8U + 8U + 8U + 8U + 16U);
+}
+
+TEST(Message, Builder_BasicHandle) {
+ MessageBuilder builder;
+ EXPECT_TRUE(builder.Initialize(1));
+
+ mojo::Handle handle = { 1 };
+
+ EXPECT_TRUE(builder.Append(1, handle));
+
+ Message message;
+ EXPECT_TRUE(builder.Finish(&message));
+
+ EXPECT_EQ(message.data().size(), 8U + 8U);
+ EXPECT_EQ(message.handles().size(), 1U);
+}
+
+} // namespace mojo
« no previous file with comments | « mojo/public/libs/message/message_builder.cc ('k') | mojo/public/system/core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698