Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/ConditionTests.cpp
diff options
context:
space:
mode:
authorPhil Nash2015-12-04 10:19:08 +0000
committerPhil Nash2015-12-04 10:19:08 +0000
commitfdc42d0af47f58fa13a42b685bbeaf55a8347673 (patch)
tree779ff3d692eeffd33353d89ad7697a592ab5201e /projects/SelfTest/ConditionTests.cpp
parentd758428fe297655e558a86cc6a013fcb1bcc8c7d (diff)
parentd274fc571c3980b5ac04cbe1416cf2205e6c99f7 (diff)
downloadcatch3-1.3.0.tar.gz
Merged from develop branchv1.3.0
- now v1.3.0
Diffstat (limited to 'projects/SelfTest/ConditionTests.cpp')
-rw-r--r--projects/SelfTest/ConditionTests.cpp77
1 files changed, 39 insertions, 38 deletions
diff --git a/projects/SelfTest/ConditionTests.cpp b/projects/SelfTest/ConditionTests.cpp
index 097c3f33..d1b7ed24 100644
--- a/projects/SelfTest/ConditionTests.cpp
+++ b/projects/SelfTest/ConditionTests.cpp
@@ -6,7 +6,8 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifdef __clang__
-#pragma clang diagnostic ignored "-Wpadded"
+# pragma clang diagnostic ignored "-Wpadded"
+# pragma clang diagnostic ignored "-Wc++98-compat"
#endif
#include "catch.hpp"
@@ -21,7 +22,7 @@ struct TestData {
float_nine_point_one( 9.1f ),
double_pi( 3.1415926535 )
{}
-
+
int int_seven;
std::string str_hello;
float float_nine_point_one;
@@ -36,7 +37,7 @@ struct TestDef {
TestDef& operator[]( const std::string& ) {
return *this;
}
-
+
};
// The "failing" tests all use the CHECK macro, which continues if the specific test fails.
@@ -48,14 +49,14 @@ TEST_CASE( "Equality checks that should succeed", "" )
TestDef td;
td + "hello" + "hello";
-
+
TestData data;
-
+
REQUIRE( data.int_seven == 7 );
REQUIRE( data.float_nine_point_one == Approx( 9.1f ) );
REQUIRE( data.double_pi == Approx( 3.1415926535 ) );
REQUIRE( data.str_hello == "hello" );
- REQUIRE( "hello" == data.str_hello );
+ REQUIRE( "hello" == data.str_hello );
REQUIRE( data.str_hello.size() == 5 );
double x = 1.1 + 0.1 + 0.1;
@@ -65,7 +66,7 @@ TEST_CASE( "Equality checks that should succeed", "" )
TEST_CASE( "Equality checks that should fail", "[.][failing][!mayfail]" )
{
TestData data;
-
+
CHECK( data.int_seven == 6 );
CHECK( data.int_seven == 8 );
CHECK( data.int_seven == 0 );
@@ -86,7 +87,7 @@ TEST_CASE( "Equality checks that should fail", "[.][failing][!mayfail]" )
TEST_CASE( "Inequality checks that should succeed", "" )
{
TestData data;
-
+
REQUIRE( data.int_seven != 6 );
REQUIRE( data.int_seven != 8 );
REQUIRE( data.float_nine_point_one != Approx( 9.11f ) );
@@ -103,7 +104,7 @@ TEST_CASE( "Inequality checks that should succeed", "" )
TEST_CASE( "Inequality checks that should fail", "[.][failing]" )
{
TestData data;
-
+
CHECK( data.int_seven != 7 );
CHECK( data.float_nine_point_one != Approx( 9.1f ) );
CHECK( data.double_pi != Approx( 3.1415926535 ) );
@@ -115,7 +116,7 @@ TEST_CASE( "Inequality checks that should fail", "[.][failing]" )
TEST_CASE( "Ordering comparison checks that should succeed", "" )
{
TestData data;
-
+
REQUIRE( data.int_seven < 8 );
REQUIRE( data.int_seven > 6 );
REQUIRE( data.int_seven > 0 );
@@ -125,14 +126,14 @@ TEST_CASE( "Ordering comparison checks that should succeed", "" )
REQUIRE( data.int_seven >= 6 );
REQUIRE( data.int_seven <= 7 );
REQUIRE( data.int_seven <= 8 );
-
+
REQUIRE( data.float_nine_point_one > 9 );
REQUIRE( data.float_nine_point_one < 10 );
REQUIRE( data.float_nine_point_one < 9.2 );
-
+
REQUIRE( data.str_hello <= "hello" );
REQUIRE( data.str_hello >= "hello" );
-
+
REQUIRE( data.str_hello < "hellp" );
REQUIRE( data.str_hello < "zebra" );
REQUIRE( data.str_hello > "hellm" );
@@ -142,7 +143,7 @@ TEST_CASE( "Ordering comparison checks that should succeed", "" )
TEST_CASE( "Ordering comparison checks that should fail", "[.][failing]" )
{
TestData data;
-
+
CHECK( data.int_seven > 7 );
CHECK( data.int_seven < 7 );
CHECK( data.int_seven > 8 );
@@ -152,11 +153,11 @@ TEST_CASE( "Ordering comparison checks that should fail", "[.][failing]" )
CHECK( data.int_seven >= 8 );
CHECK( data.int_seven <= 6 );
-
+
CHECK( data.float_nine_point_one < 9 );
CHECK( data.float_nine_point_one > 10 );
CHECK( data.float_nine_point_one > 9.2 );
-
+
CHECK( data.str_hello > "hello" );
CHECK( data.str_hello < "hello" );
CHECK( data.str_hello > "hellp" );
@@ -177,7 +178,7 @@ TEST_CASE( "Comparisons with int literals don't warn when mixing signed/ unsigne
unsigned long ul = 4;
char c = 5;
unsigned char uc = 6;
-
+
REQUIRE( i == 1 );
REQUIRE( ui == 2 );
REQUIRE( l == 3 );
@@ -214,7 +215,7 @@ TEST_CASE( "comparisons between int variables", "" )
unsigned short unsigned_short_var = 1;
unsigned int unsigned_int_var = 1;
unsigned long unsigned_long_var = 1L;
-
+
REQUIRE( long_var == unsigned_char_var );
REQUIRE( long_var == unsigned_short_var );
REQUIRE( long_var == unsigned_int_var );
@@ -251,7 +252,7 @@ template<typename T>
struct Ex
{
Ex( T ){}
-
+
bool operator == ( const T& ) const { return true; }
T operator * ( const T& ) const { return T(); }
};
@@ -265,32 +266,32 @@ TEST_CASE( "Comparisons between ints where one side is computed", "" )
#pragma GCC diagnostic pop
#endif
-inline const char* returnsConstNull(){ return NULL; }
-inline char* returnsNull(){ return NULL; }
+inline const char* returnsConstNull(){ return CATCH_NULL; }
+inline char* returnsNull(){ return CATCH_NULL; }
TEST_CASE( "Pointers can be compared to null", "" )
{
- TestData* p = NULL;
- TestData* pNULL = NULL;
-
- REQUIRE( p == NULL );
+ TestData* p = CATCH_NULL;
+ TestData* pNULL = CATCH_NULL;
+
+ REQUIRE( p == CATCH_NULL );
REQUIRE( p == pNULL );
-
+
TestData data;
p = &data;
-
- REQUIRE( p != NULL );
+
+ REQUIRE( p != CATCH_NULL );
const TestData* cp = p;
- REQUIRE( cp != NULL );
+ REQUIRE( cp != CATCH_NULL );
const TestData* const cpc = p;
- REQUIRE( cpc != NULL );
+ REQUIRE( cpc != CATCH_NULL );
+
+ REQUIRE( returnsNull() == CATCH_NULL );
+ REQUIRE( returnsConstNull() == CATCH_NULL );
- REQUIRE( returnsNull() == NULL );
- REQUIRE( returnsConstNull() == NULL );
-
- REQUIRE( NULL != p );
+ REQUIRE( CATCH_NULL != p );
}
// Not (!) tests
@@ -303,7 +304,7 @@ TEST_CASE( "Pointers can be compared to null", "" )
TEST_CASE( "'Not' checks that should succeed", "" )
{
bool falseValue = false;
-
+
REQUIRE( false == false );
REQUIRE( true == true );
REQUIRE( !false );
@@ -319,15 +320,15 @@ TEST_CASE( "'Not' checks that should succeed", "" )
TEST_CASE( "'Not' checks that should fail", "[.][failing]" )
{
bool trueValue = true;
-
+
CHECK( false != false );
CHECK( true != true );
CHECK( !true );
CHECK_FALSE( true );
-
+
CHECK( !trueValue );
CHECK_FALSE( trueValue );
-
+
CHECK( !(1 == 1) );
CHECK_FALSE( 1 == 1 );
}