青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

不倦的候鳥成長日記

——候鳥,候補的菜鳥也
隨筆 - 6, 文章 - 0, 評論 - 5, 引用 - 0
數據加載中……

[轉]Boost Test Library

boost 的 Test

test 庫中有如下的組件:
Execution Monitor  一個基本用于 program 和 test program 的異常與錯誤檢測與報告機制,Execution Monitor 調用用戶提供的函數并報告所有捕獲的運行時的異常,它只被其他 Boost Test Library components 內部調用,當然也可以用于一些 production environment 控制那些會導致程序崩潰的函數的調用;

Program Execution Monitor  一個簡單的 helper facility 用于監控一個程序的運行,Program Execution Monitor 提供了 main() 函數和 Execution Monitor 監控程序的執行,可以用以 production environment 產生一致錯誤報告,控制在 test environment 環境中運行的程序,直接使用 Test Execution Monitor;

Test Tools  一個用以進行 testing 的一個 toolbox,Test Tools 被用來測試在 Test Execution Monitor 或 Unit Test Framework 控制下運行的程序;

Test Execution Monitor  讓一個測試程序在 monitored environment 環境中運行,Test Execution Monitor 提供了 main() 來控制被測試程序的運行并可以讓 Test Tools 實現測試的邏輯,它被用在 test environment,如果要控制 production code 的運行使用 Program Execution Monitor;

Unit Test Framework  用以簡化編寫和組織 test cases 的 framework,支持簡單函數或者是成員函數編寫的 test cases 并將他們組織成一個 test suites 的 tree,該 framework 使用 Test Tools 來實現 test cases 并提供了一種機制用以管理 log report level 和 result report level;

