BOOST check (test) library example (Robinkin organizes)

xiaoxiao2021-03-06  42

// file name: Test.cpp Robinkin organizes

#include

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

}

// EOF

// Compilation method

G test -lboost_test_exec_monitor-gcc test.cpp

转载请注明原文地址:https://www.9cbs.com/read-54027.html

New Post(0)