| [29] | 1 |  | 
|---|
|  | 2 | #ifndef TEST_FRMWK_HPP___ | 
|---|
|  | 3 | #define TEST_FRMWK_HPP___ | 
|---|
|  | 4 |  | 
|---|
|  | 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 or http://www.boost.org/LICENSE-1.0) | 
|---|
|  | 9 | * $Date: 2003/11/23 03:29:56 $ | 
|---|
|  | 10 | */ | 
|---|
|  | 11 |  | 
|---|
|  | 12 |  | 
|---|
|  | 13 | #include <iostream> | 
|---|
|  | 14 | #include <string> | 
|---|
|  | 15 |  | 
|---|
|  | 16 | //! Really simple test framework for counting and printing | 
|---|
|  | 17 | class TestStats | 
|---|
|  | 18 | { | 
|---|
|  | 19 | public: | 
|---|
|  | 20 | static TestStats& instance() {static TestStats ts; return ts;} | 
|---|
|  | 21 | void addPassingTest() {testcount_++; passcount_++;} | 
|---|
|  | 22 | void addFailingTest() {testcount_++;} | 
|---|
|  | 23 | unsigned int testcount() const {return testcount_;} | 
|---|
|  | 24 | unsigned int passcount() const {return passcount_;} | 
|---|
|  | 25 | void print(std::ostream& out = std::cout) const | 
|---|
|  | 26 | { | 
|---|
|  | 27 | out << testcount_ << " Tests Executed: " ; | 
|---|
|  | 28 | if (passcount() != testcount()) { | 
|---|
|  | 29 | out << (testcount() - passcount()) << " FAILURES"; | 
|---|
|  | 30 | } | 
|---|
|  | 31 | else { | 
|---|
|  | 32 | out << "All Succeeded" << std::endl; | 
|---|
|  | 33 | } | 
|---|
|  | 34 | out << std::endl; | 
|---|
|  | 35 | } | 
|---|
|  | 36 | private: | 
|---|
|  | 37 | TestStats() : testcount_(0), passcount_(0) {} | 
|---|
|  | 38 | unsigned int testcount_; | 
|---|
|  | 39 | unsigned int passcount_; | 
|---|
|  | 40 | }; | 
|---|
|  | 41 |  | 
|---|
|  | 42 |  | 
|---|
|  | 43 | bool check(const std::string& testname, bool testcond) | 
|---|
|  | 44 | { | 
|---|
|  | 45 | TestStats& stat = TestStats::instance(); | 
|---|
|  | 46 | if (testcond) { | 
|---|
|  | 47 | std::cout << "Pass :: " << testname << " " <<  std::endl; | 
|---|
|  | 48 | stat.addPassingTest(); | 
|---|
|  | 49 | return true; | 
|---|
|  | 50 | } | 
|---|
|  | 51 | else { | 
|---|
|  | 52 | stat.addFailingTest(); | 
|---|
|  | 53 | std::cout << "FAIL :: " << testname << " " <<  std::endl; | 
|---|
|  | 54 | return false; | 
|---|
|  | 55 | } | 
|---|
|  | 56 | } | 
|---|
|  | 57 |  | 
|---|
|  | 58 |  | 
|---|
|  | 59 | int printTestStats() | 
|---|
|  | 60 | { | 
|---|
|  | 61 | TestStats& stat = TestStats::instance(); | 
|---|
|  | 62 | stat.print(); | 
|---|
|  | 63 | return stat.testcount() - stat.passcount(); | 
|---|
|  | 64 | } | 
|---|
|  | 65 |  | 
|---|
|  | 66 | #endif | 
|---|