unittest.h

00001 /*
00002  *  Copyright (C) 2006  Helmut Grohne
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00019 #ifndef LIBMUTH_UNITTEST_H
00020 #define LIBMUTH_UNITTEST_H
00021 
00022 #include "unittest_decls.h"
00023 
00024 inline ForwardGatherer::ForwardGatherer(BaseGatherer &g, const std::string &p)
00025                 : gatherer(g.forwardto()), prefix(g.prefixed() + p) {
00026 }
00027 
00028 inline Gatherer::Gatherer() : succeeded(0), failed(0) {
00029 }
00030 
00031 inline BaseTest::BaseTest(const std::string &n) : name(n) {
00032 }
00033 
00034 template<class F> inline TestCase<F>::TestCase(const std::string &n,
00035                 void (F::*func)()) : BaseTest(n), function(func) {
00036 }
00037 
00038 template<class F> inline TestCase<F>::TestCase(const TestCase<F> &o)
00039                 : BaseTest(o), function(o.function) {
00040 }
00041 
00042 template<class F> inline TestCase<F> *TestCase<F>::clone() const {
00043         return new TestCase<F>(*this);
00044 }
00045 
00046 template<class F> void TestCase<F>::run(BaseGatherer &g) {
00047         F fixture;
00048         bool succeeded(false);
00049         try {
00050                 (fixture.*function)();
00051                 succeeded = true;
00052         } catch(Failure &f) {
00053                 g.fail(this->name, f.what());
00054         } catch(...) {
00055                 g.fail(this->name, std::string("unknown exception caught"));
00056         } if(succeeded)
00057                 g.succeed(this->name);
00058 }
00059 
00060 inline TestSuite::TestSuite(const std::string &n) : BaseTest(n) {
00061 }
00062 
00063 inline TestSuite::TestSuite(const TestSuite &o) : BaseTest(o) {
00064         for(std::list<BaseTest*>::const_iterator i(o.tests.begin());
00065                         i!=o.tests.end();
00066                         ++i)
00067                 this->tests.push_back((*i)->clone());
00068 }
00069 
00070 inline Failure::Failure(const std::string &r) : std::runtime_error(r) {
00071 }
00072 
00073 #endif

Generated on Thu Feb 14 13:30:30 2008 by  doxygen 1.5.1