blob: a356cc265a58b66dfc5fb27929e2eca27a360b35 [file] [log] [blame]
Tommi9e46cf52020-05-04 16:43:05 +02001/*
2 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "test/run_loop.h"
12
13#include "rtc_base/task_queue.h"
14#include "rtc_base/task_utils/to_queued_task.h"
15#include "test/gtest.h"
16
17namespace webrtc {
18
19TEST(RunLoopTest, TaskQueueOnThread) {
20 EXPECT_EQ(TaskQueueBase::Current(), nullptr);
21 test::RunLoop loop;
22 EXPECT_EQ(TaskQueueBase::Current(), loop.task_queue());
23 EXPECT_TRUE(loop.task_queue()->IsCurrent());
24}
25
26TEST(RunLoopTest, Flush) {
27 test::RunLoop loop;
28 int counter = 0;
29 loop.PostTask([&counter]() { ++counter; });
30 EXPECT_EQ(counter, 0);
31 loop.Flush();
32 EXPECT_EQ(counter, 1);
33}
34
35TEST(RunLoopTest, Delayed) {
36 test::RunLoop loop;
37 bool ran = false;
38 loop.PostDelayedTask(
39 [&ran, &loop]() {
40 ran = true;
41 loop.Quit();
42 },
43 100);
44 loop.Flush();
45 EXPECT_FALSE(ran);
46 loop.Run();
47 EXPECT_TRUE(ran);
48}
49
50TEST(RunLoopTest, PostAndQuit) {
51 test::RunLoop loop;
52 bool ran = false;
53 loop.PostTask([&ran, &loop]() {
54 ran = true;
55 loop.Quit();
56 });
57 loop.Run();
58 EXPECT_TRUE(ran);
59}
60
61} // namespace webrtc