#ifndef _tst_Verify_h_ #define _tst_Verify_h_ /** \file Tools to complement the CppUnit testing framework \author Lukas Nellen \author Darko Veberic \version $Id$ \date 08 Feb 2004 \ingroup testing */ #include #include #include #include #include #include #include #include namespace tst { /// Test condition by evaluating a predicate and print on failure /** If the predicate evaluates to false, we print a failure message with the values of the left- and right-hand side and the name of the predicate. This information is normally not available when using the CPPUNIT_ASSERT macro. Verify functions have the same syntax as the utl::Test function, except that in case of failure (result is false) they also print out the exact reason... */ template inline bool Verify(const Predicate& pred, const T& lhs, const T& rhs) { const bool test = pred(lhs, rhs); if (!test) std::cerr << "Failure: " << lhs << " not " << pred.Name() << ' ' << rhs << std::endl; return test; } inline bool Verify(const utl::CloseTo& pred, const utl::Triple& lhs, const utl::Triple& rhs) { const bool test = pred(lhs, rhs); if (!test) std::cerr << "Failure: " << lhs << " not " << pred.Name() << ' ' << rhs << " diff: " << utl::Diff(lhs, rhs) << std::endl; return test; } inline bool Verify(const utl::Not& pred, const utl::Triple& lhs, const utl::Triple& rhs) { const bool test = pred(lhs, rhs); if (!test) std::cerr << "Failure: " << lhs << " not " << pred.Name() << ' ' << rhs << " diff: " << utl::Diff(lhs, rhs) << std::endl; return test; } /// Main test function template inline bool Verify(const T& lhs, const T& rhs) { return Verify(Predicate(), lhs, rhs); } /// Test for predicates with an option template inline bool Verify(const T& lhs, const T& rhs, const double eps) { return Verify(Predicate(eps), lhs, rhs); } /// Print `Expected' for expected failures inline void Expected() { std::cerr << "\nExpected failure: "; } } #endif // Configure (x)emacs for this file ... // Local Variables: // mode: c++ // compile-command: "make -C .. -k" // End: