GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/timer.cc Lines: 43 43 100.0 %
Date: 2017-11-29 Branches: 149 414 36.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "unittests/unittests.h"
22
23
#include "const/utils/timer.h"
24
25
#include "utils/timer.h"
26
27
#include <climits>
28
29
#include "debug.h"
30
31
static const int MAX_TICK_VALUE = INT_MAX / 2;
32
33
6
TEST_CASE("timer const", "")
34
{
35



8
    REQUIRE(MILLISECONDS_IN_A_TICK != 0);
36
2
}
37
38
6
TEST_CASE("timer get_elapsed_time", "")
39
{
40
2
    tick_time = 0;
41



8
    REQUIRE(get_elapsed_time(0) == 0);
42



8
    REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 1) == 1 * MILLISECONDS_IN_A_TICK);
43



8
    REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 2) == 2 * MILLISECONDS_IN_A_TICK);
44
45
2
    tick_time = 1;
46



8
    REQUIRE(get_elapsed_time(0) == 1 * MILLISECONDS_IN_A_TICK);
47



8
    REQUIRE(get_elapsed_time(1) == 0 * MILLISECONDS_IN_A_TICK);
48



8
    REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 1) == 2 * MILLISECONDS_IN_A_TICK);
49



8
    REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 2) == 3 * MILLISECONDS_IN_A_TICK);
50
51
2
    tick_time = 10;
52



8
    REQUIRE(get_elapsed_time(0) == 10 * MILLISECONDS_IN_A_TICK);
53



8
    REQUIRE(get_elapsed_time(10) == 0 * MILLISECONDS_IN_A_TICK);
54



8
    REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 1) ==
55
        11 * MILLISECONDS_IN_A_TICK);
56
57
2
    tick_time = 10000;
58



8
    REQUIRE(get_elapsed_time(0) == 10000 * MILLISECONDS_IN_A_TICK);
59



8
    REQUIRE(get_elapsed_time(10) == 9990 * MILLISECONDS_IN_A_TICK);
60



8
    REQUIRE(get_elapsed_time(10000) == 0 * MILLISECONDS_IN_A_TICK);
61



8
    REQUIRE(get_elapsed_time(MAX_TICK_VALUE - 1) ==
62
        10001 * MILLISECONDS_IN_A_TICK);
63
2
}
64
65
6
TEST_CASE("timer get_elapsed_time1", "")
66
{
67
2
    tick_time = 0;
68



8
    REQUIRE(get_elapsed_time1(0) == 0);
69



8
    REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 1) == 1);
70



8
    REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 2) == 2);
71
72
2
    tick_time = 1;
73



8
    REQUIRE(get_elapsed_time1(0) == 1);
74



8
    REQUIRE(get_elapsed_time1(1) == 0);
75



8
    REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 1) == 2);
76



8
    REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 2) == 3);
77
78
2
    tick_time = 10;
79



8
    REQUIRE(get_elapsed_time1(0) == 10);
80



8
    REQUIRE(get_elapsed_time1(10) == 0);
81



8
    REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 1) == 11);
82
83
2
    tick_time = 10000;
84



8
    REQUIRE(get_elapsed_time1(0) == 10000);
85



8
    REQUIRE(get_elapsed_time1(10) == 9990);
86



8
    REQUIRE(get_elapsed_time1(10000) == 0);
87



8
    REQUIRE(get_elapsed_time1(MAX_TICK_VALUE - 1) == 10001);
88

8
}