Line data Source code
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 : namespace task_queue_unittest {
17 :
18 : namespace {
19 :
20 1 : struct MockTask : public Task {
21 0 : MOCK_METHOD0(Run, void());
22 : };
23 :
24 :
25 1 : class TaskQueueThread final : public base::Thread {
26 : public:
27 : explicit TaskQueueThread(TaskQueue* queue)
28 2 : : Thread(Options("libplatform TaskQueueThread")), queue_(queue) {}
29 :
30 4 : void Run() override { EXPECT_THAT(queue_->GetNext(), IsNull()); }
31 :
32 : private:
33 : TaskQueue* queue_;
34 : };
35 :
36 : } // namespace
37 :
38 :
39 13158 : TEST(TaskQueueTest, Basic) {
40 1 : TaskQueue queue;
41 : MockTask task;
42 1 : queue.Append(&task);
43 2 : EXPECT_EQ(&task, queue.GetNext());
44 1 : queue.Terminate();
45 2 : EXPECT_THAT(queue.GetNext(), IsNull());
46 1 : }
47 :
48 :
49 13158 : TEST(TaskQueueTest, TerminateMultipleReaders) {
50 1 : TaskQueue queue;
51 : TaskQueueThread thread1(&queue);
52 : TaskQueueThread thread2(&queue);
53 1 : thread1.Start();
54 1 : thread2.Start();
55 1 : queue.Terminate();
56 1 : thread1.Join();
57 2 : thread2.Join();
58 1 : }
59 :
60 : } // namespace task_queue_unittest
61 : } // namespace platform
62 7893 : } // namespace v8
|