|
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) |
|
6 */ |
|
7 /* |
|
8 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. |
|
9 */ |
|
10 |
|
11 #include <string> |
|
12 #include <iostream> |
|
13 #include <boost/array.hpp> |
|
14 |
|
15 #ifdef __SYMBIAN32__ |
|
16 #include "std_log_result.h" |
|
17 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
18 #endif |
|
19 |
|
20 namespace { |
|
21 unsigned int failed_tests = 0; |
|
22 |
|
23 void fail_test( const char * reason ) { |
|
24 ++failed_tests; |
|
25 std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl; |
|
26 } |
|
27 |
|
28 template< class T > |
|
29 void BadValue( const T & ) |
|
30 { |
|
31 fail_test( "Unexpected value" ); |
|
32 } |
|
33 |
|
34 template< class T > |
|
35 void RunTests() |
|
36 { |
|
37 typedef boost::array< T, 0 > test_type; |
|
38 |
|
39 // Test value and aggegrate initialization |
|
40 test_type test_case = {}; |
|
41 const boost::array< T, 0 > const_test_case = test_type(); |
|
42 |
|
43 test_case.assign( T() ); |
|
44 |
|
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() ); |
|
49 } |
|
50 |
|
51 if( !const_test_case.empty() ) { |
|
52 BadValue( const_test_case.back() ); |
|
53 } |
|
54 |
|
55 if( test_case.size() > 0 ) { |
|
56 BadValue( test_case[ 0 ] ); |
|
57 } |
|
58 |
|
59 if( const_test_case.max_size() > 0 ) { |
|
60 BadValue( const_test_case[ 0 ] ); |
|
61 } |
|
62 |
|
63 // Assert requirements of TR1 6.2.2.4 |
|
64 if( test_case.begin() != test_case.end() ) { |
|
65 fail_test( "Not an empty range" ); |
|
66 } |
|
67 if( const_test_case.begin() != const_test_case.end() ) { |
|
68 fail_test( "Not an empty range" ); |
|
69 } |
|
70 |
|
71 if( test_case.begin() == const_test_case.begin() ) { |
|
72 fail_test( "iterators for different containers are not distinct" ); |
|
73 } |
|
74 |
|
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! |
|
78 } |
|
79 |
|
80 |
|
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 > ); |
|
86 |
|
87 // Check swap is well formed |
|
88 std::swap( test_case, test_case ); |
|
89 |
|
90 // Check assigment operator and overloads are well formed |
|
91 test_case = const_test_case; |
|
92 |
|
93 // Confirm at() throws the std lib defined exception |
|
94 try { |
|
95 BadValue( test_case.at( 0 ) ); |
|
96 } catch ( const std::range_error & ) { |
|
97 } |
|
98 |
|
99 try { |
|
100 BadValue( const_test_case.at( 0 ) ); |
|
101 } catch ( const std::range_error & ) { |
|
102 } |
|
103 } |
|
104 |
|
105 } |
|
106 |
|
107 int main() |
|
108 { |
|
109 std_log(LOG_FILENAME_LINE,"[Test Case for array0]"); |
|
110 RunTests< bool >(); |
|
111 RunTests< void * >(); |
|
112 RunTests< long double >(); |
|
113 RunTests< std::string >(); |
|
114 #ifdef __SYMBIAN32__ |
|
115 if(failed_tests) |
|
116 { |
|
117 std_log(LOG_FILENAME_LINE,"Result : Failed"); |
|
118 assert_failed = true; |
|
119 } |
|
120 else |
|
121 { |
|
122 std_log(LOG_FILENAME_LINE,"Result : Passed"); |
|
123 } |
|
124 std_log(LOG_FILENAME_LINE,"[End Test Case ]"); |
|
125 #endif |
|
126 testResultXml("array0"); |
|
127 close_log_file(); |
|
128 return failed_tests; |
|
129 } |
|
130 |