4
* Copyright (C) 2008 10gen Inc.
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Affero General Public License, version 3,
8
* as published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Affero General Public License for more details.
15
* You should have received a copy of the GNU Affero General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
simple portable regression system
24
#include "../stdafx.h"
26
#define ASSERT_EXCEPTION(a,b) \
29
mongo::regression::assert_fail( #a , __FILE__ , __LINE__ ); \
31
mongo::regression::assert_pass(); \
36
#define ASSERT_EQUALS(a,b) (mongo::regression::MyAsserts( #a , #b , __FILE__ , __LINE__ ) ).ae( (a) , (b) )
37
#define ASSERT(x) (void)( (!(!(x))) ? mongo::regression::assert_pass() : mongo::regression::assert_fail( #x , __FILE__ , __LINE__ ) )
38
#define FAIL(x) mongo::regression::fail( #x , __FILE__ , __LINE__ )
40
#include "../db/instance.h"
44
namespace regression {
48
string demangleName( const type_info& typeinfo );
53
virtual void run() = 0;
54
virtual string getName() = 0;
58
class TestHolderBase : public TestCase {
61
virtual ~TestHolderBase(){}
67
virtual T * create() = 0;
68
virtual string getName(){
69
return demangleName( typeid(T) );
74
class TestHolder0 : public TestHolderBase<T> {
81
template< class T , typename A >
82
class TestHolder1 : public TestHolderBase<T> {
84
TestHolder1( const A& a ) : _a(a){}
93
Suite( string name ) : _name( name ){
94
registerSuite( name , this );
101
c.dropDatabase( "unittests" );
107
_tests.push_back( new TestHolder0<T>() );
110
template<class T , typename A >
111
void add( const A& a ){
112
_tests.push_back( new TestHolder1<T,A>(a) );
117
static int run( vector<string> suites );
118
static int run( int argc , char ** argv , string default_dbpath );
122
virtual void setupTests() = 0;
126
list<TestCase*> _tests;
129
static map<string,Suite*> * _suites;
131
void registerSuite( string name , Suite * s );
135
void assert_fail( const char * exp , const char * file , unsigned line );
136
void fail( const char * exp , const char * file , unsigned line );
138
class MyAssertionException : boost::noncopyable {
140
MyAssertionException(){
150
MyAsserts( const char * aexp , const char * bexp , const char * file , unsigned line )
151
: _aexp( aexp ) , _bexp( bexp ) , _file( file ) , _line( line ){
155
template<typename A,typename B>
156
void ae( A a , B b ){
163
MyAssertionException * e = getBase();
164
e->ss << a << " != " << b << endl;
165
log() << e->ss.str() << endl;
169
void printLocation();
175
MyAssertionException * getBase();