Files
range/test/array.cpp

88 lines
3.1 KiB
C++
Raw Normal View History

2004-06-29 02:58:13 +00:00
// Boost.Range library
//
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
// distribution is subject to 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)
//
// For more information, see http://www.boost.org/libs/range/
//
2004-07-29 14:20:35 +00:00
2004-07-29 14:45:19 +00:00
#include <boost/detail/workaround.hpp>
2004-07-29 14:20:35 +00:00
2004-07-29 14:28:41 +00:00
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
2004-07-29 14:20:35 +00:00
# pragma warn -8091 // supress warning in Boost.Test
# pragma warn -8057 // unused argument argc/argv in Boost.Test
#endif
2004-06-29 02:58:13 +00:00
#include <boost/range.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include <iostream>
2004-07-20 15:16:22 +00:00
// This should be included before "using namespace boost",
// otherwise gcc headers will be confused with boost::iterator
// namespace.
#include <boost/test/included/unit_test_framework.hpp>
2004-06-29 02:58:13 +00:00
using namespace boost;
using namespace std;
void check_array()
{
const int sz = 9;
typedef int array_t[sz];
int my_array[sz] = { 1,2,3,4,5,6,7,8,9 };
const array_t ca = { 1,2,3,4,5,6,7,8,10 };
2004-07-29 14:20:35 +00:00
// BOOST_RANGE_NO_STATIC_ASSERT
2004-07-30 21:07:56 +00:00
#if !defined( __BORLANDC__ )
BOOST_STATIC_ASSERT(( is_same< value_type_of<int[10]>::type, int >::value ));
BOOST_STATIC_ASSERT(( is_same< iterator_of<int[10]>::type, int* >::value ));
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<int[10]>::type, const int* >::value ));
BOOST_STATIC_ASSERT(( is_same< difference_type_of<int[10]>::type, std::ptrdiff_t >::value ));
BOOST_STATIC_ASSERT(( is_same< size_type_of<int[10]>::type, std::size_t >::value ));
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<int[10]>::type, int* >::value ));
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const int[10]>::type, const int* >::value ));
2004-06-29 02:58:13 +00:00
2004-07-30 21:07:56 +00:00
BOOST_STATIC_ASSERT(( is_same< value_type_of<const int[10]>::type, const int >::value ));
BOOST_STATIC_ASSERT(( is_same< iterator_of<const int[10]>::type, const int* >::value ));
BOOST_STATIC_ASSERT(( is_same< const_iterator_of<const int[10]>::type, const int* >::value ));
BOOST_STATIC_ASSERT(( is_same< difference_type_of<const int[10]>::type, std::ptrdiff_t >::value ));
BOOST_STATIC_ASSERT(( is_same< size_type_of<const int[10]>::type, std::size_t >::value ));
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const int[10]>::type, const int* >::value ));
BOOST_STATIC_ASSERT(( is_same< result_iterator_of<const int[10]>::type, const int* >::value ));
2004-06-29 02:58:13 +00:00
#endif
BOOST_CHECK_EQUAL( begin( my_array ), my_array );
BOOST_CHECK_EQUAL( end( my_array ), my_array + size( my_array ) );
BOOST_CHECK_EQUAL( empty( my_array ), false );
BOOST_CHECK_EQUAL( begin( ca ), ca );
BOOST_CHECK_EQUAL( end( ca ), ca + size( ca ) );
BOOST_CHECK_EQUAL( empty( ca ),false );
}
2004-07-20 15:16:22 +00:00
2004-06-29 02:58:13 +00:00
using boost::unit_test_framework::test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] )
{
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
test->add( BOOST_TEST_CASE( &check_array ) );
return test;
}