2 #ifndef TEST_FRMWK_HPP___
3 #define TEST_FRMWK_HPP___
5 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
6 * Use, modification and distribution is subject to the
7 * Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
15 #include <boost/config.hpp>
17 //! Really simple test framework for counting and printing
21 static TestStats& instance() {static TestStats ts; return ts;}
22 void addPassingTest() {testcount_++; passcount_++;}
23 void addFailingTest() {testcount_++;}
24 unsigned int testcount() const {return testcount_;}
25 unsigned int passcount() const {return passcount_;}
26 void print(std::ostream& out = std::cout) const
28 out << testcount_ << " Tests Executed: " ;
29 if (passcount() != testcount()) {
30 out << (testcount() - passcount()) << " FAILURES";
33 out << "All Succeeded" << std::endl;
38 TestStats() : testcount_(0), passcount_(0) {}
39 unsigned int testcount_;
40 unsigned int passcount_;
44 inline bool check(const std::string& testname, bool testcond)
46 TestStats& stat = TestStats::instance();
48 std::cout << "Pass :: " << testname << " " << std::endl;
49 stat.addPassingTest();
53 stat.addFailingTest();
54 std::cout << "FAIL :: " << testname << " " << std::endl;
59 // In the comparisons below, it is possible that T and U are signed and unsigned integer types, which generates warnings in some compilers.
60 #if defined(BOOST_MSVC)
61 # pragma warning(push)
62 # pragma warning(disable: 4389)
63 #elif defined(BOOST_CLANG) && defined(__has_warning)
64 # if __has_warning("-Wsign-compare")
65 # pragma clang diagnostic push
66 # pragma clang diagnostic ignored "-Wsign-compare"
68 #elif defined(BOOST_GCC) && (BOOST_GCC+0) >= 40600
69 # pragma GCC diagnostic push
70 # pragma GCC diagnostic ignored "-Wsign-compare"
73 template< typename T, typename U >
74 inline bool check_equal(const std::string& testname, T const& left, U const& right)
76 bool res = check(testname, left == right);
79 std::cout << " left = " << left << ", right = " << right << std::endl;
84 #if defined(BOOST_MSVC)
86 #elif defined(BOOST_CLANG) && defined(__has_warning)
87 # if __has_warning("-Wsign-compare")
88 # pragma clang diagnostic pop
90 #elif defined(BOOST_GCC) && (BOOST_GCC+0) >= 40600
91 # pragma GCC diagnostic pop
94 #ifndef BOOST_NO_STD_WSTRING
95 inline bool check_equal(const std::string& testname, std::wstring const& left, std::wstring const& right)
97 bool res = check(testname, left == right);
100 std::wcout << L" left = " << left << L", right = " << right << std::endl;
106 inline int printTestStats()
108 TestStats& stat = TestStats::instance();
110 return stat.testcount() - stat.passcount();