GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* |
||
2 |
* The ManaPlus Client |
||
3 |
* Copyright (C) 2012-2019 The ManaPlus Developers |
||
4 |
* Copyright (C) 2019-2021 Andrei Karas |
||
5 |
* |
||
6 |
* This file is part of The ManaPlus Client. |
||
7 |
* |
||
8 |
* This program is free software; you can redistribute it and/or modify |
||
9 |
* it under the terms of the GNU General Public License as published by |
||
10 |
* the Free Software Foundation; either version 2 of the License, or |
||
11 |
* any later version. |
||
12 |
* |
||
13 |
* This program is distributed in the hope that it will be useful, |
||
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 |
* GNU General Public License for more details. |
||
17 |
* |
||
18 |
* You should have received a copy of the GNU General Public License |
||
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
20 |
*/ |
||
21 |
|||
22 |
#include "unittests/unittests.h" |
||
23 |
|||
24 |
#include "const/utils/timer.h" |
||
25 |
|||
26 |
#include "utils/timer.h" |
||
27 |
|||
28 |
#include <climits> |
||
29 |
|||
30 |
#include "debug.h" |
||
31 |
|||
32 |
static const int MAX_TICK_VALUE = INT_MAX / 2; |
||
33 |
|||
34 |
✓✗ | 3 |
TEST_CASE("timer const", "") |
35 |
{ |
||
36 |
✓✗✓✗ ✓✗✓✗ ✗✗✗✗ |
4 |
REQUIRE(MILLISECONDS_IN_A_TICK != 0); |
37 |
1 |
} |
|
38 |
|||
39 |
✓✗ | 3 |
TEST_CASE("timer get_elapsed_time", "") |
40 |
{ |
||
41 |
1 |
tick_time = 0; |
|
42 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(0) == 0); |
43 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 1) == 1 * MILLISECONDS_IN_A_TICK); |
44 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 2) == 2 * MILLISECONDS_IN_A_TICK); |
45 |
|||
46 |
1 |
tick_time = 1; |
|
47 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(0) == 1 * MILLISECONDS_IN_A_TICK); |
48 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(1) == 0 * MILLISECONDS_IN_A_TICK); |
49 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 1) == 2 * MILLISECONDS_IN_A_TICK); |
50 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 2) == 3 * MILLISECONDS_IN_A_TICK); |
51 |
|||
52 |
1 |
tick_time = 10; |
|
53 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(0) == 10 * MILLISECONDS_IN_A_TICK); |
54 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(10) == 0 * MILLISECONDS_IN_A_TICK); |
55 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 1) == |
56 |
11 * MILLISECONDS_IN_A_TICK); |
||
57 |
|||
58 |
1 |
tick_time = 10000; |
|
59 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(0) == 10000 * MILLISECONDS_IN_A_TICK); |
60 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(10) == 9990 * MILLISECONDS_IN_A_TICK); |
61 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(10000) == 0 * MILLISECONDS_IN_A_TICK); |
62 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 1) == |
63 |
10001 * MILLISECONDS_IN_A_TICK); |
||
64 |
1 |
} |
|
65 |
|||
66 |
✓✗ | 3 |
TEST_CASE("timer get_elapsed_time1", "") |
67 |
{ |
||
68 |
1 |
tick_time = 0; |
|
69 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(0) == 0); |
70 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 1) == 1); |
71 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 2) == 2); |
72 |
|||
73 |
1 |
tick_time = 1; |
|
74 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(0) == 1); |
75 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(1) == 0); |
76 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 1) == 2); |
77 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 2) == 3); |
78 |
|||
79 |
1 |
tick_time = 10; |
|
80 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(0) == 10); |
81 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(10) == 0); |
82 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 1) == 11); |
83 |
|||
84 |
1 |
tick_time = 10000; |
|
85 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(0) == 10000); |
86 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(10) == 9990); |
87 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(10000) == 0); |
88 |
✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗ |
4 |
REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 1) == 10001); |
89 |
✓✗✓✗ |
4 |
} |
Generated by: GCOVR (Version 3.3) |