12#include "../ah-errors.H"
21#define TEST_EXCEPTION(exception_type, code, should_throw) \
23 bool caught = false; \
27 } catch (const exception_type& e) { \
32 cerr << "Wrong exception type caught!" << endl; \
36 if (should_throw && !caught) { \
37 cerr << "FAIL: Expected " #exception_type " was not thrown" << endl; \
39 } else if (!should_throw && caught) { \
40 cerr << "FAIL: Unexpected " #exception_type " was thrown" << endl; \
44 if (msg.find("test_ah_errors.cc") == string::npos) { \
45 cerr << "FAIL: Message doesn't contain file name: " << msg << endl;\
62 cout <<
"Testing ah_range_error_if..." << endl;
77 cout <<
"Testing ah_range_error_unless..." << endl;
92 cout <<
"Testing ah_range_error..." << endl;
106 cout <<
"Testing ah_runtime_error_if..." << endl;
119 cout <<
"Testing ah_runtime_error_unless..." << endl;
132 cout <<
"Testing ah_runtime_error..." << endl;
145 cout <<
"Testing ah_logic_error_if..." << endl;
158 cout <<
"Testing ah_logic_error_unless..." << endl;
171 cout <<
"Testing ah_logic_error..." << endl;
184 cout <<
"Testing ah_underflow_error_if..." << endl;
197 cout <<
"Testing ah_underflow_error_unless..." << endl;
210 cout <<
"Testing ah_underflow_error..." << endl;
223 cout <<
"Testing ah_overflow_error_if..." << endl;
236 cout <<
"Testing ah_overflow_error_unless..." << endl;
249 cout <<
"Testing ah_overflow_error..." << endl;
262 cout <<
"Testing ah_domain_error_if..." << endl;
275 cout <<
"Testing ah_domain_error_unless..." << endl;
288 cout <<
"Testing ah_domain_error..." << endl;
301 cout <<
"Testing ah_out_of_range_error_if..." << endl;
314 cout <<
"Testing ah_out_of_range_error_unless..." << endl;
327 cout <<
"Testing ah_out_of_range_error..." << endl;
340 cout <<
"Testing ah_invalid_argument_if..." << endl;
353 cout <<
"Testing ah_invalid_argument_unless..." << endl;
366 cout <<
"Testing ah_invalid_argument..." << endl;
379 cout <<
"Testing ah_length_error_if..." << endl;
392 cout <<
"Testing ah_length_error_unless..." << endl;
405 cout <<
"Testing ah_length_error..." << endl;
418 cout <<
"Testing ah_fatal_error..." << endl;
431 cout <<
"Testing warning macros..." << endl;
437 string result = oss.str();
438 if (result.find(
"WARNING") != string::npos &&
439 result.find(
"test_ah_errors.cc") != string::npos) {
442 cerr <<
"FAIL: ah_warning_if didn't produce expected output" << endl;
452 if (result.find(
"WARNING") != string::npos &&
453 result.find(
"test_ah_errors.cc") != string::npos) {
456 cerr <<
"FAIL: ah_warning_unless didn't produce expected output" << endl;
466 if (result.find(
"WARNING") != string::npos &&
467 result.find(
"test_ah_errors.cc") != string::npos) {
470 cerr <<
"FAIL: ah_warning didn't produce expected output" << endl;
481 cout <<
"Testing message formatting with stream operators..." << endl;
485 ah_range_error() <<
"Value is " << value <<
" but expected " << 100;
486 }
catch (
const range_error& e) {
487 string msg = e.what();
488 if (msg.find(
"Value is 42 but expected 100") != string::npos) {
491 cerr <<
"FAIL: Message formatting incorrect: " << msg << endl;
503 cout <<
"==================================================" << endl;
504 cout <<
"Running ah-errors.H test suite" << endl;
505 cout <<
"==================================================" << endl;
555 cout <<
"==================================================" << endl;
556 cout <<
"Test Results:" << endl;
560 cout <<
"==================================================" << endl;
563 cout <<
"SUCCESS: All tests passed!" << endl;
566 cout <<
"FAILURE: Some tests failed!" << endl;
#define ah_domain_error()
Throws std::domain_error unconditionally.
#define ah_overflow_error_unless(C)
Throws std::overflow_error if condition does NOT hold.
#define ah_runtime_error_unless(C)
Throws std::runtime_error if condition does NOT hold.
#define ah_runtime_error()
Throws std::runtime_error unconditionally.
#define ah_length_error_if(C)
Throws std::length_error if condition holds.
#define ah_domain_error_unless(C)
Throws std::domain_error if condition does NOT hold.
#define ah_length_error()
Throws std::length_error unconditionally.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#define ah_out_of_range_error_unless(C)
Throws std::out_of_range if condition does NOT hold.
#define ah_fatal_error()
Throws an unconditional std::runtime_error (fatal error)
#define ah_warning(out)
Emits an unconditional warning to a stream.
#define ah_logic_error_unless(C)
Throws std::logic_error if condition does NOT hold.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_warning_if(out, C)
Emits a warning to a stream if the condition holds.
#define ah_invalid_argument()
Throws std::invalid_argument unconditionally.
#define ah_overflow_error()
Throws std::overflow_error unconditionally.
#define ah_invalid_argument_unless(C)
Throws std::invalid_argument if condition does NOT hold.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_logic_error_if(C)
Throws std::logic_error if condition holds.
#define ah_logic_error()
Throws std::logic_error unconditionally.
#define ah_length_error_unless(C)
Throws std::length_error if condition does NOT hold.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
#define ah_range_error_unless(C)
Throws std::range_error if condition does NOT hold.
#define ah_underflow_error()
Throws std::underflow_error unconditionally.
#define ah_underflow_error_unless(C)
Throws std::underflow_error if condition does NOT hold.
#define ah_warning_unless(out, C)
Emits a warning to a stream if the condition does NOT hold.
#define ah_range_error()
Throws std::range_error unconditionally.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
#define ah_out_of_range_error()
Throws std::out_of_range unconditionally.
void test_warning_macros()
void test_underflow_error_unless()
void test_range_error_unless()
#define TEST_EXCEPTION(exception_type, code, should_throw)
void test_overflow_error_if()
void test_overflow_error_unless()
void test_out_of_range_error()
void test_length_error_if()
void test_invalid_argument_unless()
void test_out_of_range_error_unless()
void test_range_error_if()
void test_underflow_error_if()
void test_runtime_error_if()
void test_logic_error_if()
void test_length_error_unless()
void test_domain_error_if()
void test_underflow_error()
void test_invalid_argument()
void test_runtime_error_unless()
void test_runtime_error()
void test_logic_error_unless()
void test_out_of_range_error_if()
void test_domain_error_unless()
void test_message_formatting()
void test_overflow_error()
void test_invalid_argument_if()