Update contrib.
1 /* tests for using class array<> specialization for size 0
2 * (C) Copyright Alisdair Meredith 2006.
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
13 #include <boost/array.hpp>
16 #include "std_log_result.h"
17 #define LOG_FILENAME_LINE __FILE__, __LINE__
21 unsigned int failed_tests = 0;
23 void fail_test( const char * reason ) {
25 std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
29 void BadValue( const T & )
31 fail_test( "Unexpected value" );
37 typedef boost::array< T, 0 > test_type;
39 // Test value and aggegrate initialization
40 test_type test_case = {};
41 const boost::array< T, 0 > const_test_case = test_type();
43 test_case.assign( T() );
45 // front/back and operator[] must compile, but calling them is undefined
46 // Likewise, all tests below should evaluate to false, avoiding undefined behaviour
47 if( !test_case.empty() ) {
48 BadValue( test_case.front() );
51 if( !const_test_case.empty() ) {
52 BadValue( const_test_case.back() );
55 if( test_case.size() > 0 ) {
56 BadValue( test_case[ 0 ] );
59 if( const_test_case.max_size() > 0 ) {
60 BadValue( const_test_case[ 0 ] );
63 // Assert requirements of TR1 6.2.2.4
64 if( test_case.begin() != test_case.end() ) {
65 fail_test( "Not an empty range" );
67 if( const_test_case.begin() != const_test_case.end() ) {
68 fail_test( "Not an empty range" );
71 if( test_case.begin() == const_test_case.begin() ) {
72 fail_test( "iterators for different containers are not distinct" );
75 if( test_case.data() == const_test_case.data() ) {
76 // Value of data is unspecified in TR1, so no requirement this test pass or fail
77 // However, it must compile!
81 // Check can safely use all iterator types with std algorithms
82 std::for_each( test_case.begin(), test_case.end(), BadValue< T > );
83 std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > );
84 std::for_each( const_test_case.begin(), const_test_case.end(), BadValue< T > );
85 std::for_each( const_test_case.rbegin(), const_test_case.rend(), BadValue< T > );
87 // Check swap is well formed
88 std::swap( test_case, test_case );
90 // Check assigment operator and overloads are well formed
91 test_case = const_test_case;
93 // Confirm at() throws the std lib defined exception
95 BadValue( test_case.at( 0 ) );
96 } catch ( const std::range_error & ) {
100 BadValue( const_test_case.at( 0 ) );
101 } catch ( const std::range_error & ) {
109 std_log(LOG_FILENAME_LINE,"[Test Case for array0]");
111 RunTests< void * >();
112 RunTests< long double >();
113 RunTests< std::string >();
117 std_log(LOG_FILENAME_LINE,"Result : Failed");
118 assert_failed = true;
122 std_log(LOG_FILENAME_LINE,"Result : Passed");
124 std_log(LOG_FILENAME_LINE,"[End Test Case ]");
126 testResultXml("array0");