os/ossrv/ossrv_pub/boost_apis/boost/date_time/testfrmwk.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
sl@0
     2
#ifndef TEST_FRMWK_HPP___
sl@0
     3
#define TEST_FRMWK_HPP___
sl@0
     4
sl@0
     5
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
sl@0
     6
 * Use, modification and distribution is subject to the 
sl@0
     7
 * Boost Software License, Version 1.0. (See accompanying
sl@0
     8
 * file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
sl@0
     9
 * $Date: 2003/11/23 03:29:56 $
sl@0
    10
 */
sl@0
    11
sl@0
    12
sl@0
    13
#include <iostream>
sl@0
    14
#include <string>
sl@0
    15
sl@0
    16
//! Really simple test framework for counting and printing
sl@0
    17
class TestStats
sl@0
    18
{
sl@0
    19
public:
sl@0
    20
  static TestStats& instance() {static TestStats ts; return ts;}
sl@0
    21
  void addPassingTest() {testcount_++; passcount_++;}
sl@0
    22
  void addFailingTest() {testcount_++;}
sl@0
    23
  unsigned int testcount() const {return testcount_;}
sl@0
    24
  unsigned int passcount() const {return passcount_;}
sl@0
    25
  void print(std::ostream& out = std::cout) const
sl@0
    26
  {
sl@0
    27
    out << testcount_ << " Tests Executed: " ;
sl@0
    28
    if (passcount() != testcount()) {
sl@0
    29
      out << (testcount() - passcount()) << " FAILURES";
sl@0
    30
    }
sl@0
    31
    else {
sl@0
    32
      out << "All Succeeded" << std::endl;
sl@0
    33
    }
sl@0
    34
    out << std::endl;
sl@0
    35
  }
sl@0
    36
private:  
sl@0
    37
  TestStats() : testcount_(0), passcount_(0) {}
sl@0
    38
  unsigned int testcount_;
sl@0
    39
  unsigned int passcount_;
sl@0
    40
};
sl@0
    41
sl@0
    42
sl@0
    43
bool check(const std::string& testname, bool testcond) 
sl@0
    44
{
sl@0
    45
  TestStats& stat = TestStats::instance();
sl@0
    46
  if (testcond) {
sl@0
    47
    std::cout << "Pass :: " << testname << " " <<  std::endl;
sl@0
    48
    stat.addPassingTest();
sl@0
    49
    return true;
sl@0
    50
  }
sl@0
    51
  else {
sl@0
    52
    stat.addFailingTest();
sl@0
    53
    std::cout << "FAIL :: " << testname << " " <<  std::endl;
sl@0
    54
    return false;
sl@0
    55
  }
sl@0
    56
}
sl@0
    57
sl@0
    58
sl@0
    59
int printTestStats() 
sl@0
    60
{
sl@0
    61
  TestStats& stat = TestStats::instance();
sl@0
    62
  stat.print();
sl@0
    63
  return stat.testcount() - stat.passcount();
sl@0
    64
}
sl@0
    65
sl@0
    66
#endif