minimal testing facility  提供 Boost Test 最初版本的提供的功能的簡單 facility,提供了和 Test Execution Monitor 一樣的機制,但額外定義了一些簡單提供 Test Tools 類似功能的 test tools,它不需要和任何的外部組件 link,適合簡單和快速測試的需要,使用于 test environment。
(http://yaekees.spaces.live.com/blog/cns!1955EE8C6707277A!146.entry)


boost Test 的 Execution Monitor

使用 Execution Monitor 的三部曲:
1. #include <boost/test/execution_monitor.hpp>
2. Make an instance of boost::execution_monitor
3. Optionally register custom exception translators for exception classes you want special processing
 
調用 execution_monitor::execute( function_to_monitor, catch_system_exception, timeout ) 運行 monitored function。如果調用成功則返回一個 integer value,如果有如下的事情發生
1. Uncaught C++ exception
2. hardware or software signal, trap, or other exception
3. Timeout reached
4. debug assert event occurred (under Microsoft Visual C++ or compatible compiler)
the method execution_monitor::execute( ... ) throws the boost::execution_exception
如果希望程序 error message 被轉化為  execution_exception 的 error message,則扔出如下的三類異常:C string,std:string,any exception class in std::exception hierarchy。
 
終止 monitored function 而不讓 Execution Monitor 報告 any error 的最佳方法是拋出 boost::execution_aborted。如果不喜歡 "unknown exception caught" message 而更愿意使用自定義的 exception,可以向 execution monitor 為 any exception types 注冊 translator 函數,如
ex_mon.register_exception_translator<my_exception1>( &translate_my_exception1 );
my_exception1 是異常類型,translate_my_exception1 是異常處理函數。
class execution_monitor {
public:
    virtual     ~execution_monitor();
   
    template<typename Exception, typename ExceptionTranslator>
    void        register_exception_translator( ExceptionTranslator const& tr, boost::type<Exception>* = 0 );
 
    int         execute( unit_test::callback0<int> const& F, bool catch_system_errors = true, int timeout = 0 );
}; // exception monitor
 
Execution Monitor 用 boost::execution_exception 報告捕獲的問題,其最大的特點是不分配任何 memory 因此在內存稀缺環境中使用。
class execution_exception {
public:
    execution_exception( error_code ec, const_string what_msg );
    enum error_code {
        cpp_exception_error,    // see note (1) below
        user_error,             // user reported nonfatal error
        system_error,           // see note (2) below
        timeout_error,          // only detectable on certain platforms
        user_fatal_error,       // user reported fatal error
        system_fatal_error      // see note (2) below
    };
    error_code   code() const;  // use this method to get an error code for the exception
    const_string what() const;  // use this method to get an error message for the exception
};
Note 1 :uncaught C++ exceptions 被當做 error,如果應用程序捕獲到 C++ exception,則該 exception 不會到 boost::execution_monitor;
Note 2 :這些 error 包括 UNIX signals 和 Windows structured exceptions,這些經常由 hardware traps 觸發。

execution_monitor 可以動態連接,庫中沒有提供 main 函數。由于只有一個 libs/test/execution_monitor.cpp 文件,因此可以直接 copy 該文件。
(http://yaekees.spaces.live.com/blog/cns!1955EE8C6707277A!148.entry)


boost Test 的 Program Execution Monitor

C++ program 可以通過 return value 和 throwing an exception 報告 user-detected errors,而如 dereferencing an invalid pointer 的 System-detected errors 則以其他方式報告。
 
Boost Test Library 的 Program Execution Monitor 減輕了用戶處理復雜的 error detection 和 reporting,并提供了 main() 函數在 monitored environment 來調用用戶提供的 cpp_main() 函數,main() 函數以一致的方式檢測和報告多種 errors 的發生,將其轉化為一致的 return code 返回給 host enviroment。
BOOST_TEST_CATCH_SYSTEM_ERRORS 設置允許 Execution Monitor 捕獲 system errors,默認值為 "yes"。
BOOST_PRG_MON_CONFIRM 設置是否允許用戶交互確認程序正確運行,默認值為"yes"。
 
Program Execution Monitor 使用 Execution Monitor 監視用戶提供的 cpp_main() 函數的運行。盡管 Program Execution Monitor 在 libs/test/src/cpp_main.cpp 提供了 main() 函數,但是為了 link 正確,用戶必須提供一個與 main() 函數一樣接口的 cpp_main() 函數。如 cpp_main() 拋出異常或返回非 0 值,Program Execution Monitor 就認為程序發生錯誤。
Program Execution Monitor 在 cout 和 cerr 流上分別提供詳細和簡要的錯誤報告。Program Execution Monitor 提供的 main() 函數返回如下的值
1. boost::exit_success - no errors
2. boost::exit_failure - non-zero and non-boost::exit_success return code from cpp_main().
3. boost::exit_exception_failure - cpp_main() throw an exception.
(http://yaekees.spaces.live.com/blog/cns!1955EE8C6707277A!149.entry)


boost Test 的 Test Tools

Test Tools 為了讓用戶使用方便,提供了一系列的宏,這些宏分三級,其效果是不同的:
WARN 不增加引用計數,繼續執行程序
CHECK 增加應用計數,繼續執行程序
REQUIRE 增加應用計數,中斷程序的運行
 
使用 CHECK level tools 實現 assertions,使用 WARN level tools 檢驗不太重要但是正確的方面,如:性能、可移植性、有用性,如 assertions 失敗就不應該讓程序繼續運行則使用 REQUIRE level tools。
 
Test Tools 提供了兩個 .hpp 文件 boost/test/test_tools.hpp 和 boost/test/floating_point_comparison.hpp,一個 .cpp 文件 libs/test/test_tools.cpp
BOOST_WARN( P )
BOOST_CHECK( P )
BOOST_REQUIRE( P )
BOOST_WARN_MESSAGE( P, M )
BOOST_CHECK_MESSAGE( P, M )
BOOST_REQUIRE_MESSAGE( P, M )
BOOST_ERROR( M )BOOST_FAIL( M )
BOOST_MESSAGE( M )
BOOST_CHECKPOINT( M )
BOOST_WARN_THROW( S, E )
BOOST_CHECK_THROW( S, E )
BOOST_REQUIRE_THROW( S, E )
BOOST_WARN_EXCEPTION( S, E, P )
BOOST_CHECK_EXCEPTION( S, E, P )
BOOST_REQUIRE_EXCEPTION( S, E, P )
BOOST_IGNORE_CHECK( e )
BOOST_WARN_NO_THROW( S )
BOOST_CHECK_NO_THROW( S )
BOOST_REQUIRE_NO_THROW( S )
BOOST_WARN_CLOSE( L, R, T )
BOOST_CHECK_CLOSE( L, R, T )
BOOST_REQUIRE_CLOSE( L, R, T )
BOOST_WARN_SMALL( FPV, T )
BOOST_CHECK_SMALL( FPV, T )
BOOST_REQUIRE_SMALL( FPV, T )
BOOST_WARN_PREDICATE( P, ARGS )
BOOST_CHECK_PREDICATE( P, ARGS )
BOOST_REQUIRE_PREDICATE( P, ARGS )
BOOST_WARN_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end )
BOOST_CHECK_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end )
BOOST_REQUIRE_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end )
BOOST_WARN_BITWISE_EQUAL( L, R )
BOOST_CHECK_BITWISE_EQUAL( L, R )
BOOST_REQUIRE_BITWISE_EQUAL( L, R )
BOOST_IS_DEFINED( symb )
BOOST_BITWISE_EQUAL( L, R )
(http://yaekees.spaces.live.com/blog/cns!1955EE8C6707277A!145.entry)


boost Test 的 Test Execution Monitor

Test Execution Monitor 結合了 Test Tools 和 Execution Monitor 的特點簡化了煩瑣測試工作,它提供了 main() 函數調用用戶提供的 test_main() 函數,用戶可以使用 Test Tools 來進行復雜的驗證工作。
 
Test Execution Monitor 被設計用來進行測試簡單的程序或者從已存在的 production code 中 dig a problem。Program Execution Monitor 更適合監控 production (non-test) programs(因為它不影響程序的性能),而 Unit Test Framework 更適合 complex test programs,因為 Unit Test Framework 可以
1. 可以將 test 分割到多個 test cases,它會為每一個 test case 分別產生 pass/fail 的統計信息;
2. 假如某一個 test case 失敗了不會影響其他的 test;
3. 可以通過指定 name 來運行特定的 test case
4. 分離的 test cases 運行更清楚發現特定測試模塊的目的
5. 可以設置更多的選項
(http://yaekees.spaces.live.com/blog/cns!1955ee8c6707277a!150.entry)


boost Test 的 Unit Test Framework

regression testing 只關注程序運行的時候是否有錯誤發生,而 unit test 則需要盡可能詳細的輸出錯誤的信息。Unit Test Framework 用 test tools 簡化了 test cases 的編寫并將其組織為有層次的 test suites。它提供了 main() 函數初始化 framework,通過命令行參數或者是環境變量設置參數,并通過 init_unit_test_suite(argc, argv),然后運行用戶的 test suite。Framework 跟蹤所有的 passed/failed 的 Test Tools assertions,可以通過 test cases 的數目(part 和 total)得到測試進度,并且可以多種形式提供結果。Unit Test Framework 可被用來進行簡單測試和復雜重要測試,它不適合用在 production code,同時它以運行時的效率為代價加速編譯。
 
該函數負責創建和初始化頂層的 test_suite 實例,如 test_suite 創建失敗該函數返回 NULL 指針,測試終止并返回一個 boost::exit_test_failure。Framework 在測試運行時傳遞特定的命令行參數,同時排斥其他 framework 指定的參數,同時 framework 負責 test_suite 的生命周期,在 test 終止時會被銷毀。
 
假如 test cases 會丟出自定義的異常,可以像 Execution Monitor 那樣注冊特定的 translator,注冊函數的原型定義如下
template<typename Exception, typename ExceptionTranslator>
void boost::unit_test::register_exception_translator( ExceptionTranslator const& tr, boost::type<Exception>* d = 0 )
 
一旦測試結束,framework 會報告結果并返回 return code。下面是集成在 unit test framework 內部的的返回值
boost::exit_success  returned if no errors occurred during test or success result code was explicitly requested with the no result code framework parameter
boost::exit_test_failure  returned if nonfatal errors detected and no uncaught exceptions thrown or the framework fails to initialize the test suite
boost::exit_exception_failure  returned if fatal errors detected or uncaught exceptions thrown
 
在 VC7.1+stlport 4.62 上 unit_test_example3.cpp 沒有通過(對多種繼承沒有通過)
 
簡單的使用方法:
1. 首先定義 #define BOOST_AUTO_TEST_MAIN
2. 包含 #include <boost/test/auto_unit_test.hpp>
3. 創建一個 test_suite
BOOST_AUTO_TEST_CASE( test )
{
    BOOST_CHECK( true );
}
然后 link libboost_test_exec_monitor-vc71-mt-sp-1_33.lib 就可以了。
 
另一類使用方法,首先包含如下
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_monitor.hpp>
using namespace boost::unit_test;
然后聲明 test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {}
一個典型用法是
test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) {
    test_suite* test = BOOST_TEST_SUITE("custom_exception_test");
    unit_test_monitor.register_exception_translator<my_exception1>( &my_exception1_translator );
    unit_test_monitor.register_exception_translator<my_exception2>( &my_exception2_translator );
    test->add( BOOST_TEST_CASE( &throw_my_exception1 ) );
    test->add( BOOST_TEST_CASE( &throw_my_exception2 ) );
    return test;
}
(http://yaekees.spaces.live.com/blog/cns!1955EE8C6707277A!151.entry)


boost 的 minimal testing facility

只適合使用在 test environment 中,不需要 link 任何外部的組件。用戶只需要提供了如下的函數
int test_main( int argc, char* argv[] ) 就可以了。minimal testing facility 提供了 BOOST_CHECK(predicate),BOOST_REQUIRE(predicate),BOOST_ERROR(message), BOOST_FAIL(message)。除了這四個 MACRO 以外可以通過拋出異常和 return 返回值報告錯誤。下面是 boost 提供的一個示例。
#include <boost/test/minimal.hpp>
int add( int i, int j ) { return i+j; }
int test_main( int, char *[] )             // note the name!
{
    // six ways to detect and report the same error:
    BOOST_CHECK( add( 2,2 ) == 4 );        // #1 continues on error
    BOOST_REQUIRE( add( 2,2 ) == 4 );      // #2 throws on error
    if( add( 2,2 ) != 4 )
      BOOST_ERROR( "Ouch..." );            // #3 continues on error
    if( add( 2,2 ) != 4 )
      BOOST_FAIL( "Ouch..." );             // #4 throws on error
    if( add( 2,2 ) != 4 ) throw "Oops..."; // #5 throws on error
    return add( 2, 2 ) == 4 ? 0 : 1;       // #6 returns error code
}
BOOST_CHECK 如果該表達式失敗了,會出現源代碼文件名、代碼行號、并且會增加 error count,一旦程序終止 error count 會顯示在 std::cout;
BOOST_REQUIRE 類似于 BOOST_CHECK,但是會拋出被  Minimal testing facility 捕獲的異常。
(http://yaekees.spaces.live.com/blog/cns!1955EE8C6707277A!147.entry)

posted on 2008-03-29 15:39 不倦 閱讀(3341) 評論(1)  編輯 收藏 引用 所屬分類: C++單元測試框架

評論

# re: [轉]Boost Test Library  回復  更多評論   

不錯不錯 很受教啊
美中不足的是具體的例子舉的太少了
2008-06-12 11:07 | jazz
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲一区二区三区高清| 久久er99精品| 亚洲欧美日韩中文在线制服| 国产精品一区一区| 欧美/亚洲一区| 狂野欧美一区| 欧美日韩精品在线观看| 欧美成人蜜桃| 欧美精品一区二区三区一线天视频| 欧美中文字幕在线播放| 亚洲午夜小视频| 欧美怡红院视频一区二区三区| 99re6热只有精品免费观看 | 久久女同精品一区二区| 欧美一区二区精品在线| 欧美有码视频| 欧美福利在线| 国产精品女主播在线观看 | 亚洲免费激情| 欧美在线视频a| 欧美国产专区| 亚洲一区二区三区高清| 欧美亚洲视频在线观看| 久久久国产一区二区| 欧美国产丝袜视频| 国产精品丝袜xxxxxxx| 一色屋精品亚洲香蕉网站| 亚洲第一免费播放区| 一区二区三区国产在线观看| av不卡免费看| 麻豆精品91| 亚洲欧美日韩天堂一区二区| 亚洲欧美日韩精品久久久久| 香蕉国产精品偷在线观看不卡| 久久琪琪电影院| 欧美午夜女人视频在线| 一区二区视频免费在线观看| 亚洲缚视频在线观看| 亚洲欧美日韩精品| 亚洲欧洲精品一区二区三区波多野1战4| 亚洲成在线观看| 久久大逼视频| 国产欧美大片| 亚洲伊人观看| 亚洲精品三级| 欧美理论在线播放| 亚洲人成网站影音先锋播放| 亚洲欧美日韩国产一区二区| 久久青青草综合| 欧美亚洲三级| 国产一区二区三区免费在线观看| 最新亚洲激情| 你懂的一区二区| 久久久国产精品一区二区中文 | 亚洲第一搞黄网站| 麻豆国产精品va在线观看不卡| 中国成人在线视频| 欧美日韩亚洲视频一区| 亚洲人在线视频| 美女网站在线免费欧美精品| 宅男噜噜噜66一区二区66| 欧美国产1区2区| 亚洲精品久久视频| 亚洲国产精品一区二区www| 久久一综合视频| 亚洲七七久久综合桃花剧情介绍| 国产一区二区你懂的| 亚洲一区二区在线免费观看视频| 亚洲欧洲一二三| 欧美精选一区| 亚洲一区二区四区| 亚洲专区在线视频| 韩国精品在线观看| 美女视频一区免费观看| 久久精品国产免费观看| 国产最新精品精品你懂的| 久久久久久久久久久久久女国产乱 | 亚洲精品国精品久久99热| 欧美xx69| 欧美日韩成人一区二区| 宅男在线国产精品| 亚洲女性裸体视频| 国产一区二区三区在线免费观看 | 欧美一级视频免费在线观看| 欧美日韩成人综合| 亚洲国产精品v| 亚洲精品日韩激情在线电影| 久久久精品久久久久| 亚洲国产婷婷| 亚洲无限乱码一二三四麻| 国产亚洲女人久久久久毛片| 亚洲一区中文字幕在线观看| 久久久激情视频| 欧美成人午夜激情在线| 亚洲欧美韩国| 欧美国产乱视频| 国产精品久久久久7777婷婷| 亚洲欧美三级伦理| 欧美 日韩 国产 一区| 亚洲精品日韩一| 欧美一级理论性理论a| 亚洲欧洲日本mm| 99精品久久| 亚洲国产精品国自产拍av秋霞| 亚洲国产另类久久精品| 欧美日韩理论| 美女精品自拍一二三四| 欧美亚一区二区| 久久精品91久久久久久再现| 中文网丁香综合网| 亚洲国产日韩一区| 欧美一级艳片视频免费观看| 尤物在线观看一区| 亚洲一区二区三区午夜| 亚洲人成绝费网站色www| 香蕉亚洲视频| 亚洲欧美日韩一区在线| 久久亚洲一区二区| 久久久久9999亚洲精品| 欧美日本韩国在线| 免费一级欧美在线大片| 久久国产手机看片| 亚洲深夜福利视频| 欧美大片专区| 欧美岛国在线观看| 一区视频在线播放| 欧美一区二区三区男人的天堂| 欧美亚洲在线视频| 午夜精品久久久| 久久亚洲私人国产精品va| 久久久久国产一区二区三区四区 | 欧美精品三级日韩久久| 久久精品一区蜜桃臀影院| 欧美精品一区二区三区蜜臀| 亚洲一区区二区| 欧美日韩亚洲精品内裤| 久久综合色婷婷| 伊人蜜桃色噜噜激情综合| 午夜精品一区二区三区四区| 一区二区在线视频| 欧美在线黄色| 久久九九精品| 国语精品一区| 久久天天躁狠狠躁夜夜爽蜜月| 亚洲一区二区伦理| 欧美视频三区在线播放| 亚洲激情偷拍| 亚洲无线一线二线三线区别av| 免费亚洲视频| 欧美黄色大片网站| 亚洲毛片在线观看.| 久久久久久网址| 欧美国产精品va在线观看| 亚洲福利国产| 欧美wwwwww| 亚洲人永久免费| 亚洲欧美成人网| 国产欧美日韩麻豆91| 亚洲女性裸体视频| 久久婷婷国产综合尤物精品| 国产欧美日韩三区| 久久精品一区蜜桃臀影院 | 久久激情网站| 欧美黄在线观看| 亚洲午夜高清视频| 国产精品一区二区三区久久| 91久久久在线| 亚洲制服丝袜在线| 国产偷自视频区视频一区二区| 性久久久久久久久| 欧美成人激情视频| 亚洲色图综合久久| 国产专区欧美精品| 欧美精品97| 欧美一级视频精品观看| 欧美激情一二区| 亚洲欧美成人综合| 国内精品视频在线播放| 农夫在线精品视频免费观看| 免费成人av资源网| 亚洲天堂免费在线观看视频| 欧美国产视频在线观看| 韩国福利一区| 欧美自拍丝袜亚洲| 六月婷婷一区| 亚洲在线观看免费视频| 国产精品试看| 久久久亚洲人| 亚洲天堂第二页| 欧美高清在线精品一区| 欧美亚洲综合另类| 亚洲精品裸体| 国产精品一区二区三区四区| 欧美一区二区三区四区在线| 久久久www成人免费精品| 一区二区精品国产| 在线成人小视频| 国产欧美一区二区三区沐欲| 久久精品国产亚洲一区二区三区| 亚洲电影av|