Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cfx_timer_unittest.cpp
Go to the documentation of this file.
1
// Copyright 2019 The PDFium Authors
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
"core/fxcrt/cfx_timer.h"
6
7
#
include
<
memory
>
8
9
#
include
"testing/gmock/include/gmock/gmock.h"
10
#
include
"testing/gtest/include/gtest/gtest.h"
11
12
using
testing::_;
13
using
testing::DoAll;
14
using
testing::Return;
15
using
testing::SaveArg;
16
17
namespace
{
18
19
class
MockTimerScheduler :
public
CFX_Timer
::
HandlerIface
{
20
public
:
21
MOCK_METHOD(
int
, SetTimer, (int32_t uElapse,
TimerCallback
lpTimerFunc));
22
MOCK_METHOD(
void
, KillTimer, (int32_t nID));
23
};
24
25
class
MockTimerCallback :
public
CFX_Timer
::
CallbackIface
{
26
public
:
27
MOCK_METHOD(
void
, OnTimerFired, ());
28
};
29
30
}
// namespace
31
32
class
CFXTimer
:
public
testing
::
Test
{
33
void
SetUp
()
override
{
CFX_Timer
::
InitializeGlobals
(
)
; }
34
void
TearDown
()
override
{
CFX_Timer
::
DestroyGlobals
(
)
; }
35
};
36
37
TEST_F
(
CFXTimer
,
ValidTimers
) {
38
CFX_Timer
::
HandlerIface
::
TimerCallback
fn1 =
nullptr
;
39
CFX_Timer
::
HandlerIface
::
TimerCallback
fn2 =
nullptr
;
40
41
MockTimerScheduler scheduler;
42
EXPECT_CALL(scheduler, SetTimer(100, _))
43
.WillOnce(DoAll(SaveArg<1>(&fn1), Return(1001)));
44
EXPECT_CALL(scheduler, SetTimer(200, _))
45
.WillOnce(DoAll(SaveArg<1>(&fn2), Return(1002)));
46
EXPECT_CALL(scheduler, KillTimer(1001));
47
EXPECT_CALL(scheduler, KillTimer(1002));
48
49
MockTimerCallback cb1;
50
EXPECT_CALL(cb1, OnTimerFired()).Times(1);
51
52
MockTimerCallback cb2;
53
EXPECT_CALL(cb2, OnTimerFired()).Times(2);
54
55
auto
timer1 =
std
::make_unique<
CFX_Timer
>(&scheduler, &cb1, 100);
56
auto
timer2 =
std
::make_unique<
CFX_Timer
>(&scheduler, &cb2, 200);
57
EXPECT_TRUE(timer1->HasValidID());
58
EXPECT_TRUE(timer2->HasValidID());
59
60
// Fire some timers.
61
ASSERT_TRUE(fn1);
62
ASSERT_TRUE(fn2);
63
(*fn1)(1001);
64
(*fn1)(1002);
65
(*fn1)(1002);
66
}
67
68
TEST_F
(
CFXTimer
,
MisbehavingEmbedder
) {
69
CFX_Timer
::
HandlerIface
::
TimerCallback
fn1 =
nullptr
;
70
71
MockTimerScheduler scheduler;
72
EXPECT_CALL(scheduler, SetTimer(100, _))
73
.WillOnce(DoAll(SaveArg<1>(&fn1), Return(1001)));
74
EXPECT_CALL(scheduler, KillTimer(1001));
75
76
MockTimerCallback cb1;
77
EXPECT_CALL(cb1, OnTimerFired()).Times(0);
78
79
{
80
auto
timer1 =
std
::make_unique<
CFX_Timer
>(&scheduler, &cb1, 100);
81
EXPECT_TRUE(timer1->HasValidID());
82
83
// Fire callback with bad arguments.
84
ASSERT_TRUE(fn1);
85
(*fn1)(-1);
86
(*fn1)(0);
87
(*fn1)(1002);
88
}
89
90
// Fire callback against stale timer.
91
(*fn1)(1001);
92
}
TEST_F
TEST_F(CFXTimer, ValidTimers)
Definition
cfx_timer_unittest.cpp:37
CFXTimer
Definition
cfx_timer_unittest.cpp:32
CFXTimer::SetUp
void SetUp() override
Definition
cfx_timer_unittest.cpp:33
CFXTimer::TearDown
void TearDown() override
Definition
cfx_timer_unittest.cpp:34
CFX_Timer::CallbackIface
Definition
cfx_timer.h:32
CFX_Timer::HandlerIface
Definition
cfx_timer.h:19
CFX_Timer::HandlerIface::TimerCallback
void(*)(int32_t idEvent) TimerCallback
Definition
cfx_timer.h:22
CFX_Timer
Definition
cfx_timer.h:15
CFX_Timer::DestroyGlobals
static void DestroyGlobals()
Definition
cfx_timer.cpp:27
CFX_Timer::InitializeGlobals
static void InitializeGlobals()
Definition
cfx_timer.cpp:21
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxcrt
cfx_timer_unittest.cpp
Generated on
for Qt by
1.18.0