| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/edk/system/dispatcher.h" | 5 #include "mojo/edk/system/dispatcher.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/threading/simple_thread.h" | 10 #include "base/threading/simple_thread.h" |
| 11 #include "mojo/edk/embedder/platform_shared_buffer.h" | 11 #include "mojo/edk/embedder/platform_shared_buffer.h" |
| 12 #include "mojo/edk/system/memory.h" | 12 #include "mojo/edk/system/memory.h" |
| 13 #include "mojo/edk/system/waiter.h" | 13 #include "mojo/edk/system/waiter.h" |
| 14 #include "mojo/public/cpp/system/macros.h" | 14 #include "mojo/public/cpp/system/macros.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace system { | 18 namespace edk { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Trivial subclass that makes the constructor public. | 21 // Trivial subclass that makes the constructor public. |
| 22 class TrivialDispatcher final : public Dispatcher { | 22 class TrivialDispatcher final : public Dispatcher { |
| 23 public: | 23 public: |
| 24 TrivialDispatcher() {} | 24 TrivialDispatcher() {} |
| 25 | 25 |
| 26 Type GetType() const override { return Type::UNKNOWN; } | 26 Type GetType() const override { return Type::UNKNOWN; } |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 friend class base::RefCountedThreadSafe<TrivialDispatcher>; | 29 friend class base::RefCountedThreadSafe<TrivialDispatcher>; |
| 30 ~TrivialDispatcher() override {} | 30 ~TrivialDispatcher() override {} |
| 31 | 31 |
| 32 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() | 32 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() |
| 33 override { | 33 override { |
| 34 mutex().AssertHeld(); | 34 lock().AssertAcquired(); |
| 35 return scoped_refptr<Dispatcher>(new TrivialDispatcher()); | 35 return scoped_refptr<Dispatcher>(new TrivialDispatcher()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 MOJO_DISALLOW_COPY_AND_ASSIGN(TrivialDispatcher); | 38 MOJO_DISALLOW_COPY_AND_ASSIGN(TrivialDispatcher); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 TEST(DispatcherTest, Basic) { | 41 TEST(DispatcherTest, Basic) { |
| 42 scoped_refptr<Dispatcher> d(new TrivialDispatcher()); | 42 scoped_refptr<Dispatcher> d(new TrivialDispatcher()); |
| 43 | 43 |
| 44 EXPECT_EQ(Dispatcher::Type::UNKNOWN, d->GetType()); | 44 EXPECT_EQ(Dispatcher::Type::UNKNOWN, d->GetType()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, dispatcher_->EndReadData(0)); | 197 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, dispatcher_->EndReadData(0)); |
| 198 break; | 198 break; |
| 199 case DUPLICATE_BUFFER_HANDLE: { | 199 case DUPLICATE_BUFFER_HANDLE: { |
| 200 scoped_refptr<Dispatcher> unused; | 200 scoped_refptr<Dispatcher> unused; |
| 201 EXPECT_EQ( | 201 EXPECT_EQ( |
| 202 MOJO_RESULT_INVALID_ARGUMENT, | 202 MOJO_RESULT_INVALID_ARGUMENT, |
| 203 dispatcher_->DuplicateBufferHandle(NullUserPointer(), &unused)); | 203 dispatcher_->DuplicateBufferHandle(NullUserPointer(), &unused)); |
| 204 break; | 204 break; |
| 205 } | 205 } |
| 206 case MAP_BUFFER: { | 206 case MAP_BUFFER: { |
| 207 scoped_ptr<embedder::PlatformSharedBufferMapping> unused; | 207 scoped_ptr<PlatformSharedBufferMapping> unused; |
| 208 EXPECT_EQ( | 208 EXPECT_EQ( |
| 209 MOJO_RESULT_INVALID_ARGUMENT, | 209 MOJO_RESULT_INVALID_ARGUMENT, |
| 210 dispatcher_->MapBuffer(0u, 0u, MOJO_MAP_BUFFER_FLAG_NONE, &unused)); | 210 dispatcher_->MapBuffer(0u, 0u, MOJO_MAP_BUFFER_FLAG_NONE, &unused)); |
| 211 break; | 211 break; |
| 212 } | 212 } |
| 213 case ADD_WAITER: { | 213 case ADD_WAITER: { |
| 214 HandleSignalsState hss; | 214 HandleSignalsState hss; |
| 215 MojoResult r = dispatcher_->AddAwakable( | 215 MojoResult r = dispatcher_->AddAwakable( |
| 216 &waiter_, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss); | 216 &waiter_, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss); |
| 217 EXPECT_TRUE(r == MOJO_RESULT_FAILED_PRECONDITION || | 217 EXPECT_TRUE(r == MOJO_RESULT_FAILED_PRECONDITION || |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 } | 296 } |
| 297 // Kicks off real work on the threads: | 297 // Kicks off real work on the threads: |
| 298 event.Signal(); | 298 event.Signal(); |
| 299 } // Joins all the threads. | 299 } // Joins all the threads. |
| 300 | 300 |
| 301 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 301 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 | 304 |
| 305 } // namespace | 305 } // namespace |
| 306 } // namespace system | 306 } // namespace edk |
| 307 } // namespace mojo | 307 } // namespace mojo |
| OLD | NEW |