forked from boostorg/core
Move sp_typeinfo to core; add BOOST_TEST_TRAIT_*; add core::is_same; add more tests using those.
This commit is contained in:
@@ -56,3 +56,12 @@ run-fail lightweight_test_fail3.cpp ;
|
||||
run-fail lightweight_test_fail4.cpp ;
|
||||
run-fail lightweight_test_fail5.cpp ;
|
||||
run-fail lightweight_test_fail6.cpp ;
|
||||
run-fail lightweight_test_fail7.cpp ;
|
||||
run-fail lightweight_test_fail8.cpp ;
|
||||
|
||||
run is_same_test.cpp ;
|
||||
|
||||
run typeinfo_test.cpp ;
|
||||
run typeinfo_test.cpp : : : <rtti>off : typeinfo_test_no_rtti ;
|
||||
|
||||
run iterator_test.cpp ;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Test for core::is_same<T1,T2>
|
||||
//
|
||||
// Copyright 2014 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/iterator.hpp>
|
||||
#include <boost/core/is_same.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<X, X> ));
|
||||
BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<Y, Y> ));
|
||||
BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<void, void> ));
|
||||
BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<int, int> ));
|
||||
BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<void const volatile, void const volatile> ));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<X, Y> ));
|
||||
BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<X, X const> ));
|
||||
BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<X, void> ));
|
||||
BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<X, int> ));
|
||||
BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<int, void> ));
|
||||
BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<void, void const volatile> ));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// Test for boost/iterator.hpp
|
||||
//
|
||||
// Copyright 2014 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/iterator.hpp>
|
||||
#include <boost/core/is_same.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
/*
|
||||
|
||||
template< class Category, class T,
|
||||
class Distance = ptrdiff_t,
|
||||
class Pointer = T*,
|
||||
class Reference = T&>
|
||||
struct iterator
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef Distance difference_type;
|
||||
typedef Pointer pointer;
|
||||
typedef Reference reference;
|
||||
typedef Category iterator_category;
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
struct C
|
||||
{
|
||||
};
|
||||
|
||||
struct T
|
||||
{
|
||||
};
|
||||
|
||||
struct D
|
||||
{
|
||||
};
|
||||
|
||||
struct P
|
||||
{
|
||||
};
|
||||
|
||||
struct R
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::core::is_same;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T,D,P,R>::iterator_category,C>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T,D,P,R>::value_type,T>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T,D,P,R>::difference_type,D>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T,D,P,R>::pointer,P>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T,D,P,R>::reference,R>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T>::iterator_category,C>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T>::value_type,T>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T>::difference_type,std::ptrdiff_t>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T>::pointer,T*>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T>::reference,T&>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Negative test for BOOST_TEST_TRAIT_TRUE
|
||||
//
|
||||
// Copyright (c) 2014 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/detail/lightweight_test.hpp>
|
||||
|
||||
template<class T1, class T2> struct Y1
|
||||
{
|
||||
enum { value = 1 };
|
||||
};
|
||||
|
||||
template<class T1, class T2> struct Y2
|
||||
{
|
||||
enum { value = 0 };
|
||||
};
|
||||
|
||||
struct X1
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
struct X2
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE(( Y2<X1::type, X2::type> ));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Negative test for BOOST_TEST_TRAIT_FALSE
|
||||
//
|
||||
// Copyright (c) 2014 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/detail/lightweight_test.hpp>
|
||||
|
||||
template<class T1, class T2> struct Y1
|
||||
{
|
||||
enum { value = 1 };
|
||||
};
|
||||
|
||||
template<class T1, class T2> struct Y2
|
||||
{
|
||||
enum { value = 0 };
|
||||
};
|
||||
|
||||
struct X1
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
struct X2
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE(( Y1<X1::type, X2::type> ));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -32,6 +32,26 @@ void f( bool x )
|
||||
}
|
||||
}
|
||||
|
||||
template<class T1, class T2> struct Y1
|
||||
{
|
||||
enum { value = 1 };
|
||||
};
|
||||
|
||||
template<class T1, class T2> struct Y2
|
||||
{
|
||||
enum { value = 0 };
|
||||
};
|
||||
|
||||
struct X1
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
struct X2
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 0;
|
||||
@@ -68,7 +88,13 @@ int main()
|
||||
BOOST_TEST_THROWS( f(true), X );
|
||||
BOOST_TEST_THROWS( f(false), int );
|
||||
|
||||
//
|
||||
// BOOST_TEST_TRAIT_TRUE
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE(( Y1<X1::type, X2::type> ));
|
||||
|
||||
// BOOST_TEST_TRAIT_FALSE
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(( Y2<X1::type, X2::type> ));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// typeinfo_test.cpp
|
||||
//
|
||||
// Copyright (c) 2009 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/core/typeinfo.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( BOOST_CORE_TYPEID( int ) == BOOST_CORE_TYPEID( int ) );
|
||||
BOOST_TEST( BOOST_CORE_TYPEID( int ) != BOOST_CORE_TYPEID( long ) );
|
||||
BOOST_TEST( BOOST_CORE_TYPEID( int ) != BOOST_CORE_TYPEID( void ) );
|
||||
|
||||
boost::core::typeinfo const & ti = BOOST_CORE_TYPEID( int );
|
||||
|
||||
boost::core::typeinfo const * pti = &BOOST_CORE_TYPEID( int );
|
||||
BOOST_TEST( *pti == ti );
|
||||
|
||||
BOOST_TEST( ti == ti );
|
||||
BOOST_TEST( !( ti != ti ) );
|
||||
BOOST_TEST( !ti.before( ti ) );
|
||||
|
||||
char const * nti = ti.name();
|
||||
std::cout << nti << std::endl;
|
||||
|
||||
boost::core::typeinfo const & tv = BOOST_CORE_TYPEID( void );
|
||||
|
||||
boost::core::typeinfo const * ptv = &BOOST_CORE_TYPEID( void );
|
||||
BOOST_TEST( *ptv == tv );
|
||||
|
||||
BOOST_TEST( tv == tv );
|
||||
BOOST_TEST( !( tv != tv ) );
|
||||
BOOST_TEST( !tv.before( tv ) );
|
||||
|
||||
char const * ntv = tv.name();
|
||||
std::cout << ntv << std::endl;
|
||||
|
||||
BOOST_TEST( ti != tv );
|
||||
BOOST_TEST( !( ti == tv ) );
|
||||
|
||||
BOOST_TEST( ti.before( tv ) != tv.before( ti ) );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
Reference in New Issue
Block a user