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

Side by Side Diff: mojo/public/tests/bindings_array_unittest.cc

Issue 134823005: Mojo: re-organize public tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/bindings/lib/array.h"
6 #include "mojo/public/tests/simple_bindings_support.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace mojo {
10 namespace test {
11
12 // Tests that basic Array operations work.
13 TEST(BindingsArrayTest, Basic) {
14 SimpleBindingsSupport bindings_support;
15
16 // 8 bytes for the array, with 8 bytes left over for elements.
17 internal::FixedBuffer buf(8 + 8*sizeof(char));
18 EXPECT_EQ(16u, buf.size());
19
20 Array<char>::Builder builder(8);
21 EXPECT_EQ(8u, builder.size());
22 for (size_t i = 0; i < builder.size(); ++i) {
23 char val = static_cast<char>(i*2);
24 builder[i] = val;
25 EXPECT_EQ(val, builder.at(i));
26 }
27 Array<char> array = builder.Finish();
28 for (size_t i = 0; i < array.size(); ++i) {
29 char val = static_cast<char>(i) * 2;
30 EXPECT_EQ(val, array[i]);
31 }
32 }
33
34 // Tests that basic Array<bool> operations work, and that it's packed into 1
35 // bit per element.
36 TEST(BindingsArrayTest, Bool) {
37 SimpleBindingsSupport bindings_support;
38
39 // 8 bytes for the array header, with 8 bytes left over for elements.
40 internal::FixedBuffer buf(8 + 3);
41 EXPECT_EQ(16u, buf.size());
42
43 // An array of 64 bools can fit into 8 bytes.
44 Array<bool>::Builder builder(64);
45 EXPECT_EQ(64u, builder.size());
46 for (size_t i = 0; i < builder.size(); ++i) {
47 bool val = i % 3 == 0;
48 builder[i] = val;
49 EXPECT_EQ(val, builder.at(i));
50 }
51 Array<bool> array = builder.Finish();
52 for (size_t i = 0; i < array.size(); ++i) {
53 bool val = i % 3 == 0;
54 EXPECT_EQ(val, array[i]);
55 }
56 }
57
58 // Tests that Array<Handle> supports transferring handles.
59 TEST(BindingsArrayTest, Handle) {
60 SimpleBindingsSupport bindings_support;
61
62 AllocationScope scope;
63
64 ScopedMessagePipeHandle pipe0, pipe1;
65 CreateMessagePipe(&pipe0, &pipe1);
66
67 Array<MessagePipeHandle>::Builder handles_builder(2);
68 handles_builder[0] = pipe0.Pass();
69 handles_builder[1].reset(pipe1.release());
70
71 EXPECT_FALSE(pipe0.is_valid());
72 EXPECT_FALSE(pipe1.is_valid());
73
74 Array<MessagePipeHandle> handles = handles_builder.Finish();
75 EXPECT_TRUE(handles[0].is_valid());
76 EXPECT_TRUE(handles[1].is_valid());
77
78 pipe0 = handles[0].Pass();
79 EXPECT_TRUE(pipe0.is_valid());
80 EXPECT_FALSE(handles[0].is_valid());
81 }
82
83 } // namespace test
84 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/tests/bindings/type_conversion_unittest.cc ('k') | mojo/public/tests/bindings_connector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698