os/ossrv/stdcpp/tsrc/Boost_test/array/src/array0.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/array/src/array0.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,130 @@
     1.4 +/* tests for using class array<> specialization for size 0
     1.5 + * (C) Copyright Alisdair Meredith 2006.
     1.6 + * Distributed under the Boost Software License, Version 1.0. (See
     1.7 + * accompanying file LICENSE_1_0.txt or copy at
     1.8 + * http://www.boost.org/LICENSE_1_0.txt)
     1.9 + */
    1.10 +/*
    1.11 + * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
    1.12 +*/
    1.13 +
    1.14 +#include <string>
    1.15 +#include <iostream>
    1.16 +#include <boost/array.hpp>
    1.17 +
    1.18 +#ifdef __SYMBIAN32__
    1.19 +#include "std_log_result.h"
    1.20 +#define LOG_FILENAME_LINE __FILE__, __LINE__
    1.21 +#endif
    1.22 +
    1.23 +namespace {
    1.24 +unsigned int failed_tests = 0;
    1.25 +
    1.26 +void    fail_test( const char * reason ) {
    1.27 +    ++failed_tests;
    1.28 +    std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
    1.29 +}
    1.30 +
    1.31 +template< class T >
    1.32 +void    BadValue( const T &  )
    1.33 +{
    1.34 +    fail_test( "Unexpected value" );
    1.35 +}
    1.36 +
    1.37 +template< class T >
    1.38 +void    RunTests()
    1.39 +{
    1.40 +    typedef boost::array< T, 0 >    test_type;
    1.41 +
    1.42 +    //  Test value and aggegrate initialization
    1.43 +    test_type                   test_case   =   {};
    1.44 +    const boost::array< T, 0 >  const_test_case = test_type();
    1.45 +
    1.46 +    test_case.assign( T() );
    1.47 +
    1.48 +    //  front/back and operator[] must compile, but calling them is undefined
    1.49 +    //  Likewise, all tests below should evaluate to false, avoiding undefined behaviour
    1.50 +    if( !test_case.empty() ) {
    1.51 +        BadValue( test_case.front() );
    1.52 +    }
    1.53 +
    1.54 +    if( !const_test_case.empty() ) {
    1.55 +        BadValue( const_test_case.back() );
    1.56 +    }
    1.57 +
    1.58 +    if( test_case.size() > 0 ) {
    1.59 +        BadValue( test_case[ 0 ] );
    1.60 +    }
    1.61 +
    1.62 +    if( const_test_case.max_size() > 0 ) {
    1.63 +        BadValue( const_test_case[ 0 ] );
    1.64 +    }
    1.65 +
    1.66 +    //  Assert requirements of TR1 6.2.2.4
    1.67 +    if( test_case.begin() != test_case.end() ) {
    1.68 +        fail_test( "Not an empty range" );
    1.69 +    }
    1.70 +    if( const_test_case.begin() != const_test_case.end() ) {
    1.71 +        fail_test( "Not an empty range" );
    1.72 +    }
    1.73 +
    1.74 +    if( test_case.begin() == const_test_case.begin() ) {
    1.75 +        fail_test( "iterators for different containers are not distinct" );
    1.76 +    }
    1.77 +
    1.78 +    if( test_case.data() == const_test_case.data() ) {
    1.79 +    //  Value of data is unspecified in TR1, so no requirement this test pass or fail
    1.80 +    //  However, it must compile!
    1.81 +    }
    1.82 +
    1.83 +
    1.84 +    //  Check can safely use all iterator types with std algorithms
    1.85 +    std::for_each( test_case.begin(), test_case.end(), BadValue< T > );
    1.86 +    std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > );
    1.87 +    std::for_each( const_test_case.begin(), const_test_case.end(), BadValue< T > );
    1.88 +    std::for_each( const_test_case.rbegin(), const_test_case.rend(), BadValue< T > );
    1.89 +
    1.90 +    //  Check swap is well formed
    1.91 +    std::swap( test_case, test_case );
    1.92 +
    1.93 +    //  Check assigment operator and overloads are well formed
    1.94 +    test_case   =   const_test_case;
    1.95 +
    1.96 +    //  Confirm at() throws the std lib defined exception
    1.97 +    try {
    1.98 +        BadValue( test_case.at( 0 ) );
    1.99 +    } catch ( const std::range_error & ) {
   1.100 +    }
   1.101 +
   1.102 +    try {
   1.103 +        BadValue( const_test_case.at( 0 ) );
   1.104 +    } catch ( const std::range_error & ) {
   1.105 +    }
   1.106 +}
   1.107 +
   1.108 +}
   1.109 +
   1.110 +int main()
   1.111 +{
   1.112 +	std_log(LOG_FILENAME_LINE,"[Test Case for array0]");
   1.113 +    RunTests< bool >();
   1.114 +    RunTests< void * >();
   1.115 +    RunTests< long double >();
   1.116 +    RunTests< std::string >();
   1.117 +#ifdef __SYMBIAN32__
   1.118 +	if(failed_tests)
   1.119 +	{
   1.120 +		std_log(LOG_FILENAME_LINE,"Result : Failed"); 
   1.121 +		assert_failed = true;
   1.122 +	}
   1.123 +	else
   1.124 +	{
   1.125 +		std_log(LOG_FILENAME_LINE,"Result : Passed");
   1.126 +	}  
   1.127 +	std_log(LOG_FILENAME_LINE,"[End Test Case ]");
   1.128 +#endif
   1.129 +	testResultXml("array0");
   1.130 +	close_log_file();
   1.131 +    return failed_tests;
   1.132 +}
   1.133 +