mirror of
https://github.com/boostorg/core.git
synced 2025-07-29 20:37:22 +02:00
Make BOOST_TEST_EQ/NE work with nullptr
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
#include <boost/core/no_exceptions_support.hpp>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <cstddef>
|
||||
|
||||
// IDE's like Visual Studio perform better if output goes to std::cout or
|
||||
// some other stream, so allow user to configure output stream:
|
||||
@ -113,6 +114,10 @@ inline const void* test_output_impl(unsigned char* v) { return v; }
|
||||
inline const void* test_output_impl(signed char* v) { return v; }
|
||||
template<class T> inline const void* test_output_impl(T volatile* v) { return const_cast<T*>(v); }
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
inline const void* test_output_impl(std::nullptr_t v) { return v; }
|
||||
#endif
|
||||
|
||||
template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2,
|
||||
char const * file, int line, char const * function, T const & t, U const & u )
|
||||
{
|
||||
|
@ -71,6 +71,8 @@ run lightweight_test_all_with_test.cpp ;
|
||||
run lightweight_test_all_with_fail.cpp ;
|
||||
run lightweight_test_lt_le_test.cpp ;
|
||||
|
||||
run lightweight_test_eq_nullptr.cpp ;
|
||||
|
||||
run-fail lightweight_test_fail.cpp ;
|
||||
run-fail lightweight_test_fail2.cpp ;
|
||||
run-fail lightweight_test_fail3.cpp ;
|
||||
|
28
test/lightweight_test_eq_nullptr.cpp
Normal file
28
test/lightweight_test_eq_nullptr.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// Test BOOST_TEST_EQ( p, nullptr )
|
||||
//
|
||||
// Copyright 2017 Peter Dimov
|
||||
//
|
||||
// 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/config.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if !defined( BOOST_NO_CXX11_NULLPTR )
|
||||
|
||||
int x = 0;
|
||||
int* p1 = 0;
|
||||
int* p2 = &x;
|
||||
|
||||
BOOST_TEST_EQ( p1, nullptr );
|
||||
BOOST_TEST_NE( p2, nullptr );
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user