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

Unified Diff: mojo/public/cpp/bindings/tests/array_unittest.cc

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more Created 6 years, 7 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
Index: mojo/public/cpp/bindings/tests/array_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/array_unittest.cc b/mojo/public/cpp/bindings/tests/array_unittest.cc
index 4bef4cd57001916be97b21a5f12540a47f7578aa..75eceb641de7ea11cbc5bef828ffdc96b48bfffa 100644
--- a/mojo/public/cpp/bindings/tests/array_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/array_unittest.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "mojo/public/cpp/bindings/array.h"
#include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
#include "mojo/public/cpp/bindings/lib/scratch_buffer.h"
@@ -16,108 +15,47 @@ namespace {
// Tests that basic Array operations work.
TEST(ArrayTest, Basic) {
- Environment env;
-
- // 8 bytes for the array, with 8 bytes left over for elements.
- internal::FixedBuffer buf(8 + 8*sizeof(char));
- EXPECT_EQ(16u, buf.size());
-
- Array<char>::Builder builder(8);
- EXPECT_EQ(8u, builder.size());
- for (size_t i = 0; i < builder.size(); ++i) {
- char val = static_cast<char>(i*2);
- builder[i] = val;
- EXPECT_EQ(val, builder.at(i));
- }
- Array<char> array = builder.Finish();
+ Array<char> array(8);
for (size_t i = 0; i < array.size(); ++i) {
- char val = static_cast<char>(i) * 2;
- EXPECT_EQ(val, array[i]);
+ char val = static_cast<char>(i*2);
+ array[i] = val;
+ EXPECT_EQ(val, array.at(i));
}
}
-// Tests that basic Array<bool> operations work, and that it's packed into 1
-// bit per element.
+// Tests that basic Array<bool> operations work.
TEST(ArrayTest, Bool) {
- Environment env;
-
- // 8 bytes for the array header, with 8 bytes left over for elements.
- internal::FixedBuffer buf(8 + 3);
- EXPECT_EQ(16u, buf.size());
-
- // An array of 64 bools can fit into 8 bytes.
- Array<bool>::Builder builder(64);
- EXPECT_EQ(64u, builder.size());
- for (size_t i = 0; i < builder.size(); ++i) {
- bool val = i % 3 == 0;
- builder[i] = val;
- EXPECT_EQ(val, builder.at(i));
- }
- Array<bool> array = builder.Finish();
+ Array<bool> array(64);
for (size_t i = 0; i < array.size(); ++i) {
bool val = i % 3 == 0;
- EXPECT_EQ(val, array[i]);
+ array[i] = val;
+ EXPECT_EQ(val, array.at(i));
}
}
-// Tests that Array<Handle> supports transferring handles.
+// Tests that Array<ScopedMessagePipeHandle> supports transferring handles.
TEST(ArrayTest, Handle) {
- Environment env;
-
- AllocationScope scope;
-
ScopedMessagePipeHandle pipe0, pipe1;
CreateMessagePipe(&pipe0, &pipe1);
- Array<MessagePipeHandle>::Builder handles_builder(2);
- handles_builder[0] = pipe0.Pass();
- handles_builder[1].reset(pipe1.release());
+ Array<ScopedMessagePipeHandle> handles(2);
+ handles[0] = pipe0.Pass();
+ handles[1].reset(pipe1.release());
EXPECT_FALSE(pipe0.is_valid());
EXPECT_FALSE(pipe1.is_valid());
- Array<MessagePipeHandle> handles = handles_builder.Finish();
- EXPECT_TRUE(handles[0].is_valid());
- EXPECT_TRUE(handles[1].is_valid());
+ Array<ScopedMessagePipeHandle> handles2 = handles.Pass();
+ EXPECT_TRUE(handles2[0].is_valid());
+ EXPECT_TRUE(handles2[1].is_valid());
- pipe0 = handles[0].Pass();
+ pipe0 = handles2[0].Pass();
EXPECT_TRUE(pipe0.is_valid());
- EXPECT_FALSE(handles[0].is_valid());
+ EXPECT_FALSE(handles2[0].is_valid());
}
-// Tests that Array<Handle> supports closing handles.
+// Tests that Array<ScopedMessagePipeHandle> supports closing handles.
TEST(ArrayTest, HandlesAreClosed) {
- Environment env;
-
- ScopedMessagePipeHandle msg_pipe0, msg_pipe1;
- CreateMessagePipe(&msg_pipe0, &msg_pipe1);
-
- ScopedHandle pipe0 = ScopedHandle::From(msg_pipe0.Pass());
- ScopedHandle pipe1 = ScopedHandle::From(msg_pipe1.Pass());
-
- MojoHandle pipe0_value = pipe0.get().value();
- MojoHandle pipe1_value = pipe1.get().value();
-
- {
- AllocationScope scope;
-
- Array<Handle>::Builder handles_builder(2);
- handles_builder[0] = pipe0.Pass();
- handles_builder[1].reset(pipe1.release());
-
- MOJO_ALLOW_UNUSED Array<Handle> handles =
- handles_builder.Finish();
- }
-
- // We expect the pipes to have been closed.
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(pipe0_value));
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(pipe1_value));
-}
-
-// Tests that Array<MessagePipeHandle> supports closing handles.
-TEST(ArrayTest, MessagePipeHandlesAreClosed) {
- Environment env;
-
ScopedMessagePipeHandle pipe0, pipe1;
CreateMessagePipe(&pipe0, &pipe1);
@@ -125,14 +63,9 @@ TEST(ArrayTest, MessagePipeHandlesAreClosed) {
MojoHandle pipe1_value = pipe1.get().value();
{
- AllocationScope scope;
-
- Array<MessagePipeHandle>::Builder handles_builder(2);
- handles_builder[0] = pipe0.Pass();
- handles_builder[1].reset(pipe1.release());
-
- MOJO_ALLOW_UNUSED Array<MessagePipeHandle> handles =
- handles_builder.Finish();
+ Array<ScopedMessagePipeHandle> handles(2);
+ handles[0] = pipe0.Pass();
+ handles[1].reset(pipe1.release());
}
// We expect the pipes to have been closed.

Powered by Google App Engine
This is Rietveld 408576698