-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-timing.cpp
More file actions
54 lines (36 loc) · 1.11 KB
/
example-timing.cpp
File metadata and controls
54 lines (36 loc) · 1.11 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
#include "gut.h"
#include <thread>
int f(int, int) {
std::this_thread::sleep_for(std::chrono::milliseconds(250));
return 0;
}
TEST("duration detection") {
#ifdef GUT_HAS_CHRONO
// define a threshold in s
auto limit_s = std::chrono::duration<double>(.1);
// emits a warning
SHOULD_LAST_AT_MOST(f(1, 2), limit_s);
// emits an error
LASTS_AT_MOST(f(1, 2), limit_s);
// can use threshold defined in other units
auto limit_ms = std::chrono::milliseconds(100);
LASTS_AT_MOST(f(1, 2), limit_ms);
// thresholds are in s by default
LASTS_AT_MOST(f(1, 2), 0);
LASTS_AT_MOST(f(1, 2), 1);
LASTS_AT_MOST(f(1, 2), .1);
// causes the test to end
REQUIRE_LASTS_AT_MOST(f(1, 2), limit_s);
// this check won't be executed
CHECK(1 == 2);
#else // GUT_HAS_CHRONO - <chrono> not available
// thresholds are in s
LASTS_AT_MOST(f(1, 2), 0);
LASTS_AT_MOST(f(1, 2), 1);
LASTS_AT_MOST(f(1, 2), .1);
// causes the test to end
REQUIRE_LASTS_AT_MOST(f(1, 2), .1);
// this check won't be executed
CHECK(1 == 2);
#endif // GUT_HAS_CHRONO
}