blob: 2de104b9c03a40dc8c62f151aa79e033183b6479 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
10using testing::InSequence;
11using testing::IsNull;
12using testing::StrictMock;
13
14namespace v8 {
15namespace platform {
16
17namespace {
18
19struct MockTask : public Task {
20 MOCK_METHOD0(Run, void());
21};
22
23
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000024class TaskQueueThread final : public base::Thread {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000025 public:
26 explicit TaskQueueThread(TaskQueue* queue)
27 : Thread(Options("libplatform TaskQueueThread")), queue_(queue) {}
28
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000029 void Run() override { EXPECT_THAT(queue_->GetNext(), IsNull()); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030
31 private:
32 TaskQueue* queue_;
33};
34
35} // namespace
36
37
38TEST(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
48TEST(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