#define BOOST_TEST_MODULE f_to_c_test_suite #include #include #include #include "FtoC.h" // so we can use the elements of the output_test_stream without // a horrid list of namespaces using boost::test_tools::output_test_stream; using namespace std; BOOST_AUTO_TEST_SUITE(f_to_c_BASIC) BOOST_AUTO_TEST_CASE(basic_tests) { BOOST_TEST(0 == FtoC(32)); BOOST_TEST(100 == FtoC(212), "Bad result of less than"); BOOST_TEST(212 == CtoF(100)); BOOST_TEST(32 == CtoF(0)); } BOOST_AUTO_TEST_CASE(basic_tests2) { BOOST_TEST(0 == FtoC(32)); } BOOST_AUTO_TEST_SUITE_END() // start a new test suite for errors BOOST_AUTO_TEST_SUITE(f_to_c_ERRORS) BOOST_AUTO_TEST_CASE(output_error_test) { string goodMessage = "Illegal Temperature in F.\n"; string badMessage = "illegal temp\n"; output_test_stream output; streambuf * old = cout.rdbuf(output.rdbuf()); // force the error FtoC(-500); // restore cout cout.rdbuf(old); BOOST_TEST(not output.is_empty(false)); BOOST_TEST(output.check_length(goodMessage.size(),false)); cout << endl; BOOST_TEST(output.check_length(badMessage.size(),false), "Expect fail"); BOOST_TEST(output.is_equal(goodMessage,false)); cout << endl; BOOST_TEST(output.is_equal(badMessage,false), "Expect Fail"); cout << endl; // clean the output stream for reuse. // not needed here but given for an example output.flush(); return; } BOOST_AUTO_TEST_CASE(exception_error_test) { // these will warn if the exception does not occur BOOST_CHECK_THROW(CtoF(-400),exception); BOOST_CHECK_THROW(CtoF(-400),invalid_argument); // we expect an excption, but one does not occur cout << "Here is an error" << endl; BOOST_CHECK_THROW(CtoF(400),exception); cout << "After error " << endl; cout << endl; // these will bomb if the exception does not occur. BOOST_REQUIRE_THROW(CtoF(-400),exception); BOOST_REQUIRE_THROW(CtoF(-400),invalid_argument); cout << endl; // require a throw but it does not happen. cout << "Here is an error, we required a throw but it did not" << endl; BOOST_REQUIRE_THROW(CtoF(400),invalid_argument); cout << "Did not get here." << endl; } BOOST_AUTO_TEST_CASE(uncaught_exception_test) { // this will throw an exception and abort the test. cout << endl; cout << "About to throw an error " << endl; CtoF(-400); cout << "Boy is that cold" << endl; } BOOST_AUTO_TEST_CASE(no_throw_test) { cout << endl; cout << "We made it to the no_throw case." << endl; BOOST_CHECK_NO_THROW(CtoF(100)); cout << "This should complain " << endl; BOOST_CHECK_NO_THROW(CtoF(-2100)); cout << "Done with the no_throw case." <