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 // This file tests the C++ Mojo system core wrappers. | 5 // This file tests the C++ Mojo system core wrappers. |
6 // TODO(vtl): Maybe rename "CoreCppTest" -> "CoreTest" if/when this gets | 6 // TODO(vtl): Maybe rename "CoreCppTest" -> "CoreTest" if/when this gets |
7 // compiled into a different binary from the C API tests. | 7 // compiled into a different binary from the C API tests. |
8 | 8 |
9 #include "mojo/public/cpp/system/core.h" | 9 #include "mojo/public/cpp/system/core.h" |
10 | 10 |
11 #include <stddef.h> | 11 #include <stddef.h> |
12 #include <stdint.h> | 12 #include <stdint.h> |
13 | |
14 #include <map> | 13 #include <map> |
| 14 #include <utility> |
15 | 15 |
16 #include "mojo/public/cpp/system/macros.h" | 16 #include "mojo/public/cpp/system/macros.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 namespace { | 20 namespace { |
21 | 21 |
22 const MojoHandleSignals kSignalReadableWritable = | 22 const MojoHandleSignals kSignalReadableWritable = |
23 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; | 23 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; |
24 | 24 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // how to support the variations of |hash_map|.) | 96 // how to support the variations of |hash_map|.) |
97 } | 97 } |
98 | 98 |
99 // |Handle|/|ScopedHandle| functions: | 99 // |Handle|/|ScopedHandle| functions: |
100 { | 100 { |
101 ScopedHandle h; | 101 ScopedHandle h; |
102 | 102 |
103 EXPECT_EQ(kInvalidHandleValue, h.get().value()); | 103 EXPECT_EQ(kInvalidHandleValue, h.get().value()); |
104 | 104 |
105 // This should be a no-op. | 105 // This should be a no-op. |
106 Close(h.Pass()); | 106 Close(std::move(h)); |
107 | 107 |
108 // It should still be invalid. | 108 // It should still be invalid. |
109 EXPECT_EQ(kInvalidHandleValue, h.get().value()); | 109 EXPECT_EQ(kInvalidHandleValue, h.get().value()); |
110 | 110 |
111 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 111 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
112 Wait(h.get(), ~MOJO_HANDLE_SIGNAL_NONE, 1000000, nullptr)); | 112 Wait(h.get(), ~MOJO_HANDLE_SIGNAL_NONE, 1000000, nullptr)); |
113 | 113 |
114 std::vector<Handle> wh; | 114 std::vector<Handle> wh; |
115 wh.push_back(h.get()); | 115 wh.push_back(h.get()); |
116 std::vector<MojoHandleSignals> sigs; | 116 std::vector<MojoHandleSignals> sigs; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 EXPECT_EQ(MOJO_RESULT_OK, wait_many_result.result); | 206 EXPECT_EQ(MOJO_RESULT_OK, wait_many_result.result); |
207 EXPECT_EQ(1u, wait_many_result.index); | 207 EXPECT_EQ(1u, wait_many_result.index); |
208 EXPECT_TRUE(wait_many_result.IsIndexValid()); | 208 EXPECT_TRUE(wait_many_result.IsIndexValid()); |
209 EXPECT_TRUE(wait_many_result.AreSignalsStatesValid()); | 209 EXPECT_TRUE(wait_many_result.AreSignalsStatesValid()); |
210 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, states[0].satisfied_signals); | 210 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, states[0].satisfied_signals); |
211 EXPECT_EQ(kSignalAll, states[0].satisfiable_signals); | 211 EXPECT_EQ(kSignalAll, states[0].satisfiable_signals); |
212 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, states[1].satisfied_signals); | 212 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, states[1].satisfied_signals); |
213 EXPECT_EQ(kSignalAll, states[1].satisfiable_signals); | 213 EXPECT_EQ(kSignalAll, states[1].satisfiable_signals); |
214 | 214 |
215 // Test closing |h1| explicitly. | 215 // Test closing |h1| explicitly. |
216 Close(h1.Pass()); | 216 Close(std::move(h1)); |
217 EXPECT_FALSE(h1.get().is_valid()); | 217 EXPECT_FALSE(h1.get().is_valid()); |
218 | 218 |
219 // Make sure |h1| is closed. | 219 // Make sure |h1| is closed. |
220 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 220 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
221 Wait(Handle(hv1), ~MOJO_HANDLE_SIGNAL_NONE, | 221 Wait(Handle(hv1), ~MOJO_HANDLE_SIGNAL_NONE, |
222 MOJO_DEADLINE_INDEFINITE, nullptr)); | 222 MOJO_DEADLINE_INDEFINITE, nullptr)); |
223 | 223 |
224 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 224 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
225 Wait(h0.get(), MOJO_HANDLE_SIGNAL_READABLE, | 225 Wait(h0.get(), MOJO_HANDLE_SIGNAL_READABLE, |
226 MOJO_DEADLINE_INDEFINITE, &state)); | 226 MOJO_DEADLINE_INDEFINITE, &state)); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 ScopedSharedBufferHandle buffer1; | 467 ScopedSharedBufferHandle buffer1; |
468 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer1)); | 468 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer1)); |
469 EXPECT_TRUE(buffer1.is_valid()); | 469 EXPECT_TRUE(buffer1.is_valid()); |
470 | 470 |
471 ScopedSharedBufferHandle buffer2; | 471 ScopedSharedBufferHandle buffer2; |
472 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer2)); | 472 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer2)); |
473 EXPECT_TRUE(buffer2.is_valid()); | 473 EXPECT_TRUE(buffer2.is_valid()); |
474 | 474 |
475 // If this fails to close buffer1, ScopedHandleBase::CloseIfNecessary() will | 475 // If this fails to close buffer1, ScopedHandleBase::CloseIfNecessary() will |
476 // assert. | 476 // assert. |
477 buffer1 = buffer2.Pass(); | 477 buffer1 = std::move(buffer2); |
478 | 478 |
479 EXPECT_TRUE(buffer1.is_valid()); | 479 EXPECT_TRUE(buffer1.is_valid()); |
480 EXPECT_FALSE(buffer2.is_valid()); | 480 EXPECT_FALSE(buffer2.is_valid()); |
481 } | 481 } |
482 | 482 |
483 TEST(CoreCppTest, ScopedHandleMoveCtorSelf) { | |
484 ScopedSharedBufferHandle buffer1; | |
485 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer1)); | |
486 EXPECT_TRUE(buffer1.is_valid()); | |
487 | |
488 buffer1 = buffer1.Pass(); | |
489 | |
490 EXPECT_TRUE(buffer1.is_valid()); | |
491 } | |
492 | |
493 // TODO(vtl): Write data pipe tests. | 483 // TODO(vtl): Write data pipe tests. |
494 | 484 |
495 } // namespace | 485 } // namespace |
496 } // namespace mojo | 486 } // namespace mojo |
OLD | NEW |