mirror of
https://github.com/boostorg/core.git
synced 2025-05-09 23:03:54 +00:00
Added BOOST_TEST_GT and BOOST_TEST_GE.
Just LT and LE are insufficient for testing operator overloads.
This commit is contained in:
parent
226ef58027
commit
3a2c94df8c
@ -2,6 +2,7 @@
|
||||
Copyright 2010, 2011 Beman Dawes
|
||||
Copyright 2013 Ion Gaztanaga
|
||||
Copyright 2014, 2017 Peter Dimov
|
||||
Copyright 2017 Kohei Takahashi
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
@ -38,6 +39,8 @@ When using `lightweight_test.hpp`, *do not forget* to
|
||||
#define BOOST_TEST_NE(expr1, expr2) /*unspecified*/
|
||||
#define BOOST_TEST_LT(expr1, expr2) /*unspecified*/
|
||||
#define BOOST_TEST_LE(expr1, expr2) /*unspecified*/
|
||||
#define BOOST_TEST_GT(expr1, expr2) /*unspecified*/
|
||||
#define BOOST_TEST_GE(expr1, expr2) /*unspecified*/
|
||||
#define BOOST_TEST_CSTR_EQ(expr1, expr2) /*unspecified*/
|
||||
#define BOOST_TEST_CSTR_NE(expr1, expr2) /*unspecified*/
|
||||
#define BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) /* unspecified */
|
||||
@ -129,6 +132,28 @@ message containing both expressions.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section BOOST_TEST_GT]
|
||||
|
||||
``
|
||||
BOOST_TEST_GT(expr1, expr2)
|
||||
``
|
||||
|
||||
If `expr1 > expr2` is not true increases the error count and outputs a
|
||||
message containing both expressions.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section BOOST_TEST_GE]
|
||||
|
||||
``
|
||||
BOOST_TEST_GE(expr1, expr2)
|
||||
``
|
||||
|
||||
If `expr1 >= expr2` is not true increases the error count and outputs a
|
||||
message containing both expressions.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section BOOST_TEST_CSTR_EQ]
|
||||
|
||||
``
|
||||
|
@ -186,6 +186,40 @@ template<class T, class U> inline void test_le_impl( char const * expr1, char co
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class U> inline void test_gt_impl( char const * expr1, char const * expr2,
|
||||
char const * file, int line, char const * function, T const & t, U const & u )
|
||||
{
|
||||
if( t > u )
|
||||
{
|
||||
report_errors_remind();
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
||||
<< file << "(" << line << "): test '" << expr1 << " > " << expr2
|
||||
<< "' failed in function '" << function << "': "
|
||||
<< "'" << test_output_impl(t) << "' <= '" << test_output_impl(u) << "'" << std::endl;
|
||||
++test_errors();
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class U> inline void test_ge_impl( char const * expr1, char const * expr2,
|
||||
char const * file, int line, char const * function, T const & t, U const & u )
|
||||
{
|
||||
if( t >= u )
|
||||
{
|
||||
report_errors_remind();
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
||||
<< file << "(" << line << "): test '" << expr1 << " >= " << expr2
|
||||
<< "' failed in function '" << function << "': "
|
||||
<< "'" << test_output_impl(t) << "' < '" << test_output_impl(u) << "'" << std::endl;
|
||||
++test_errors();
|
||||
}
|
||||
}
|
||||
|
||||
inline void test_cstr_eq_impl( char const * expr1, char const * expr2,
|
||||
char const * file, int line, char const * function, char const * const t, char const * const u )
|
||||
{
|
||||
@ -401,6 +435,8 @@ inline int report_errors()
|
||||
|
||||
#define BOOST_TEST_LT(expr1,expr2) ( ::boost::detail::test_lt_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
|
||||
#define BOOST_TEST_LE(expr1,expr2) ( ::boost::detail::test_le_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
|
||||
#define BOOST_TEST_GT(expr1,expr2) ( ::boost::detail::test_gt_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
|
||||
#define BOOST_TEST_GE(expr1,expr2) ( ::boost::detail::test_ge_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
|
||||
|
||||
#define BOOST_TEST_CSTR_EQ(expr1,expr2) ( ::boost::detail::test_cstr_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
|
||||
#define BOOST_TEST_CSTR_NE(expr1,expr2) ( ::boost::detail::test_cstr_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
|
||||
|
@ -70,6 +70,7 @@ run lightweight_test_all_eq_test.cpp ;
|
||||
run lightweight_test_all_with_test.cpp ;
|
||||
run lightweight_test_all_with_fail.cpp ;
|
||||
run lightweight_test_lt_le_test.cpp ;
|
||||
run lightweight_test_gt_ge_test.cpp ;
|
||||
|
||||
run lightweight_test_eq_nullptr.cpp ;
|
||||
|
||||
@ -87,6 +88,8 @@ run-fail lightweight_test_fail9.cpp ;
|
||||
run-fail lightweight_test_fail10.cpp ;
|
||||
run-fail lightweight_test_lt_fail.cpp ;
|
||||
run-fail lightweight_test_le_fail.cpp ;
|
||||
run-fail lightweight_test_gt_fail.cpp ;
|
||||
run-fail lightweight_test_ge_fail.cpp ;
|
||||
|
||||
run is_same_test.cpp ;
|
||||
|
||||
|
20
test/lightweight_test_ge_fail.cpp
Normal file
20
test/lightweight_test_ge_fail.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// Negative test for BOOST_TEST_GE
|
||||
//
|
||||
// Copyright 2017 Kohei Takahashi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
BOOST_TEST_GE( x, 1 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
20
test/lightweight_test_gt_fail.cpp
Normal file
20
test/lightweight_test_gt_fail.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// Negative test for BOOST_TEST_GT
|
||||
//
|
||||
// Copyright 2017 Kohei Takahashi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
BOOST_TEST_GT( x, 0 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
34
test/lightweight_test_gt_ge_test.cpp
Normal file
34
test/lightweight_test_gt_ge_test.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
//
|
||||
// Test for BOOST_TEST_GT, BOOST_TEST_GE
|
||||
//
|
||||
// Copyright 2017 Kohei Takahashi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
BOOST_TEST_GT( x, -1 );
|
||||
BOOST_TEST_GT( ++x, 0 );
|
||||
BOOST_TEST_GT( x++, 0 );
|
||||
|
||||
BOOST_TEST_GE( x, 2 );
|
||||
BOOST_TEST_GE( ++x, 3 );
|
||||
BOOST_TEST_GE( x++, 3 );
|
||||
|
||||
int y = 5;
|
||||
|
||||
BOOST_TEST_GT( ++y, ++x );
|
||||
BOOST_TEST_GT( y++, x++ );
|
||||
|
||||
BOOST_TEST_GE( ++y, x );
|
||||
BOOST_TEST_GE( y++, x++ );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user