| 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/system/dispatcher.h" | 5 #include "mojo/system/dispatcher.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/threading/simple_thread.h" | 11 #include "base/threading/simple_thread.h" |
| 12 #include "mojo/embedder/platform_shared_buffer.h" | 12 #include "mojo/embedder/platform_shared_buffer.h" |
| 13 #include "mojo/system/memory.h" | 13 #include "mojo/system/memory.h" |
| 14 #include "mojo/system/waiter.h" | 14 #include "mojo/system/waiter.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 system { |
| 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 : public Dispatcher { | 22 class TrivialDispatcher : public Dispatcher { |
| 23 public: | 23 public: |
| 24 TrivialDispatcher() {} | 24 TrivialDispatcher() {} |
| 25 | 25 |
| 26 virtual Type GetType() const OVERRIDE { return kTypeUnknown; } | 26 virtual Type GetType() const override { return kTypeUnknown; } |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 friend class base::RefCountedThreadSafe<TrivialDispatcher>; | 29 friend class base::RefCountedThreadSafe<TrivialDispatcher>; |
| 30 virtual ~TrivialDispatcher() {} | 30 virtual ~TrivialDispatcher() {} |
| 31 | 31 |
| 32 virtual scoped_refptr<Dispatcher> | 32 virtual scoped_refptr<Dispatcher> |
| 33 CreateEquivalentDispatcherAndCloseImplNoLock() OVERRIDE { | 33 CreateEquivalentDispatcherAndCloseImplNoLock() override { |
| 34 lock().AssertAcquired(); | 34 lock().AssertAcquired(); |
| 35 return scoped_refptr<Dispatcher>(new TrivialDispatcher()); | 35 return scoped_refptr<Dispatcher>(new TrivialDispatcher()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 DISALLOW_COPY_AND_ASSIGN(TrivialDispatcher); | 38 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 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 event_(event), | 153 event_(event), |
| 154 dispatcher_(dispatcher), | 154 dispatcher_(dispatcher), |
| 155 op_(op) { | 155 op_(op) { |
| 156 CHECK_LE(0, op_); | 156 CHECK_LE(0, op_); |
| 157 CHECK_LT(op_, DISPATCHER_OP_COUNT); | 157 CHECK_LT(op_, DISPATCHER_OP_COUNT); |
| 158 } | 158 } |
| 159 | 159 |
| 160 virtual ~ThreadSafetyStressThread() { Join(); } | 160 virtual ~ThreadSafetyStressThread() { Join(); } |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 virtual void Run() OVERRIDE { | 163 virtual void Run() override { |
| 164 event_->Wait(); | 164 event_->Wait(); |
| 165 | 165 |
| 166 waiter_.Init(); | 166 waiter_.Init(); |
| 167 switch (op_) { | 167 switch (op_) { |
| 168 case CLOSE: { | 168 case CLOSE: { |
| 169 MojoResult r = dispatcher_->Close(); | 169 MojoResult r = dispatcher_->Close(); |
| 170 EXPECT_TRUE(r == MOJO_RESULT_OK || r == MOJO_RESULT_INVALID_ARGUMENT) | 170 EXPECT_TRUE(r == MOJO_RESULT_OK || r == MOJO_RESULT_INVALID_ARGUMENT) |
| 171 << "Result: " << r; | 171 << "Result: " << r; |
| 172 break; | 172 break; |
| 173 } | 173 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 event.Signal(); | 317 event.Signal(); |
| 318 } // Joins all the threads. | 318 } // Joins all the threads. |
| 319 | 319 |
| 320 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 320 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 321 } | 321 } |
| 322 } | 322 } |
| 323 | 323 |
| 324 } // namespace | 324 } // namespace |
| 325 } // namespace system | 325 } // namespace system |
| 326 } // namespace mojo | 326 } // namespace mojo |
| OLD | NEW |