// basictests.cpp : basic unit tests
//
/**
* Copyright (C) 2009 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
#include "stdafx.h"
#include "dbtests.h"
#include "../util/base64.h"
namespace BasicTests {
class Rarely {
public:
void run() {
int first = 0;
int second = 0;
int third = 0;
for( int i = 0; i < 128; ++i ) {
incRarely( first );
incRarely2( second );
ONCE ++third;
}
ASSERT_EQUALS( 1, first );
ASSERT_EQUALS( 1, second );
ASSERT_EQUALS( 1, third );
}
private:
void incRarely( int &c ) {
RARELY ++c;
}
void incRarely2( int &c ) {
RARELY ++c;
}
};
class Base64Tests {
public:
void roundTrip( string s ){
ASSERT_EQUALS( s , base64::decode( base64::encode( s ) ) );
}
void roundTrip( const unsigned char * _data , int len ){
const char *data = (const char *) _data;
string s = base64::encode( data , len );
string out = base64::decode( s );
ASSERT_EQUALS( out.size() , static_cast(len) );
bool broke = false;
for ( int i=0; i 1000000 );
ASSERT( t.micros() < 2000000 );
t.reset();
sleepmillis( 1727 );
ASSERT( t.millis() >= 1000 );
ASSERT( t.millis() <= 2000 );
}
};
class AssertTests {
public:
int x;
AssertTests(){
x = 0;
}
string foo(){
x++;
return "";
}
void run(){
uassert( -1 , foo() , 1 );
ASSERT_EQUALS( 0 , x );
try {
uassert( -1 , foo() , 0 );
}
catch ( ... ){}
ASSERT_EQUALS( 1 , x );
}
};
class All : public Suite {
public:
All() : Suite( "basic" ){
}
void setupTests(){
add< Rarely >();
add< Base64Tests >();
add< stringbuildertests::simple1 >();
add< stringbuildertests::simple2 >();
add< stringbuildertests::reset1 >();
add< stringbuildertests::reset2 >();
add< sleeptest >();
add< AssertTests >();
}
} myall;
} // namespace BasicTests