diff --git a/Debug/DebTime.hh b/Debug/DebTime.hh index 37430274ddf1edb31845665dcc730709daae7703..dec65c481f70ad7c8e7435ca07aa81cc847712d5 100644 --- a/Debug/DebTime.hh +++ b/Debug/DebTime.hh @@ -28,9 +28,8 @@ public: ~StopWatchSessionT() NOEXCEPT(false) { - const auto dvsr = std::max(ONE, dvsr_); // TODO: implement "prettier" DEB out if seconds turn into minutes/hours/etc - DEB_line_if(dvsr_ == ONE, deb_lvl_, + DEB_line_if(dvsr_ <= ONE, deb_lvl_, sssn_name_ << " took " << sw_.stop() / 1000.0 << " s."); DEB_line_if(dvsr_ > ONE, deb_lvl_, dvsr_ << " x " << sssn_name_ << " took " << sw_.stop() / 1000.0 / dvsr_ diff --git a/Test/TestOutcome.cc b/Test/TestOutcome.cc index 5f38b50280a0d4a6abdc6d6f978947f298832f5e..ec5e5cd4c5f31912e0204276fed0bd132739a78f 100755 --- a/Test/TestOutcome.cc +++ b/Test/TestOutcome.cc @@ -20,17 +20,26 @@ namespace Test namespace { -void record_and_handle_unexpected( - const char* const _call, const Outcome& _oc, const bool _unexpected) +void record_and_handle_unexpected(const char* const _call, const Outcome& _oc, + const bool _unexpected, const char* const _expctd_what) { - TEST(outcome, record(_call, _oc.ok(), _oc.error_description().c_str())); - if (_unexpected) + { + Base::OStringStream strm; + strm << "Unexpected outcome: Expected " << _expctd_what + << " but got " << _oc.error_description().c_str() << " instead!"; + TEST(outcome, record(_call, _oc.ok(), strm.str.c_str())); _oc.unexpected_handler(); + } + else + TEST(outcome, record(_call, _oc.ok(), _oc.error_description().c_str())); } } // namespace -Outcome::Outcome() : ok_(true), error_code_("0"), error_message_("Success") {} +const char SUCCESS[] = "Success"; +const Outcome FAILURE(false, "FAILURE", "Failure"); + +Outcome::Outcome() : ok_(true), error_code_(SUCCESS), error_message_(SUCCESS) {} Outcome::Outcome( bool _ok, const std::string& _error_code, const std::string& _error_message) @@ -58,21 +67,22 @@ Outcome::UnexpectedHandler Outcome::unexpected_handler = [] const Outcome& record_outcome(const char* const _call, const Outcome& _oc) { // Never call unexpected-outcome handler - record_and_handle_unexpected(_call, _oc, false); + record_and_handle_unexpected(_call, _oc, false, nullptr); return _oc; } void expect_success(const char* const _call, const Outcome& _oc) { // Call unexpected-outcome handler if the call *failed* - record_and_handle_unexpected(_call, _oc, !_oc.ok()); + record_and_handle_unexpected(_call, _oc, !_oc.ok(), SUCCESS); } void expect_outcome( const char* const _call, const Outcome& _oc, const char* const _error_code) { // Call unexpected-outcome handler if the error code is not correct - record_and_handle_unexpected(_call, _oc, _oc.error_code() != _error_code); + record_and_handle_unexpected( + _call, _oc, _oc.error_code() != _error_code, _error_code); } void expect_outcome( @@ -84,10 +94,11 @@ void expect_outcome( void expect_failure(const char* const _call, const Outcome& _oc) { // If _oc represents a failure, replace it with a generic failure outcome - auto oc = _oc.ok() ? _oc : Outcome(_oc.ok(), "FAILURE", "Failure"); + auto oc = _oc.ok() ? _oc : FAILURE; // Call unexpected-outcome handler if the call *succeeds* - record_and_handle_unexpected(_call, oc, oc.ok()); + record_and_handle_unexpected( + _call, oc, oc.ok(), FAILURE.error_code().c_str()); } void ignore_outcome(const char* const _call, const char* const _reason)