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

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



168
    SECTION("reportFalse")
86
    {
87




8
        REQUIRE(reportFalseReal(false) == false);
88



8
        REQUIRE(reportFalseReal(true) == true);
89
    }
90
91



168
    SECTION("reportTrue")
92
    {
93



8
        REQUIRE(reportTrueReal(false) == false);
94




8
        REQUIRE(reportTrueReal(true) == true);
95
    }
96
97



168
    SECTION("reportAlways")
98
    {
99

2
        reportAlwaysReal("test report");
100
    }
101
102



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






12
        REQUIRE_THROWS(failFalse(false));
107



8
        REQUIRE(failFalse(true) == true);
108






12
        REQUIRE_THROWS(reportFalse(false));
109



8
        REQUIRE(reportFalse(true) == true);
110
PRAGMA4(GCC diagnostic pop)
111
    }
112
113



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



8
        REQUIRE(failTrue(false) == false);
118






12
        REQUIRE_THROWS(failTrue(true));
119



8
        REQUIRE(reportTrue(false) == false);
120






12
        REQUIRE_THROWS(reportTrue(true));
121
PRAGMA4(GCC diagnostic pop)
122
    }
123
124



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





12
        REQUIRE_THROWS(testFailAlways1());
129





12
        REQUIRE_THROWS(testFailAlways2());
130
PRAGMA4(GCC diagnostic pop)
131
    }
132
133



168
    SECTION("returnFalseV")
134
    {
135
        testReturnFalseV(false);
136



8
        REQUIRE(flag == false);
137
        testReturnFalseV(true);
138



8
        REQUIRE(flag == true);
139
    }
140
141



168
    SECTION("returnTrueV")
142
    {
143
        testReturnTrueV(false);
144



8
        REQUIRE(flag == true);
145
        testReturnTrueV(true);
146



8
        REQUIRE(flag == false);
147
    }
148
149



168
    SECTION("returnFalse")
150
    {
151



10
        REQUIRE(testReturnFalse(false) == 0);
152



8
        REQUIRE(testReturnFalse(true) == 1);
153
    }
154
155



168
    SECTION("returnTrue")
156
    {
157



8
        REQUIRE(testReturnTrue(false) == 1);
158



10
        REQUIRE(testReturnTrue(true) == 0);
159
    }
160
161



168
    SECTION("returnNullptr")
162
    {
163



10
        REQUIRE(testReturnNullptr(nullptr) == 0);
164



8
        REQUIRE(testReturnNullptr(reinterpret_cast<void*>(1)) == 1);
165
    }
166
167



168
    SECTION("returnNullptrV")
168
    {
169
        testReturnNullptrV(nullptr);
170



8
        REQUIRE(flag == false);
171
        testReturnNullptrV(reinterpret_cast<void*>(1));
172



8
        REQUIRE(flag == true);
173
    }
174

30
}