KGantt

test.cpp
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KGantt library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#ifndef KDAB_NO_UNIT_TESTS
10
11#include "test.h"
12
13#ifdef TEMPORARILY_REMOVED
14#include <trinav/ascshared/libfakes/fakes.h>
15#endif
16
17#include <cmath>
18#include <limits>
19
20KDAB::UnitTest::Test::Test( const std::string & n )
21 : mName( n ), mFailed( 0 ), mSucceeded( 0 ) {}
22
23void KDAB::UnitTest::Test::_assertNotNull( const void * x, const char * expression, const char * file, unsigned int line ) {
24 if ( x ) success();
25 else fail( file, line ) << '"' << expression << "\" is NULL, expected non-NULL" << std::endl;
26}
27
28void KDAB::UnitTest::Test::_assertNull( const void * x, const char * expression, const char * file, unsigned int line ) {
29 if ( !x ) success();
30 else fail( file, line ) << '"' << expression << "\" is not NULL, expected NULL" << std::endl;
31}
32
33#if 0
34void KDAB::UnitTest::Test::_assertIsNaN( qreal d, const char * expression, const char * file, unsigned int line ) {
35 if ( std::isnan( d ) ) success();
36 else fail( file, line ) << '"' << expression << "\" yielded " << d << "; expected NaN" << std::endl;
37}
38
39void KDAB::UnitTest::Test::_assertIsNotNaN( qreal d, const char * expression, const char * file, unsigned int line ) {
40 if ( !std::isnan( d ) ) success();
41 else fail( file, line ) << '"' << expression << "\" yielded nan; expected something else" << std::endl;
42}
43#endif
44
45void KDAB::UnitTest::Test::_assertTrue( bool x, const char * expression, const char * file, unsigned int line ) {
46 if ( x ) success();
47 else fail( file, line ) << '"' << expression << "\" != TRUE" << std::endl;
48}
49
50void KDAB::UnitTest::Test::_assertFalse( bool x, const char * expression, const char * file, unsigned int line ) {
51 if ( !x ) success();
52 else fail( file, line ) << '"' << expression << "\" != FALSE" << std::endl;
53}
54
55void KDAB::UnitTest::Test::_assertEqualWithEpsilons( float x1, float x2, int prec, const char * expr1, const char * expr2, const char * exprP, const char * file, unsigned int line ) {
56 if ( qAbs( x1/x2 - 1.0f ) <= prec * std::numeric_limits<float>::epsilon() ) success();
57 else fail( file, line ) << x1 << " (" << expr1 << ") deviates from expected "
58 << x2 << " (" << expr2 << ") by more than "
59 << prec << " (" << exprP << ") epsilons." << std::endl;
60}
61
62void KDAB::UnitTest::Test::_assertEqualWithEpsilons( qreal x1, qreal x2, int prec, const char * expr1, const char * expr2, const char * exprP, const char * file, unsigned int line ) {
63 if ( qAbs( x1/x2 - 1.0 ) <= prec * std::numeric_limits<qreal>::epsilon() ) success();
64 else fail( file, line ) << x1 << " (" << expr1 << ") deviates from expected "
65 << x2 << " (" << expr2 << ") by more than "
66 << prec << " (" << exprP << ") epsilons." << std::endl;
67}
68
69void KDAB::UnitTest::Test::_assertEqualWithEpsilons( long double x1, long double x2, int prec, const char * expr1, const char * expr2, const char * exprP, const char * file, unsigned int line ) {
70 if ( qAbs( x1/x2 - 1.0l ) <= prec * std::numeric_limits<long double>::epsilon() ) success();
71 else fail( file, line ) << x1 << " (" << expr1 << ") deviates from expected "
72 << x2 << " (" << expr2 << ") by more than "
73 << prec << " (" << exprP << ") epsilons." << std::endl;
74}
75
76std::ostream & KDAB::UnitTest::Test::fail( const char * file, unsigned int line ) {
77 ++mFailed;
78 return std::cerr << "FAIL: " << file << ':' << line << ": ";
79}
80
81#endif // KDAB_NO_UNIT_TESTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.