-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy path_test_steady_timer.cpp
More file actions
179 lines (152 loc) · 2.96 KB
/
_test_steady_timer.cpp
File metadata and controls
179 lines (152 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
* @file _test_steady_timer.h
* @brief Test for SteadyTimer class
*
* @author Yonhgwhan, Roh (somma@somma.kr)
* @date 2018/09/28 13:58 created.
* @copyright (C)Somma, Inc. All rights reserved.
**/
#include "stdafx.h"
#include <crtdbg.h>
#include "_MyLib/src/steady_timer.h"
bool test_steady_timer_using_lambda()
{
//
// 1초 짜리 타이머를 생성
//
DWORD_PTR random_value = 1024;
SteadyTimer timer;
bool ret = timer.start(2,
random_value,
[&](_In_ DWORD_PTR tag)->bool
{
_ASSERTE(random_value == tag);
log_info "timer callback" log_end;
return true;
});
_ASSERTE(true == ret);
for (int i = 0; i < 4; ++i)
{
Sleep(1000);
}
timer.stop();
return true;
}
bool timer_callback(_In_ DWORD_PTR tag)
{
UNREFERENCED_PARAMETER(tag);
//
// 4초 이후에 타이머를 취소한다.
//
static uint32_t count = 0;
count++;
log_info "timer callback: %u", count log_end;
if (count == 4)
return false;
else
return true;
}
bool test_steady_timer_using_callback()
{
//
// 1초 짜리 타이머를 생성
//
DWORD_PTR random_value = 1024;
SteadyTimer timer;
bool ret = timer.start(1,
random_value,
timer_callback);
_ASSERTE(true == ret);
for (int i = 0; i < 3; ++i)
{
Sleep(1000);
}
timer.stop();
return true;
}
class SteadyTimerTest
{
public:
SteadyTimerTest()
{
}
bool callback(_In_ DWORD_PTR tag)
{
UNREFERENCED_PARAMETER(tag);
_count++;
log_info "timer callback: %u", _count log_end;
return true;
}
bool start()
{
//
// 1초 짜리 타이머를 생성
//
_count = 0;
bool ret = _timer.start(1, _count, boost::bind(&SteadyTimerTest::callback,
this,
boost::placeholders::_1));
_ASSERTE(true == ret);
return true;
}
void stop()
{
_timer.stop();
}
private:
SteadyTimer _timer;
uint32_t _count;
};
bool test_steady_timer_class()
{
SteadyTimerTest timer;
_ASSERTE(true == timer.start());
Sleep(5000);
timer.stop();
return true;
}
bool on_timer(_In_ DWORD_PTR tag)
{
UNREFERENCED_PARAMETER(tag);
int timer_number = (int)tag;
log_info "timer[%d]: callback", timer_number log_end;
return true;
}
bool test_steady_timer_restart()
{
SteadyTimer timer;
for (int i = 0; i < 3; ++i)
{
log_info "timer[%d]: start...", i log_end;
if (!timer.start(1, i, on_timer))
{
log_err "timer.start() failed." log_end;
return false;
}
Sleep(6000);
log_info "timer[%d]: stop...", i log_end;
timer.stop();
Sleep(2000);
}
_pause;
return true;
}
bool test_steady_timer()
{
//_ASSERTE(true == test_steady_timer_using_lambda());
//_ASSERTE(true == test_steady_timer_using_callback());
//_ASSERTE(true == test_steady_timer_class());
_ASSERTE(true == test_steady_timer_restart());
return true;
}
bool test_steady_multiple_timer_in_single_thread()
{
SteadyTimer timer1;
timer1.start(1, 0, on_timer);
SteadyTimer timer2;
timer2.start(1, 0, on_timer);
Sleep(4000);
timer1.stop();
timer2.stop();
return true;
}