OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/public/cpp/bindings/array.h" | 5 #include "mojo/public/cpp/bindings/array.h" |
6 #include "mojo/public/cpp/bindings/lib/array_serialization.h" | 6 #include "mojo/public/cpp/bindings/lib/array_serialization.h" |
7 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" | 7 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" |
8 #include "mojo/public/cpp/environment/environment.h" | 8 #include "mojo/public/cpp/environment/environment.h" |
9 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" | 9 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 Array<bool> array(64); | 28 Array<bool> array(64); |
29 for (size_t i = 0; i < array.size(); ++i) { | 29 for (size_t i = 0; i < array.size(); ++i) { |
30 bool val = i % 3 == 0; | 30 bool val = i % 3 == 0; |
31 array[i] = val; | 31 array[i] = val; |
32 EXPECT_EQ(val, array.at(i)); | 32 EXPECT_EQ(val, array.at(i)); |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 // Tests that Array<ScopedMessagePipeHandle> supports transferring handles. | 36 // Tests that Array<ScopedMessagePipeHandle> supports transferring handles. |
37 TEST(ArrayTest, Handle) { | 37 TEST(ArrayTest, Handle) { |
38 ScopedMessagePipeHandle pipe0, pipe1; | 38 MessagePipe pipe; |
39 CreateMessagePipe(&pipe0, &pipe1); | 39 Array<ScopedMessagePipeHandle> handles(2); |
| 40 handles[0] = pipe.handle0.Pass(); |
| 41 handles[1].reset(pipe.handle1.release()); |
40 | 42 |
41 Array<ScopedMessagePipeHandle> handles(2); | 43 EXPECT_FALSE(pipe.handle0.is_valid()); |
42 handles[0] = pipe0.Pass(); | 44 EXPECT_FALSE(pipe.handle1.is_valid()); |
43 handles[1].reset(pipe1.release()); | |
44 | |
45 EXPECT_FALSE(pipe0.is_valid()); | |
46 EXPECT_FALSE(pipe1.is_valid()); | |
47 | 45 |
48 Array<ScopedMessagePipeHandle> handles2 = handles.Pass(); | 46 Array<ScopedMessagePipeHandle> handles2 = handles.Pass(); |
49 EXPECT_TRUE(handles2[0].is_valid()); | 47 EXPECT_TRUE(handles2[0].is_valid()); |
50 EXPECT_TRUE(handles2[1].is_valid()); | 48 EXPECT_TRUE(handles2[1].is_valid()); |
51 | 49 |
52 pipe0 = handles2[0].Pass(); | 50 ScopedMessagePipeHandle pipe_handle = handles2[0].Pass(); |
53 EXPECT_TRUE(pipe0.is_valid()); | 51 EXPECT_TRUE(pipe_handle.is_valid()); |
54 EXPECT_FALSE(handles2[0].is_valid()); | 52 EXPECT_FALSE(handles2[0].is_valid()); |
55 } | 53 } |
56 | 54 |
57 // Tests that Array<ScopedMessagePipeHandle> supports closing handles. | 55 // Tests that Array<ScopedMessagePipeHandle> supports closing handles. |
58 TEST(ArrayTest, HandlesAreClosed) { | 56 TEST(ArrayTest, HandlesAreClosed) { |
59 ScopedMessagePipeHandle pipe0, pipe1; | 57 MessagePipe pipe; |
60 CreateMessagePipe(&pipe0, &pipe1); | 58 MojoHandle pipe0_value = pipe.handle0.get().value(); |
61 | 59 MojoHandle pipe1_value = pipe.handle0.get().value(); |
62 MojoHandle pipe0_value = pipe0.get().value(); | |
63 MojoHandle pipe1_value = pipe1.get().value(); | |
64 | 60 |
65 { | 61 { |
66 Array<ScopedMessagePipeHandle> handles(2); | 62 Array<ScopedMessagePipeHandle> handles(2); |
67 handles[0] = pipe0.Pass(); | 63 handles[0] = pipe.handle0.Pass(); |
68 handles[1].reset(pipe1.release()); | 64 handles[1].reset(pipe.handle0.release()); |
69 } | 65 } |
70 | 66 |
71 // We expect the pipes to have been closed. | 67 // We expect the pipes to have been closed. |
72 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(pipe0_value)); | 68 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(pipe0_value)); |
73 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(pipe1_value)); | 69 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(pipe1_value)); |
74 } | 70 } |
75 | 71 |
76 TEST(ArrayTest, Serialization_ArrayOfPOD) { | 72 TEST(ArrayTest, Serialization_ArrayOfPOD) { |
77 Array<int32_t> array(4); | 73 Array<int32_t> array(4); |
78 for (size_t i = 0; i < array.size(); ++i) | 74 for (size_t i = 0; i < array.size(); ++i) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 EXPECT_EQ(10U, array2.size()); | 161 EXPECT_EQ(10U, array2.size()); |
166 for (size_t i = 0; i < array2.size(); ++i) { | 162 for (size_t i = 0; i < array2.size(); ++i) { |
167 char c = 'A' + 1; | 163 char c = 'A' + 1; |
168 EXPECT_EQ(String(&c, 1), array2[i]); | 164 EXPECT_EQ(String(&c, 1), array2[i]); |
169 } | 165 } |
170 } | 166 } |
171 | 167 |
172 } // namespace | 168 } // namespace |
173 } // namespace test | 169 } // namespace test |
174 } // namespace mojo | 170 } // namespace mojo |
OLD | NEW |