sl@0
|
1 |
/* tests for using class array<> specialization for size 0
|
sl@0
|
2 |
* (C) Copyright Alisdair Meredith 2006.
|
sl@0
|
3 |
* Distributed under the Boost Software License, Version 1.0. (See
|
sl@0
|
4 |
* accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
5 |
* http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
6 |
*/
|
sl@0
|
7 |
/*
|
sl@0
|
8 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
sl@0
|
9 |
*/
|
sl@0
|
10 |
|
sl@0
|
11 |
#include <string>
|
sl@0
|
12 |
#include <iostream>
|
sl@0
|
13 |
#include <boost/array.hpp>
|
sl@0
|
14 |
|
sl@0
|
15 |
#ifdef __SYMBIAN32__
|
sl@0
|
16 |
#include "std_log_result.h"
|
sl@0
|
17 |
#define LOG_FILENAME_LINE __FILE__, __LINE__
|
sl@0
|
18 |
#endif
|
sl@0
|
19 |
|
sl@0
|
20 |
namespace {
|
sl@0
|
21 |
unsigned int failed_tests = 0;
|
sl@0
|
22 |
|
sl@0
|
23 |
void fail_test( const char * reason ) {
|
sl@0
|
24 |
++failed_tests;
|
sl@0
|
25 |
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
|
sl@0
|
26 |
}
|
sl@0
|
27 |
|
sl@0
|
28 |
template< class T >
|
sl@0
|
29 |
void BadValue( const T & )
|
sl@0
|
30 |
{
|
sl@0
|
31 |
fail_test( "Unexpected value" );
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
template< class T >
|
sl@0
|
35 |
void RunTests()
|
sl@0
|
36 |
{
|
sl@0
|
37 |
typedef boost::array< T, 0 > test_type;
|
sl@0
|
38 |
|
sl@0
|
39 |
// Test value and aggegrate initialization
|
sl@0
|
40 |
test_type test_case = {};
|
sl@0
|
41 |
const boost::array< T, 0 > const_test_case = test_type();
|
sl@0
|
42 |
|
sl@0
|
43 |
test_case.assign( T() );
|
sl@0
|
44 |
|
sl@0
|
45 |
// front/back and operator[] must compile, but calling them is undefined
|
sl@0
|
46 |
// Likewise, all tests below should evaluate to false, avoiding undefined behaviour
|
sl@0
|
47 |
if( !test_case.empty() ) {
|
sl@0
|
48 |
BadValue( test_case.front() );
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
if( !const_test_case.empty() ) {
|
sl@0
|
52 |
BadValue( const_test_case.back() );
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
if( test_case.size() > 0 ) {
|
sl@0
|
56 |
BadValue( test_case[ 0 ] );
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
if( const_test_case.max_size() > 0 ) {
|
sl@0
|
60 |
BadValue( const_test_case[ 0 ] );
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
// Assert requirements of TR1 6.2.2.4
|
sl@0
|
64 |
if( test_case.begin() != test_case.end() ) {
|
sl@0
|
65 |
fail_test( "Not an empty range" );
|
sl@0
|
66 |
}
|
sl@0
|
67 |
if( const_test_case.begin() != const_test_case.end() ) {
|
sl@0
|
68 |
fail_test( "Not an empty range" );
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
if( test_case.begin() == const_test_case.begin() ) {
|
sl@0
|
72 |
fail_test( "iterators for different containers are not distinct" );
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
if( test_case.data() == const_test_case.data() ) {
|
sl@0
|
76 |
// Value of data is unspecified in TR1, so no requirement this test pass or fail
|
sl@0
|
77 |
// However, it must compile!
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
|
sl@0
|
81 |
// Check can safely use all iterator types with std algorithms
|
sl@0
|
82 |
std::for_each( test_case.begin(), test_case.end(), BadValue< T > );
|
sl@0
|
83 |
std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > );
|
sl@0
|
84 |
std::for_each( const_test_case.begin(), const_test_case.end(), BadValue< T > );
|
sl@0
|
85 |
std::for_each( const_test_case.rbegin(), const_test_case.rend(), BadValue< T > );
|
sl@0
|
86 |
|
sl@0
|
87 |
// Check swap is well formed
|
sl@0
|
88 |
std::swap( test_case, test_case );
|
sl@0
|
89 |
|
sl@0
|
90 |
// Check assigment operator and overloads are well formed
|
sl@0
|
91 |
test_case = const_test_case;
|
sl@0
|
92 |
|
sl@0
|
93 |
// Confirm at() throws the std lib defined exception
|
sl@0
|
94 |
try {
|
sl@0
|
95 |
BadValue( test_case.at( 0 ) );
|
sl@0
|
96 |
} catch ( const std::range_error & ) {
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
try {
|
sl@0
|
100 |
BadValue( const_test_case.at( 0 ) );
|
sl@0
|
101 |
} catch ( const std::range_error & ) {
|
sl@0
|
102 |
}
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
int main()
|
sl@0
|
108 |
{
|
sl@0
|
109 |
std_log(LOG_FILENAME_LINE,"[Test Case for array0]");
|
sl@0
|
110 |
RunTests< bool >();
|
sl@0
|
111 |
RunTests< void * >();
|
sl@0
|
112 |
RunTests< long double >();
|
sl@0
|
113 |
RunTests< std::string >();
|
sl@0
|
114 |
#ifdef __SYMBIAN32__
|
sl@0
|
115 |
if(failed_tests)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
std_log(LOG_FILENAME_LINE,"Result : Failed");
|
sl@0
|
118 |
assert_failed = true;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
else
|
sl@0
|
121 |
{
|
sl@0
|
122 |
std_log(LOG_FILENAME_LINE,"Result : Passed");
|
sl@0
|
123 |
}
|
sl@0
|
124 |
std_log(LOG_FILENAME_LINE,"[End Test Case ]");
|
sl@0
|
125 |
#endif
|
sl@0
|
126 |
testResultXml("array0");
|
sl@0
|
127 |
close_log_file();
|
sl@0
|
128 |
return failed_tests;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|