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

ネームスペース static_container::test


構成

struct  del_counter
 コンストラクタ、デストラクタでカウントアップ [詳細]


関数

void begin ()
template<typename ContGen> void basic_sequence ()
 シーケンスコンテナの基本テスト

template<typename Cont> void dump (const Cont &cont)
 バイナリファイルへの直接書き込み・読み込みテスト

template<typename ContGen> void dump ()


関数

template<typename ContGen>
void basic_sequence  ) 
 

シーケンスコンテナの基本テスト

basic_sequence.h14 行で定義されています。

参照先 static_container::size_type.

00014                               {
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         }

void begin  ) 
 

assert_new.h17 行で定義されています。

参照先 begin_test.

00017                      {
00018             begin_test = true;
00019         }

template<typename ContGen>
void dump  ) 
 

dump.h23 行で定義されています。

00023                     {
00024             ContGen::gen< int, 10 >::type   iv;
00025             test::dump( iv );
00026             
00027             iv.push_back( 100 );
00028             iv.push_back( 50 );
00029             test::dump( iv );
00030         }

template<typename Cont>
void dump const Cont &  cont  ) 
 

バイナリファイルへの直接書き込み・読み込みテスト

dump.h12 行で定義されています。

00012                                       {
00013             char    fileImage1[ sizeof( Cont ) ];
00014             char    fileImage2[ sizeof( Cont ) ];
00015             
00016             memcpy( fileImage1, &cont, sizeof( Cont ) );
00017             memcpy( fileImage2, fileImage1, sizeof( Cont ) );
00018             Cont* dest = reinterpret_cast< Cont* >( fileImage2 );
00019             BOOST_REQUIRE( cont == *dest );
00020         }


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