GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/checkutils.cc Lines: 57 57 100.0 %
Date: 2021-03-17 Branches: 262 592 44.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2016-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 "utils/checkutils.h"
25
26
#include "debug.h"
27
28
namespace
29
{
30
    bool flag = false;
31
}  // namespace
32
33
static void testReturnFalseV(const bool val)
34
{
35
1
    flag = false;
36
1
    returnFalseVReal(val);
37
1
    flag = true;
38
}
39
40
static void testReturnTrueV(const bool val)
41
{
42
1
    flag = false;
43
1
    returnTrueVReal(val);
44
1
    flag = true;
45
}
46
47
static int testReturnFalse(const bool val)
48
{
49
1
    returnFalseReal(0, val);
50
    return 1;
51
}
52
53
static int testReturnTrue(const bool val)
54
{
55
1
    returnTrueReal(0, val);
56
    return 1;
57
}
58
59
static int testReturnNullptr(void *val)
60
{
61
1
    returnNullptrReal(0, val);
62
    return 1;
63
}
64
65
static void testReturnNullptrV(void *val)
66
{
67
1
    flag = false;
68
1
    returnNullptrVReal(val);
69
1
    flag = true;
70
}
71
72
1
static bool testFailAlways1()
73
{
74
2
    failAlways("test fail");
75
    return false;
76
}
77
78
1
static bool testFailAlways2()
79
{
80
2
    reportAlways("test fail")
81
    return false;
82
}
83
84
14
TEST_CASE("CheckUtils", "")
85
{
86



84
    SECTION("reportFalse")
87
    {
88




4
        REQUIRE(reportFalseReal(false) == false);
89



4
        REQUIRE(reportFalseReal(true) == true);
90
    }
91
92



84
    SECTION("reportTrue")
93
    {
94



4
        REQUIRE(reportTrueReal(false) == false);
95




4
        REQUIRE(reportTrueReal(true) == true);
96
    }
97
98



84
    SECTION("reportAlways")
99
    {
100

1
        reportAlwaysReal("test report")
101
    }
102
103



84
    SECTION("failFalse")
104
    {
105
PRAGMA4(GCC diagnostic push)
106
PRAGMA4(GCC diagnostic ignored "-Wunused-value")
107






6
        REQUIRE_THROWS(failFalse(false));
108



4
        REQUIRE(failFalse(true) == true);
109






6
        REQUIRE_THROWS(reportFalse(false));
110



4
        REQUIRE(reportFalse(true) == true);
111
PRAGMA4(GCC diagnostic pop)
112
    }
113
114



84
    SECTION("failTrue")
115
    {
116
PRAGMA4(GCC diagnostic push)
117
PRAGMA4(GCC diagnostic ignored "-Wunused-value")
118



4
        REQUIRE(failTrue(false) == false);
119






6
        REQUIRE_THROWS(failTrue(true));
120



4
        REQUIRE(reportTrue(false) == false);
121






6
        REQUIRE_THROWS(reportTrue(true));
122
PRAGMA4(GCC diagnostic pop)
123
    }
124
125



84
    SECTION("failAlways")
126
    {
127
PRAGMA4(GCC diagnostic push)
128
PRAGMA4(GCC diagnostic ignored "-Wunused-value")
129





5
        REQUIRE_THROWS(testFailAlways1());
130





5
        REQUIRE_THROWS(testFailAlways2());
131
PRAGMA4(GCC diagnostic pop)
132
    }
133
134



84
    SECTION("returnFalseV")
135
    {
136
        testReturnFalseV(false);
137



4
        REQUIRE(flag == false);
138
        testReturnFalseV(true);
139



4
        REQUIRE(flag == true);
140
    }
141
142



84
    SECTION("returnTrueV")
143
    {
144
        testReturnTrueV(false);
145



4
        REQUIRE(flag == true);
146
        testReturnTrueV(true);
147



4
        REQUIRE(flag == false);
148
    }
149
150



84
    SECTION("returnFalse")
151
    {
152



5
        REQUIRE(testReturnFalse(false) == 0);
153



4
        REQUIRE(testReturnFalse(true) == 1);
154
    }
155
156



84
    SECTION("returnTrue")
157
    {
158



4
        REQUIRE(testReturnTrue(false) == 1);
159



5
        REQUIRE(testReturnTrue(true) == 0);
160
    }
161
162



84
    SECTION("returnNullptr")
163
    {
164



5
        REQUIRE(testReturnNullptr(nullptr) == 0);
165



4
        REQUIRE(testReturnNullptr(reinterpret_cast<void*>(1)) == 1);
166
    }
167
168



84
    SECTION("returnNullptrV")
169
    {
170
        testReturnNullptrV(nullptr);
171



4
        REQUIRE(flag == false);
172
        testReturnNullptrV(reinterpret_cast<void*>(1));
173



4
        REQUIRE(flag == true);
174
    }
175

15
}