メインページ | ネームスペース一覧 | クラス階層 | 構成 | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ | 関連ページ

basic_sequence.h

説明を見る。
00001 #ifndef STATIC_CONTIANER_TEST_BASIC_SEQUENCE_H
00002 
00003 #define STATIC_CONTIANER_TEST_BASIC_SEQUENCE_H
00004 
00005 #include <boost/test/minimal.hpp>
00006 #include "static_container/integer.h"
00007 #include <boost/assert.hpp>
00008 #include "static_container/test/del_counter.h"
00009 
00010 namespace static_container {
00011     namespace test {
00013         template < typename ContGen >
00014         void basic_sequence() {
00015             struct local_func {
00016                 static void test_del_counter() {
00017                     const size_type size = 10;
00018                     typedef ContGen::gen< del_counter, size >::type Cont;
00019                     BOOST_REQUIRE( size == Cont::max_size() );
00020                     size_type del_count = 0;
00021                     {
00022                         Cont cont;
00023                         BOOST_REQUIRE( cont.empty() );
00024                         BOOST_REQUIRE( 0 == cont.size() );
00025                         cont.push_back( del_counter( del_count ) );
00026                         //  一時オブジェクトの破棄を確認
00027                         BOOST_REQUIRE( 1 == del_count );
00028                         BOOST_REQUIRE( !cont.empty() );
00029                         BOOST_REQUIRE( 1 == cont.size() );
00030                     }
00031                     //  cont のデストラクタによる解放を確認
00032                     BOOST_REQUIRE( 2 == del_count );
00033                     
00034                     del_count = 0;
00035                     {
00036                         Cont cont;
00037                         for ( size_type i = 0; i < size; ++i ) {
00038                             cont.push_back( del_counter( del_count ) );
00039                             BOOST_REQUIRE( i + 1 == cont.size() );
00040                         }
00041                         BOOST_REQUIRE( 10 == del_count );
00042                         for ( size_type i = 0; i < size; ++i ) {
00043                             cont.pop_back();
00044                             BOOST_REQUIRE( size - i - 1 == cont.size() );
00045                         }
00046                         BOOST_REQUIRE( 20 == del_count );
00047                     }
00048                     BOOST_REQUIRE( 20 == del_count );
00049 
00050                     del_count = 0;
00051                     {
00052                         Cont cont;
00053                         for ( size_type i = 0; i < size; ++i ) {
00054                             cont.push_back( del_counter( del_count ) );
00055                             BOOST_REQUIRE( i + 1 == cont.size() );
00056                         }
00057                         BOOST_REQUIRE( 10 == del_count );
00058                         cont.clear();
00059                         BOOST_REQUIRE( 20 == del_count );
00060                     }
00061                     BOOST_REQUIRE( 20 == del_count );
00062                 }
00063                 
00064                 static void test_int() {
00065                     const size_type size = 10;
00066                     typedef ContGen::gen< int, size >::type Cont;
00067                     typedef Cont::iterator          iterator;
00068                     typedef Cont::const_iterator    const_iterator;
00069                     BOOST_REQUIRE( size == Cont::max_size() );
00070                     
00071                     Cont cont;
00072                     cont.push_back( 123 );
00073                     BOOST_REQUIRE( 123 == cont.front() );
00074                     cont.front() = 33;
00075                     BOOST_REQUIRE( 33 == cont.front() );
00076                     cont.push_back( 53 );
00077                     BOOST_REQUIRE( 33 == cont.front() );
00078                     BOOST_REQUIRE( 53 == cont.back() );
00079                     
00080                     Cont::iterator it = cont.begin();
00081                     BOOST_REQUIRE( 33 == *it );
00082                     ++it;
00083                     BOOST_REQUIRE( 53 == *it );
00084                     
00085                     Cont another( cont );
00086                     BOOST_REQUIRE( another == cont );
00087                     cont.push_back( 0 );
00088                     BOOST_REQUIRE( another != cont );
00089                     BOOST_REQUIRE( another < cont );
00090                     ++another.back();
00091                     BOOST_REQUIRE( cont < another );
00092                     another = cont;
00093                     BOOST_REQUIRE( cont == another );
00094                     cont = cont; // 自己代入テスト
00095                     BOOST_REQUIRE( cont == another );
00096                     
00097                     cont.clear();
00098                     
00099                     for ( int i = 0; i < static_cast< int >( size ); ++i ) {
00100                         cont.push_back( i );
00101                     }
00102                     for ( iterator it = cont.begin(); it != cont.end(); ++it ) {
00103                         BOOST_REQUIRE( std::distance( cont.begin(), it ) == *it );
00104                     }
00105                     cont.clear();
00106                     
00107                     //  iterator から const_iterator への暗黙のキャストは可能か?
00108                     const_iterator cit = cont.begin();
00109                     
00110                     //  多重クリア
00111                     for ( int i = 0; i < 10; ++i ) {
00112                         cont.clear();
00113                     }
00114                 }
00115             };
00116             
00117             local_func::test_del_counter();
00118             local_func::test_int();
00119         }
00120     }
00121 }
00122 
00123 #endif

static_containerに対してSat Jun 19 11:30:58 2004に生成されました。 doxygen 1.3.6