OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project 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 "include/v8-platform.h" |
| 6 #include "src/base/platform/platform.h" |
| 7 #include "src/libplatform/task-queue.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 |
| 10 using testing::InSequence; |
| 11 using testing::IsNull; |
| 12 using testing::StrictMock; |
| 13 |
| 14 namespace v8 { |
| 15 namespace platform { |
| 16 |
| 17 namespace { |
| 18 |
| 19 struct MockTask : public Task { |
| 20 MOCK_METHOD0(Run, void()); |
| 21 }; |
| 22 |
| 23 |
| 24 class TaskQueueThread V8_FINAL : public base::Thread { |
| 25 public: |
| 26 explicit TaskQueueThread(TaskQueue* queue) |
| 27 : Thread(Options("libplatform TaskQueueThread")), queue_(queue) {} |
| 28 |
| 29 virtual void Run() V8_OVERRIDE { EXPECT_THAT(queue_->GetNext(), IsNull()); } |
| 30 |
| 31 private: |
| 32 TaskQueue* queue_; |
| 33 }; |
| 34 |
| 35 } // namespace |
| 36 |
| 37 |
| 38 TEST(TaskQueueTest, Basic) { |
| 39 TaskQueue queue; |
| 40 MockTask task; |
| 41 queue.Append(&task); |
| 42 EXPECT_EQ(&task, queue.GetNext()); |
| 43 queue.Terminate(); |
| 44 EXPECT_THAT(queue.GetNext(), IsNull()); |
| 45 } |
| 46 |
| 47 |
| 48 TEST(TaskQueueTest, TerminateMultipleReaders) { |
| 49 TaskQueue queue; |
| 50 TaskQueueThread thread1(&queue); |
| 51 TaskQueueThread thread2(&queue); |
| 52 thread1.Start(); |
| 53 thread2.Start(); |
| 54 queue.Terminate(); |
| 55 thread1.Join(); |
| 56 thread2.Join(); |
| 57 } |
| 58 |
| 59 } // namespace platform |
| 60 } // namespace v8 |
OLD | NEW |