blob: 160aba0716a2297ba00c0f120422a2c416e2ba8f [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) {
Tommi9e46cf52020-05-04 16:43:05 +020020 test::RunLoop loop;
21 EXPECT_EQ(TaskQueueBase::Current(), loop.task_queue());
22 EXPECT_TRUE(loop.task_queue()->IsCurrent());
23}
24
25TEST(RunLoopTest, Flush) {
26 test::RunLoop loop;
27 int counter = 0;
28 loop.PostTask([&counter]() { ++counter; });
29 EXPECT_EQ(counter, 0);
30 loop.Flush();
31 EXPECT_EQ(counter, 1);
32}
33
34TEST(RunLoopTest, Delayed) {
35 test::RunLoop loop;
36 bool ran = false;
37 loop.PostDelayedTask(
38 [&ran, &loop]() {
39 ran = true;
40 loop.Quit();
41 },
42 100);
43 loop.Flush();
44 EXPECT_FALSE(ran);
45 loop.Run();
46 EXPECT_TRUE(ran);
47}
48
49TEST(RunLoopTest, PostAndQuit) {
50 test::RunLoop loop;
51 bool ran = false;
52 loop.PostTask([&ran, &loop]() {
53 ran = true;
54 loop.Quit();
55 });
56 loop.Run();
57 EXPECT_TRUE(ran);
58}
59
60} // namespace webrtc