summaryrefslogtreecommitdiff
path: root/dbtests
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-01-04 00:40:41 -0500
committerEliot Horowitz <eliot@10gen.com>2011-01-04 00:40:41 -0500
commitb828d21630d8715fff5a30c682a51ab79880093d (patch)
treecbbc46069dcfc08ab1525ec06a5dff5967dde148 /dbtests
parent4315a900ae604e11f2d9d68d1e6f87b8aa01dddc (diff)
downloadmongo-b828d21630d8715fff5a30c682a51ab79880093d.tar.gz
ran astyle SERVER-2304
Diffstat (limited to 'dbtests')
-rw-r--r--dbtests/background_job_test.cpp20
-rw-r--r--dbtests/balancer_policy_tests.cpp30
-rw-r--r--dbtests/basictests.cpp196
-rw-r--r--dbtests/btreetests.cpp308
-rw-r--r--dbtests/clienttests.cpp60
-rw-r--r--dbtests/commandtests.cpp18
-rw-r--r--dbtests/cursortests.cpp33
-rw-r--r--dbtests/d_chunk_manager_tests.cpp140
-rw-r--r--dbtests/directclienttests.cpp8
-rw-r--r--dbtests/framework.cpp126
-rw-r--r--dbtests/framework.h52
-rw-r--r--dbtests/histogram_test.cpp20
-rw-r--r--dbtests/jsobjtests.cpp300
-rw-r--r--dbtests/jsontests.cpp74
-rw-r--r--dbtests/jstests.cpp314
-rw-r--r--dbtests/matchertests.cpp48
-rw-r--r--[-rwxr-xr-x]dbtests/mmaptests.cpp48
-rw-r--r--dbtests/mockdbclient.h4
-rw-r--r--dbtests/namespacetests.cpp46
-rw-r--r--dbtests/pairingtests.cpp24
-rw-r--r--dbtests/pdfiletests.cpp40
-rw-r--r--dbtests/perf/btreeperf.cpp65
-rw-r--r--dbtests/perf/perftest.cpp86
-rw-r--r--dbtests/perftests.cpp68
-rw-r--r--dbtests/queryoptimizertests.cpp328
-rw-r--r--dbtests/querytests.cpp207
-rw-r--r--dbtests/repltests.cpp335
-rw-r--r--dbtests/sharding.cpp12
-rw-r--r--dbtests/socktests.cpp10
-rw-r--r--dbtests/spin_lock_test.cpp68
-rw-r--r--dbtests/threadedtests.cpp72
-rw-r--r--dbtests/updatetests.cpp166
32 files changed, 1672 insertions, 1654 deletions
diff --git a/dbtests/background_job_test.cpp b/dbtests/background_job_test.cpp
index 44190a8f145..f2bf7d86244 100644
--- a/dbtests/background_job_test.cpp
+++ b/dbtests/background_job_test.cpp
@@ -31,10 +31,10 @@ namespace BackgroundJobTests {
class IncTester : public mongo::BackgroundJob {
public:
- explicit IncTester( long long millis , bool selfDelete = false )
+ explicit IncTester( long long millis , bool selfDelete = false )
: BackgroundJob(selfDelete), _val(0), _millis(millis) { GLOBAL_val = 0; }
- void waitAndInc( long long millis ){
+ void waitAndInc( long long millis ) {
if ( millis )
mongo::sleepmillis( millis );
++_val;
@@ -48,14 +48,14 @@ namespace BackgroundJobTests {
string name() const { return "IncTester"; }
void run() { waitAndInc( _millis ); }
-
+
private:
int _val;
long long _millis;
};
- class NormalCase {
+ class NormalCase {
public:
void run() {
IncTester tester( 0 /* inc without wait */ );
@@ -85,20 +85,20 @@ namespace BackgroundJobTests {
BackgroundJob* j = new IncTester( 0 /* inc without wait */ , true /* self delete */ );
j->go();
-
- // the background thread should have continued running and this test should pass the
+
+ // the background thread should have continued running and this test should pass the
// heap-checker as well
mongo::sleepmillis( 1000 );
ASSERT_EQUALS( GLOBAL_val, 1 );
}
};
-
- class BackgroundJobSuite : public Suite{
+
+ class BackgroundJobSuite : public Suite {
public:
- BackgroundJobSuite() : Suite( "background_job" ){}
+ BackgroundJobSuite() : Suite( "background_job" ) {}
- void setupTests(){
+ void setupTests() {
add< NormalCase >();
add< TimeOutCase >();
add< SelfDeletingCase >();
diff --git a/dbtests/balancer_policy_tests.cpp b/dbtests/balancer_policy_tests.cpp
index 36010719aaf..6f7c4a5dcd3 100644
--- a/dbtests/balancer_policy_tests.cpp
+++ b/dbtests/balancer_policy_tests.cpp
@@ -35,7 +35,7 @@ namespace BalancerPolicyTests {
class SizeMaxedShardTest {
public:
- void run(){
+ void run() {
BSONObj shard0 = BSON( sf::maxSize(0LL) << lf::currSize(0LL) );
ASSERT( ! BalancerPolicy::isSizeMaxed( shard0 ) );
@@ -52,7 +52,7 @@ namespace BalancerPolicyTests {
class DrainingShardTest {
public:
- void run(){
+ void run() {
BSONObj shard0 = BSON( sf::draining(true) );
ASSERT( BalancerPolicy::isDraining( shard0 ) );
@@ -66,7 +66,7 @@ namespace BalancerPolicyTests {
class BalanceNormalTest {
public:
- void run(){
+ void run() {
// 2 chunks and 0 chunk shards
BalancerPolicy::ShardToChunksMap chunkMap;
vector<BSONObj> chunks;
@@ -84,7 +84,7 @@ namespace BalancerPolicyTests {
BSONObj limits1 = BSON( sf::maxSize(0LL) << lf::currSize(0LL) << sf::draining(false) << lf::hasOpsQueued(false) );
limitsMap["shard0"] = limits0;
limitsMap["shard1"] = limits1;
-
+
BalancerPolicy::ChunkInfo* c = NULL;
c = BalancerPolicy::balance( "ns", limitsMap, chunkMap, 1 );
ASSERT( c );
@@ -93,7 +93,7 @@ namespace BalancerPolicyTests {
class BalanceDrainingTest {
public:
- void run(){
+ void run() {
// one normal, one draining
// 2 chunks and 0 chunk shards
BalancerPolicy::ShardToChunksMap chunkMap;
@@ -112,7 +112,7 @@ namespace BalancerPolicyTests {
BSONObj limits1 = BSON( sf::maxSize(0LL) << lf::currSize(0LL) << sf::draining(false) );
limitsMap["shard0"] = limits0;
limitsMap["shard1"] = limits1;
-
+
BalancerPolicy::ChunkInfo* c = NULL;
c = BalancerPolicy::balance( "ns", limitsMap, chunkMap, 0 );
ASSERT( c );
@@ -124,7 +124,7 @@ namespace BalancerPolicyTests {
class BalanceEndedDrainingTest {
public:
- void run(){
+ void run() {
// 2 chunks and 0 chunk (drain completed) shards
BalancerPolicy::ShardToChunksMap chunkMap;
vector<BSONObj> chunks;
@@ -142,7 +142,7 @@ namespace BalancerPolicyTests {
BSONObj limits1 = BSON( sf::maxSize(0LL) << lf::currSize(0LL) << sf::draining(true) );
limitsMap["shard0"] = limits0;
limitsMap["shard1"] = limits1;
-
+
BalancerPolicy::ChunkInfo* c = NULL;
c = BalancerPolicy::balance( "ns", limitsMap, chunkMap, 0 );
ASSERT( ! c );
@@ -151,7 +151,7 @@ namespace BalancerPolicyTests {
class BalanceImpasseTest {
public:
- void run(){
+ void run() {
// one maxed out, one draining
// 2 chunks and 0 chunk shards
BalancerPolicy::ShardToChunksMap chunkMap;
@@ -172,7 +172,7 @@ namespace BalancerPolicyTests {
limitsMap["shard0"] = limits0;
limitsMap["shard1"] = limits1;
limitsMap["shard2"] = limits2;
-
+
BalancerPolicy::ChunkInfo* c = NULL;
c = BalancerPolicy::balance( "ns", limitsMap, chunkMap, 0 );
ASSERT( ! c );
@@ -186,10 +186,10 @@ namespace BalancerPolicyTests {
class All : public Suite {
public:
- All() : Suite( "balancer_policy" ){
+ All() : Suite( "balancer_policy" ) {
}
- void setupTests(){
+ void setupTests() {
// TODO SERVER-1822
// add< SizeMaxedShardTest >();
// add< DrainingShardTest >();
@@ -197,7 +197,7 @@ namespace BalancerPolicyTests {
// add< BalanceDrainingTest >();
// add< BalanceEndedDrainingTest >();
// add< BalanceImpasseTest >();
- }
- } allTests;
-
+ }
+ } allTests;
+
} // namespace BalancerPolicyTests
diff --git a/dbtests/basictests.cpp b/dbtests/basictests.cpp
index a417f05b28c..6b802db0092 100644
--- a/dbtests/basictests.cpp
+++ b/dbtests/basictests.cpp
@@ -51,21 +51,21 @@ namespace BasicTests {
RARELY ++c;
}
};
-
+
class Base64Tests {
public:
-
- void roundTrip( string s ){
+
+ void roundTrip( string s ) {
ASSERT_EQUALS( s , base64::decode( base64::encode( s ) ) );
}
-
- void roundTrip( const unsigned char * _data , int len ){
+
+ 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<size_t>(len) );
bool broke = false;
- for ( int i=0; i<len; i++ ){
+ for ( int i=0; i<len; i++ ) {
if ( data[i] != out[i] )
broke = true;
}
@@ -79,16 +79,16 @@ namespace BasicTests {
for ( int i=0; i<len; i++ )
cout << hex << ( out[i] & 0xFF ) << dec << " ";
cout << endl;
-
+
ASSERT(0);
}
-
- void run(){
+
+ void run() {
ASSERT_EQUALS( "ZWxp" , base64::encode( "eli" , 3 ) );
ASSERT_EQUALS( "ZWxpb3Rz" , base64::encode( "eliots" , 6 ) );
ASSERT_EQUALS( "ZWxpb3Rz" , base64::encode( "eliots" ) );
-
+
ASSERT_EQUALS( "ZQ==" , base64::encode( "e" , 1 ) );
ASSERT_EQUALS( "ZWw=" , base64::encode( "el" , 2 ) );
@@ -99,10 +99,10 @@ namespace BasicTests {
roundTrip( "eliot" );
roundTrip( "eliots" );
roundTrip( "eliotsz" );
-
+
unsigned char z[] = { 0x1 , 0x2 , 0x3 , 0x4 };
roundTrip( z , 4 );
-
+
unsigned char y[] = {
0x01, 0x10, 0x83, 0x10, 0x51, 0x87, 0x20, 0x92, 0x8B, 0x30,
0xD3, 0x8F, 0x41, 0x14, 0x93, 0x51, 0x55, 0x97, 0x61, 0x96,
@@ -117,15 +117,15 @@ namespace BasicTests {
namespace stringbuildertests {
#define SBTGB(x) ss << (x); sb << (x);
-
+
class Base {
virtual void pop() = 0;
-
+
public:
- Base(){}
- virtual ~Base(){}
+ Base() {}
+ virtual ~Base() {}
- void run(){
+ void run() {
pop();
ASSERT_EQUALS( ss.str() , sb.str() );
}
@@ -133,9 +133,9 @@ namespace BasicTests {
stringstream ss;
StringBuilder sb;
};
-
+
class simple1 : public Base {
- void pop(){
+ void pop() {
SBTGB(1);
SBTGB("yo");
SBTGB(2);
@@ -143,7 +143,7 @@ namespace BasicTests {
};
class simple2 : public Base {
- void pop(){
+ void pop() {
SBTGB(1);
SBTGB("yo");
SBTGB(2);
@@ -156,10 +156,10 @@ namespace BasicTests {
SBTGB( (short)(1231231231231LL) );
}
};
-
+
class reset1 {
public:
- void run(){
+ void run() {
StringBuilder sb;
sb << "1" << "abc" << "5.17";
ASSERT_EQUALS( "1abc5.17" , sb.str() );
@@ -173,7 +173,7 @@ namespace BasicTests {
class reset2 {
public:
- void run(){
+ void run() {
StringBuilder sb;
sb << "1" << "abc" << "5.17";
ASSERT_EQUALS( "1abc5.17" , sb.str() );
@@ -190,7 +190,7 @@ namespace BasicTests {
class sleeptest {
public:
- void run(){
+ void run() {
Timer t;
sleepsecs( 1 );
ASSERT_EQUALS( 1 , t.seconds() );
@@ -204,17 +204,17 @@ namespace BasicTests {
sleepmillis( 1727 );
ASSERT( t.millis() >= 1000 );
ASSERT( t.millis() <= 2500 );
-
+
{
int total = 1200;
int ms = 2;
t.reset();
- for ( int i=0; i<(total/ms); i++ ){
+ for ( int i=0; i<(total/ms); i++ ) {
sleepmillis( ms );
}
{
int x = t.millis();
- if ( x < 1000 || x > 2500 ){
+ if ( x < 1000 || x > 2500 ) {
cout << "sleeptest x: " << x << endl;
ASSERT( x >= 1000 );
ASSERT( x <= 20000 );
@@ -228,12 +228,12 @@ namespace BasicTests {
int micros = 100;
t.reset();
int numSleeps = 1000*(total/micros);
- for ( int i=0; i<numSleeps; i++ ){
+ for ( int i=0; i<numSleeps; i++ ) {
sleepmicros( micros );
}
{
int y = t.millis();
- if ( y < 1000 || y > 2500 ){
+ if ( y < 1000 || y > 2500 ) {
cout << "sleeptest y: " << y << endl;
ASSERT( y >= 1000 );
/* ASSERT( y <= 100000 ); */
@@ -241,9 +241,9 @@ namespace BasicTests {
}
}
#endif
-
+
}
-
+
};
class AssertTests {
@@ -251,15 +251,15 @@ namespace BasicTests {
int x;
- AssertTests(){
+ AssertTests() {
x = 0;
}
- string foo(){
+ string foo() {
x++;
return "";
}
- void run(){
+ void run() {
uassert( -1 , foo() , 1 );
if( x != 0 ) {
ASSERT_EQUALS( 0 , x );
@@ -267,7 +267,7 @@ namespace BasicTests {
try {
uassert( -1 , foo() , 0 );
}
- catch ( ... ){}
+ catch ( ... ) {}
ASSERT_EQUALS( 1 , x );
}
};
@@ -275,13 +275,13 @@ namespace BasicTests {
namespace ArrayTests {
class basic1 {
public:
- void run(){
+ void run() {
FastArray<int> a(100);
a.push_back( 5 );
a.push_back( 6 );
-
+
ASSERT_EQUALS( 2 , a.size() );
-
+
FastArray<int>::iterator i = a.begin();
ASSERT( i != a.end() );
ASSERT_EQUALS( 5 , *i );
@@ -293,10 +293,10 @@ namespace BasicTests {
}
};
};
-
+
class ThreadSafeStringTest {
public:
- void run(){
+ void run() {
ThreadSafeString s;
s = "eliot";
ASSERT_EQUALS( s , "eliot" );
@@ -304,8 +304,8 @@ namespace BasicTests {
ThreadSafeString s2 = s;
ASSERT_EQUALS( s2 , "eliot" );
-
-
+
+
{
string foo;
{
@@ -317,11 +317,11 @@ namespace BasicTests {
}
}
};
-
+
class LexNumCmp {
public:
void run() {
-
+
ASSERT( ! isNumber( (char)255 ) );
ASSERT_EQUALS( 0, lexNumCmp( "a", "a" ) );
@@ -357,7 +357,7 @@ namespace BasicTests {
ASSERT_EQUALS( -1, lexNumCmp( "a1{", "a1{a" ) );
ASSERT_EQUALS( 1, lexNumCmp("21", "11") );
ASSERT_EQUALS( -1, lexNumCmp("11", "21") );
-
+
ASSERT_EQUALS( -1 , lexNumCmp( "a.0" , "a.1" ) );
ASSERT_EQUALS( -1 , lexNumCmp( "a.0.b" , "a.1" ) );
@@ -365,39 +365,39 @@ namespace BasicTests {
ASSERT_EQUALS( -1 , lexNumCmp( "b.0e" , (string("b.") + (char)255).c_str() ) );
ASSERT_EQUALS( -1 , lexNumCmp( "b." , "b.0e" ) );
- ASSERT_EQUALS( 0, lexNumCmp( "238947219478347782934718234", "238947219478347782934718234"));
- ASSERT_EQUALS( 0, lexNumCmp( "000238947219478347782934718234", "238947219478347782934718234"));
- ASSERT_EQUALS( 1, lexNumCmp( "000238947219478347782934718235", "238947219478347782934718234"));
- ASSERT_EQUALS( -1, lexNumCmp( "238947219478347782934718234", "238947219478347782934718234.1"));
- ASSERT_EQUALS( 0, lexNumCmp( "238", "000238"));
- ASSERT_EQUALS( 0, lexNumCmp( "002384", "0002384"));
- ASSERT_EQUALS( 0, lexNumCmp( "00002384", "0002384"));
- ASSERT_EQUALS( 0, lexNumCmp( "0", "0"));
- ASSERT_EQUALS( 0, lexNumCmp( "0000", "0"));
+ ASSERT_EQUALS( 0, lexNumCmp( "238947219478347782934718234", "238947219478347782934718234"));
+ ASSERT_EQUALS( 0, lexNumCmp( "000238947219478347782934718234", "238947219478347782934718234"));
+ ASSERT_EQUALS( 1, lexNumCmp( "000238947219478347782934718235", "238947219478347782934718234"));
+ ASSERT_EQUALS( -1, lexNumCmp( "238947219478347782934718234", "238947219478347782934718234.1"));
+ ASSERT_EQUALS( 0, lexNumCmp( "238", "000238"));
+ ASSERT_EQUALS( 0, lexNumCmp( "002384", "0002384"));
+ ASSERT_EQUALS( 0, lexNumCmp( "00002384", "0002384"));
+ ASSERT_EQUALS( 0, lexNumCmp( "0", "0"));
+ ASSERT_EQUALS( 0, lexNumCmp( "0000", "0"));
ASSERT_EQUALS( 0, lexNumCmp( "0", "000"));
ASSERT_EQUALS( -1, lexNumCmp( "0000", "0.0"));
- ASSERT_EQUALS( 1, lexNumCmp( "2380", "238"));
- ASSERT_EQUALS( 1, lexNumCmp( "2385", "2384"));
- ASSERT_EQUALS( 1, lexNumCmp( "2385", "02384"));
- ASSERT_EQUALS( 1, lexNumCmp( "2385", "002384"));
- ASSERT_EQUALS( -1, lexNumCmp( "123.234.4567", "00238"));
- ASSERT_EQUALS( 0, lexNumCmp( "123.234", "00123.234"));
- ASSERT_EQUALS( 0, lexNumCmp( "a.123.b", "a.00123.b"));
- ASSERT_EQUALS( 1, lexNumCmp( "a.123.b", "a.b.00123.b"));
- ASSERT_EQUALS( -1, lexNumCmp( "a.00.0", "a.0.1"));
- ASSERT_EQUALS( 0, lexNumCmp( "01.003.02", "1.3.2"));
- ASSERT_EQUALS( -1, lexNumCmp( "1.3.2", "10.300.20"));
- ASSERT_EQUALS( 0, lexNumCmp( "10.300.20", "000000000000010.0000300.000000020"));
- ASSERT_EQUALS( 0, lexNumCmp( "0000a", "0a"));
- ASSERT_EQUALS( -1, lexNumCmp( "a", "0a"));
- ASSERT_EQUALS( -1, lexNumCmp( "000a", "001a"));
- ASSERT_EQUALS( 0, lexNumCmp( "010a", "0010a"));
+ ASSERT_EQUALS( 1, lexNumCmp( "2380", "238"));
+ ASSERT_EQUALS( 1, lexNumCmp( "2385", "2384"));
+ ASSERT_EQUALS( 1, lexNumCmp( "2385", "02384"));
+ ASSERT_EQUALS( 1, lexNumCmp( "2385", "002384"));
+ ASSERT_EQUALS( -1, lexNumCmp( "123.234.4567", "00238"));
+ ASSERT_EQUALS( 0, lexNumCmp( "123.234", "00123.234"));
+ ASSERT_EQUALS( 0, lexNumCmp( "a.123.b", "a.00123.b"));
+ ASSERT_EQUALS( 1, lexNumCmp( "a.123.b", "a.b.00123.b"));
+ ASSERT_EQUALS( -1, lexNumCmp( "a.00.0", "a.0.1"));
+ ASSERT_EQUALS( 0, lexNumCmp( "01.003.02", "1.3.2"));
+ ASSERT_EQUALS( -1, lexNumCmp( "1.3.2", "10.300.20"));
+ ASSERT_EQUALS( 0, lexNumCmp( "10.300.20", "000000000000010.0000300.000000020"));
+ ASSERT_EQUALS( 0, lexNumCmp( "0000a", "0a"));
+ ASSERT_EQUALS( -1, lexNumCmp( "a", "0a"));
+ ASSERT_EQUALS( -1, lexNumCmp( "000a", "001a"));
+ ASSERT_EQUALS( 0, lexNumCmp( "010a", "0010a"));
}
};
class DatabaseValidNames {
public:
- void run(){
+ void run() {
ASSERT( Database::validDBName( "foo" ) );
ASSERT( ! Database::validDBName( "foo/bar" ) );
ASSERT( ! Database::validDBName( "foo.bar" ) );
@@ -410,14 +410,14 @@ namespace BasicTests {
class DatabaseOwnsNS {
public:
- void run(){
-
+ void run() {
+
bool isNew = false;
// this leaks as ~Database is private
// if that changes, should put this on the stack
Database * db = new Database( "dbtests_basictests_ownsns" , isNew );
assert( isNew );
-
+
ASSERT( db->ownsNS( "dbtests_basictests_ownsns.x" ) );
ASSERT( db->ownsNS( "dbtests_basictests_ownsns.x.y" ) );
ASSERT( ! db->ownsNS( "dbtests_basictests_ownsn.x.y" ) );
@@ -427,16 +427,16 @@ namespace BasicTests {
class NSValidNames {
public:
- void run(){
+ void run() {
ASSERT( isValidNS( "test.foo" ) );
ASSERT( ! isValidNS( "test." ) );
ASSERT( ! isValidNS( "test" ) );
}
};
-
+
class PtrTests {
public:
- void run(){
+ void run() {
scoped_ptr<int> p1 (new int(1));
boost::shared_ptr<int> p2 (new int(2));
scoped_ptr<const int> p3 (new int(3));
@@ -447,7 +447,7 @@ namespace BasicTests {
ASSERT_EQUALS( p2.get() , ptr<int>(p2) );
ASSERT_EQUALS( p2.get() , ptr<int>(p2.get()) ); // T* constructor
ASSERT_EQUALS( p2.get() , ptr<int>(ptr<int>(p2)) ); // copy constructor
- ASSERT_EQUALS( *p2 , *ptr<int>(p2));
+ ASSERT_EQUALS( *p2 , *ptr<int>(p2));
ASSERT_EQUALS( p2.get() , ptr<boost::shared_ptr<int> >(&p2)->get() ); // operator->
//const
@@ -459,14 +459,14 @@ namespace BasicTests {
ASSERT_EQUALS( p4.get() , ptr<const int>(p4.get()) );
ASSERT_EQUALS( p2.get() , ptr<const int>(ptr<const int>(p2)) );
ASSERT_EQUALS( p2.get() , ptr<const int>(ptr<int>(p2)) ); // constizing copy constructor
- ASSERT_EQUALS( *p2 , *ptr<int>(p2));
+ ASSERT_EQUALS( *p2 , *ptr<int>(p2));
ASSERT_EQUALS( p2.get() , ptr<const boost::shared_ptr<int> >(&p2)->get() );
//bool context
ASSERT( ptr<int>(p1) );
ASSERT( !ptr<int>(NULL) );
ASSERT( !ptr<int>() );
-
+
#if 0
// These shouldn't compile
ASSERT_EQUALS( p3.get() , ptr<int>(p3) );
@@ -478,12 +478,12 @@ namespace BasicTests {
struct StringSplitterTest {
- void test( string s ){
+ void test( string s ) {
vector<string> v = StringSplitter::split( s , "," );
ASSERT_EQUALS( s , StringSplitter::join( v , "," ) );
}
- void run(){
+ void run() {
test( "a" );
test( "a,b" );
test( "a,b,c" );
@@ -526,7 +526,7 @@ namespace BasicTests {
class QueueTest {
public:
- void run(){
+ void run() {
BlockingQueue<int> q;
Timer t;
int x;
@@ -538,32 +538,32 @@ namespace BasicTests {
class StrTests {
public:
-
- void run(){
+
+ void run() {
ASSERT_EQUALS( 1u , str::count( "abc" , 'b' ) );
ASSERT_EQUALS( 3u , str::count( "babab" , 'b' ) );
}
-
+
};
-
+
class HostAndPortTests {
public:
- void run(){
+ void run() {
HostAndPort a( "x1" , 1000 );
HostAndPort b( "x1" , 1000 );
HostAndPort c( "x1" , 1001 );
HostAndPort d( "x2" , 1000 );
-
+
ASSERT( a == b );
ASSERT( a != c );
ASSERT( a != d );
-
+
}
};
class RelativePathTest {
public:
- void run(){
+ void run() {
RelativePath a = RelativePath::fromRelativePath( "a" );
RelativePath b = RelativePath::fromRelativePath( "a" );
RelativePath c = RelativePath::fromRelativePath( "b" );
@@ -579,13 +579,13 @@ namespace BasicTests {
class All : public Suite {
public:
- All() : Suite( "basic" ){
+ All() : Suite( "basic" ) {
}
-
- void setupTests(){
+
+ void setupTests() {
add< Rarely >();
add< Base64Tests >();
-
+
add< stringbuildertests::simple1 >();
add< stringbuildertests::simple2 >();
add< stringbuildertests::reset1 >();
@@ -593,7 +593,7 @@ namespace BasicTests {
add< sleeptest >();
add< AssertTests >();
-
+
add< ArrayTests::basic1 >();
add< LexNumCmp >();
@@ -610,11 +610,11 @@ namespace BasicTests {
add< QueueTest >();
add< StrTests >();
-
+
add< HostAndPortTests >();
add< RelativePathTest >();
}
} myall;
-
+
} // namespace BasicTests
diff --git a/dbtests/btreetests.cpp b/dbtests/btreetests.cpp
index 50e17ac64e2..d29f460e645 100644
--- a/dbtests/btreetests.cpp
+++ b/dbtests/btreetests.cpp
@@ -33,8 +33,8 @@ namespace BtreeTests {
// dummy, valid record loc
const DiskLoc recordLoc() {
return DiskLoc( 0, 2 );
- }
-
+ }
+
class Ensure {
public:
Ensure() {
@@ -46,11 +46,11 @@ namespace BtreeTests {
private:
DBDirectClient _c;
};
-
+
class Base : public Ensure {
public:
- Base() :
- _context( ns() ) {
+ Base() :
+ _context( ns() ) {
{
bool f = false;
assert( f = true );
@@ -64,9 +64,9 @@ namespace BtreeTests {
string val( len, ' ' );
for( int i = 0; i < len; ++i ) {
val[ i ] = sub[ i % 16 ];
- }
+ }
return val;
- }
+ }
protected:
const BtreeBucket* bt() {
return id().head.btree();
@@ -125,7 +125,8 @@ namespace BtreeTests {
DiskLoc d;
if ( i == b->nKeys() ) {
d = b->getNextChild();
- } else {
+ }
+ else {
d = const_cast< DiskLoc& >( b->keyNode( i ).prevChildBucket );
}
assert( !d.isNull() );
@@ -140,8 +141,8 @@ namespace BtreeTests {
BSONObj key = BSON( "" << k );
// log() << "key: " << key << endl;
ASSERT( present( key, 1 ) );
- ASSERT( present( key, -1 ) );
- }
+ ASSERT( present( key, -1 ) );
+ }
private:
dblock lk_;
Client::Context _context;
@@ -206,7 +207,7 @@ namespace BtreeTests {
}
virtual void checkSplit() {
ASSERT_EQUALS( 15, child( bt(), 0 )->nKeys() );
- ASSERT_EQUALS( 4, child( bt(), 1 )->nKeys() );
+ ASSERT_EQUALS( 4, child( bt(), 1 )->nKeys() );
}
};
@@ -220,7 +221,7 @@ namespace BtreeTests {
}
virtual void checkSplit() {
ASSERT_EQUALS( 4, child( bt(), 0 )->nKeys() );
- ASSERT_EQUALS( 15, child( bt(), 1 )->nKeys() );
+ ASSERT_EQUALS( 15, child( bt(), 1 )->nKeys() );
}
};
@@ -277,7 +278,7 @@ namespace BtreeTests {
}
void insert( int i ) {
BSONObj k = key( 'b' + 2 * i );
- Base::insert( k );
+ Base::insert( k );
}
};
@@ -299,10 +300,10 @@ namespace BtreeTests {
}
void insert( int i ) {
BSONObj k = key( 'b' + 2 * i );
- Base::insert( k );
- }
+ Base::insert( k );
+ }
};
-
+
class DontReuseUnused : public Base {
public:
void run() {
@@ -321,10 +322,10 @@ namespace BtreeTests {
}
void insert( int i ) {
BSONObj k = key( 'b' + 2 * i );
- Base::insert( k );
- }
+ Base::insert( k );
+ }
};
-
+
class PackUnused : public Base {
public:
void run() {
@@ -348,8 +349,9 @@ namespace BtreeTests {
while( c->ok() ) {
if ( !c->currKeyNode().prevChildBucket.isNull() ) {
toDel.push_back( c->currKey().firstElement().valuestr() );
- } else {
- other.push_back( c->currKey().firstElement().valuestr() );
+ }
+ else {
+ other.push_back( c->currKey().firstElement().valuestr() );
}
c->advance();
}
@@ -369,21 +371,21 @@ namespace BtreeTests {
for ( long long i = 50000; i < 50100; ++i ) {
insert( i );
- }
+ }
int unused2 = 0;
ASSERT_EQUALS( 100, bt()->fullValidate( dl(), order(), &unused2, true ) );
// log() << "old unused: " << unused << ", new unused: " << unused2 << endl;
-//
+//
ASSERT( unused2 <= unused );
}
protected:
void insert( long long n ) {
string val = bigNumString( n );
BSONObj k = BSON( "a" << val );
- Base::insert( k );
- }
+ Base::insert( k );
+ }
};
class DontDropReferenceKey : public PackUnused {
@@ -393,7 +395,7 @@ namespace BtreeTests {
for ( long long i = 0; i < 80; i += 1 ) {
insert( i );
}
-
+
BSONObjBuilder start;
start.appendMinKey( "a" );
BSONObjBuilder end;
@@ -440,8 +442,8 @@ namespace BtreeTests {
}
void insert( int i ) {
BSONObj k = key( 'b' + 2 * i );
- Base::insert( k );
- }
+ Base::insert( k );
+ }
virtual int unindexKeys() = 0;
};
@@ -471,7 +473,7 @@ namespace BtreeTests {
// class MergeBucketsHead : public MergeBuckets {
// virtual BSONObj unindexKey() { return key( 'p' ); }
// };
-
+
class MergeBucketsDontReplaceHead : public Base {
public:
void run() {
@@ -494,8 +496,8 @@ namespace BtreeTests {
}
void insert( int i ) {
BSONObj k = key( 'a' + i );
- Base::insert( k );
- }
+ Base::insert( k );
+ }
};
// Tool to construct custom trees for tests.
@@ -530,7 +532,8 @@ namespace BtreeTests {
}
if ( e.fieldName() == string( "_" ) ) {
n->setNext( child );
- } else {
+ }
+ else {
n->push( BSON( "" << expectedKey( e.fieldName() ) ), child );
}
}
@@ -570,19 +573,21 @@ namespace BtreeTests {
ASSERT_EQUALS( expected, kn.key.firstElement().valuestr() );
if ( kn.prevChildBucket.isNull() ) {
ASSERT( e.type() == jstNULL );
- } else {
+ }
+ else {
ASSERT( e.type() == Object );
checkStructure( e.embeddedObject(), id, kn.prevChildBucket );
}
}
if ( n->nextChild.isNull() ) {
// maybe should allow '_' field with null value?
- ASSERT( !j.more() );
- } else {
+ ASSERT( !j.more() );
+ }
+ else {
BSONElement e = j.next();
ASSERT_EQUALS( string( "_" ), e.fieldName() );
ASSERT( e.type() == Object );
- checkStructure( e.embeddedObject(), id, n->nextChild );
+ checkStructure( e.embeddedObject(), id, n->nextChild );
}
ASSERT( !j.more() );
}
@@ -594,7 +599,7 @@ namespace BtreeTests {
bool found;
id.head.btree()->locate( id, id.head, key, Ordering::make(id.keyPattern()), pos, found, recordLoc(), direction );
return found;
- }
+ }
int headerSize() const { return BtreeBucket::headerSize(); }
int packedDataSize( int pos ) const { return BtreeBucket::packedDataSize( pos ); }
void fixParentPtrs( const DiskLoc &thisLoc ) { BtreeBucket::fixParentPtrs( thisLoc ); }
@@ -611,11 +616,11 @@ namespace BtreeTests {
* We could probably refactor the following tests, but it's easier to debug
* them in the present state.
*/
-
+
class MergeBucketsDelInternal : public Base {
public:
void run() {
- ArtificialTree::setTree( "{d:{b:{a:null},bb:null,_:{c:null}},_:{f:{e:null},_:{g:null}}}", id() );
+ ArtificialTree::setTree( "{d:{b:{a:null},bb:null,_:{c:null}},_:{f:{e:null},_:{g:null}}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 8, bt()->fullValidate( dl(), order(), 0, true ) );
@@ -633,30 +638,30 @@ namespace BtreeTests {
class MergeBucketsRightNull : public Base {
public:
void run() {
- ArtificialTree::setTree( "{d:{b:{a:null},bb:null,cc:{c:null}},_:{f:{e:null},h:{g:null}}}", id() );
+ ArtificialTree::setTree( "{d:{b:{a:null},bb:null,cc:{c:null}},_:{f:{e:null},h:{g:null}}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 10, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 7, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "bb" );
assert( unindex( k ) );
// dump();
ASSERT_EQUALS( 9, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 5, nsdetails( ns.c_str() )->stats.nrecords );
ArtificialTree::checkStructure( "{b:{a:null},cc:{c:null},d:null,f:{e:null},h:{g:null}}", id() );
- }
+ }
};
-
+
// not yet handling this case
class DontMergeSingleBucket : public Base {
public:
void run() {
- ArtificialTree::setTree( "{d:{b:{a:null},c:null}}", id() );
+ ArtificialTree::setTree( "{d:{b:{a:null},c:null}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 4, bt()->fullValidate( dl(), order(), 0, true ) );
- ASSERT_EQUALS( 3, nsdetails( ns.c_str() )->stats.nrecords );
+ ASSERT_EQUALS( 3, nsdetails( ns.c_str() )->stats.nrecords );
BSONObj k = BSON( "" << "c" );
assert( unindex( k ) );
// dump();
@@ -669,12 +674,12 @@ namespace BtreeTests {
class ParentMergeNonRightToLeft : public Base {
public:
void run() {
- ArtificialTree::setTree( "{d:{b:{a:null},bb:null,cc:{c:null}},i:{f:{e:null},h:{g:null}}}", id() );
+ ArtificialTree::setTree( "{d:{b:{a:null},bb:null,cc:{c:null}},i:{f:{e:null},h:{g:null}}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 11, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 7, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "bb" );
assert( unindex( k ) );
// dump();
@@ -682,18 +687,18 @@ namespace BtreeTests {
// child does not currently replace parent in this case
ASSERT_EQUALS( 6, nsdetails( ns.c_str() )->stats.nrecords );
ArtificialTree::checkStructure( "{i:{b:{a:null},cc:{c:null},d:null,f:{e:null},h:{g:null}}}", id() );
- }
+ }
};
class ParentMergeNonRightToRight : public Base {
public:
void run() {
- ArtificialTree::setTree( "{d:{b:{a:null},cc:{c:null}},i:{f:{e:null},ff:null,h:{g:null}}}", id() );
+ ArtificialTree::setTree( "{d:{b:{a:null},cc:{c:null}},i:{f:{e:null},ff:null,h:{g:null}}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 11, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 7, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "ff" );
assert( unindex( k ) );
// dump();
@@ -701,108 +706,108 @@ namespace BtreeTests {
// child does not currently replace parent in this case
ASSERT_EQUALS( 6, nsdetails( ns.c_str() )->stats.nrecords );
ArtificialTree::checkStructure( "{i:{b:{a:null},cc:{c:null},d:null,f:{e:null},h:{g:null}}}", id() );
- }
+ }
};
-
+
class CantMergeRightNoMerge : public Base {
public:
void run() {
- ArtificialTree::setTree( "{d:{b:{a:null},bb:null,cc:{c:null}},dd:null,_:{f:{e:null},h:{g:null}}}", id() );
+ ArtificialTree::setTree( "{d:{b:{a:null},bb:null,cc:{c:null}},dd:null,_:{f:{e:null},h:{g:null}}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 11, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 7, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "bb" );
assert( unindex( k ) );
// dump();
ASSERT_EQUALS( 10, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 7, nsdetails( ns.c_str() )->stats.nrecords );
ArtificialTree::checkStructure( "{d:{b:{a:null},cc:{c:null}},dd:null,_:{f:{e:null},h:{g:null}}}", id() );
- }
+ }
};
class CantMergeLeftNoMerge : public Base {
public:
void run() {
- ArtificialTree::setTree( "{c:{b:{a:null}},d:null,_:{f:{e:null},g:null}}", id() );
+ ArtificialTree::setTree( "{c:{b:{a:null}},d:null,_:{f:{e:null},g:null}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 7, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 5, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "g" );
assert( unindex( k ) );
// dump();
ASSERT_EQUALS( 6, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 5, nsdetails( ns.c_str() )->stats.nrecords );
ArtificialTree::checkStructure( "{c:{b:{a:null}},d:null,_:{f:{e:null}}}", id() );
- }
+ }
};
class MergeOption : public Base {
public:
void run() {
- ArtificialTree::setTree( "{c:{b:{a:null}},f:{e:{d:null},ee:null},_:{h:{g:null}}}", id() );
+ ArtificialTree::setTree( "{c:{b:{a:null}},f:{e:{d:null},ee:null},_:{h:{g:null}}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 9, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 7, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "ee" );
assert( unindex( k ) );
// dump();
ASSERT_EQUALS( 8, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 6, nsdetails( ns.c_str() )->stats.nrecords );
ArtificialTree::checkStructure( "{c:{b:{a:null}},_:{e:{d:null},f:null,h:{g:null}}}", id() );
- }
+ }
};
class ForceMergeLeft : public Base {
public:
void run() {
- ArtificialTree::setTree( "{c:{b:{a:null}},f:{e:{d:null},ee:null},ff:null,_:{h:{g:null}}}", id() );
+ ArtificialTree::setTree( "{c:{b:{a:null}},f:{e:{d:null},ee:null},ff:null,_:{h:{g:null}}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 10, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 7, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "ee" );
assert( unindex( k ) );
// dump();
ASSERT_EQUALS( 9, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 6, nsdetails( ns.c_str() )->stats.nrecords );
ArtificialTree::checkStructure( "{f:{b:{a:null},c:null,e:{d:null}},ff:null,_:{h:{g:null}}}", id() );
- }
- };
+ }
+ };
class ForceMergeRight : public Base {
public:
void run() {
- ArtificialTree::setTree( "{c:{b:{a:null}},cc:null,f:{e:{d:null},ee:null},_:{h:{g:null}}}", id() );
+ ArtificialTree::setTree( "{c:{b:{a:null}},cc:null,f:{e:{d:null},ee:null},_:{h:{g:null}}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 10, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 7, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "ee" );
assert( unindex( k ) );
// dump();
ASSERT_EQUALS( 9, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 6, nsdetails( ns.c_str() )->stats.nrecords );
ArtificialTree::checkStructure( "{c:{b:{a:null}},cc:null,_:{e:{d:null},f:null,h:{g:null}}}", id() );
- }
- };
-
+ }
+ };
+
class RecursiveMerge : public Base {
public:
void run() {
- ArtificialTree::setTree( "{h:{e:{b:{a:null},c:null,d:null},g:{f:null}},j:{i:null}}", id() );
+ ArtificialTree::setTree( "{h:{e:{b:{a:null},c:null,d:null},g:{f:null}},j:{i:null}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 10, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 6, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "c" );
assert( unindex( k ) );
// dump();
@@ -810,36 +815,36 @@ namespace BtreeTests {
ASSERT_EQUALS( 4, nsdetails( ns.c_str() )->stats.nrecords );
// height is not currently reduced in this case
ArtificialTree::checkStructure( "{j:{g:{b:{a:null},d:null,e:null,f:null},h:null,i:null}}", id() );
- }
+ }
};
-
+
class RecursiveMergeRightBucket : public Base {
public:
void run() {
- ArtificialTree::setTree( "{h:{e:{b:{a:null},c:null,d:null},g:{f:null}},_:{i:null}}", id() );
+ ArtificialTree::setTree( "{h:{e:{b:{a:null},c:null,d:null},g:{f:null}},_:{i:null}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 9, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 6, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "c" );
assert( unindex( k ) );
// dump();
ASSERT_EQUALS( 8, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 3, nsdetails( ns.c_str() )->stats.nrecords );
ArtificialTree::checkStructure( "{g:{b:{a:null},d:null,e:null,f:null},h:null,i:null}", id() );
- }
+ }
};
class RecursiveMergeDoubleRightBucket : public Base {
public:
void run() {
- ArtificialTree::setTree( "{h:{e:{b:{a:null},c:null,d:null},_:{f:null}},_:{i:null}}", id() );
+ ArtificialTree::setTree( "{h:{e:{b:{a:null},c:null,d:null},_:{f:null}},_:{i:null}}", id() );
// dump();
string ns = id().indexNamespace();
ASSERT_EQUALS( 8, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 6, nsdetails( ns.c_str() )->stats.nrecords );
-
+
BSONObj k = BSON( "" << "c" );
assert( unindex( k ) );
// dump();
@@ -847,9 +852,9 @@ namespace BtreeTests {
ASSERT_EQUALS( 4, nsdetails( ns.c_str() )->stats.nrecords );
// no recursion currently in this case
ArtificialTree::checkStructure( "{h:{b:{a:null},d:null,e:null,f:null},_:{i:null}}", id() );
- }
+ }
};
-
+
class MergeSizeBase : public Base {
public:
MergeSizeBase() : _count() {}
@@ -866,7 +871,7 @@ namespace BtreeTests {
root->setNext( right );
A* r = A::is( right );
root->fixParentPtrs( dl() );
-
+
ASSERT_EQUALS( bigSize(), bigSize() / 2 * 2 );
fillToExactSize( l, leftSize(), 'a' );
fillToExactSize( r, rightSize(), 'n' );
@@ -887,7 +892,7 @@ namespace BtreeTests {
_count += leftAdditional() + rightAdditional();
// dump();
-
+
initCheck();
string ns = id().indexNamespace();
const char *keys = delKeys();
@@ -901,18 +906,19 @@ namespace BtreeTests {
// dump();
--_count;
}
-
+
// dump();
-
+
int unused = 0;
ASSERT_EQUALS( _count, bt()->fullValidate( dl(), order(), &unused, true ) );
ASSERT_EQUALS( 0, unused );
validate();
if ( !merge() ) {
- ASSERT_EQUALS( 3, nsdetails( ns.c_str() )->stats.nrecords );
- } else {
- ASSERT_EQUALS( 1, nsdetails( ns.c_str() )->stats.nrecords );
- }
+ ASSERT_EQUALS( 3, nsdetails( ns.c_str() )->stats.nrecords );
+ }
+ else {
+ ASSERT_EQUALS( 1, nsdetails( ns.c_str() )->stats.nrecords );
+ }
}
protected:
virtual int leftAdditional() const { return 2; }
@@ -957,7 +963,7 @@ namespace BtreeTests {
}
int _count;
};
-
+
class MergeSizeJustRightRight : public MergeSizeBase {
protected:
virtual int rightSize() const { return BtreeBucket::getLowWaterMark() - 1; }
@@ -975,12 +981,12 @@ namespace BtreeTests {
virtual int rightSize() const { return MergeSizeJustRightRight::rightSize() - 1; }
virtual int leftSize() const { return MergeSizeJustRightRight::leftSize() + 1; }
};
-
+
class MergeSizeLeft : public MergeSizeJustRightLeft {
virtual int rightSize() const { return MergeSizeJustRightLeft::rightSize() + 1; }
virtual int leftSize() const { return MergeSizeJustRightLeft::leftSize() - 1; }
- };
-
+ };
+
class NoMergeBelowMarkRight : public MergeSizeJustRightRight {
virtual int rightSize() const { return MergeSizeJustRightRight::rightSize() + 1; }
virtual int leftSize() const { return MergeSizeJustRightRight::leftSize() - 1; }
@@ -992,7 +998,7 @@ namespace BtreeTests {
virtual int leftSize() const { return MergeSizeJustRightLeft::leftSize() + 1; }
virtual bool merge() const { return false; }
};
-
+
class MergeSizeRightTooBig : public MergeSizeJustRightLeft {
virtual int rightSize() const { return MergeSizeJustRightLeft::rightSize() + 1; }
virtual bool merge() const { return false; }
@@ -1002,7 +1008,7 @@ namespace BtreeTests {
virtual int leftSize() const { return MergeSizeJustRightRight::leftSize() + 1; }
virtual bool merge() const { return false; }
};
-
+
class BalanceOneLeftToRight : public Base {
public:
void run() {
@@ -1016,7 +1022,7 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 13, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 4, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$6:{$1:null,$2:null,$3:null,$4:null,$5:null},b:{$10:null,$20:null,$30:null,$50:null,a:null},_:{c:null}}", id() );
+ ArtificialTree::checkStructure( "{$6:{$1:null,$2:null,$3:null,$4:null,$5:null},b:{$10:null,$20:null,$30:null,$50:null,a:null},_:{c:null}}", id() );
}
};
@@ -1033,7 +1039,7 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 12, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 4, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$20:{$1:null,$2:null,$4:null,$10:null},b:{$30:null,$40:null,$50:null,$60:null,$70:null},_:{c:null}}", id() );
+ ArtificialTree::checkStructure( "{$20:{$1:null,$2:null,$4:null,$10:null},b:{$30:null,$40:null,$50:null,$60:null,$70:null},_:{c:null}}", id() );
}
};
@@ -1050,7 +1056,7 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 22, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 14, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$9:{$1:{$0:null},$3:{$2:null},$5:{$4:null},$7:{$6:null},_:{$8:null}},b:{$11:{$10:null},$13:{$12:null},$20:{$14:null},$40:{$35:null},$50:{$45:null}},_:{c:null}}", id() );
+ ArtificialTree::checkStructure( "{$9:{$1:{$0:null},$3:{$2:null},$5:{$4:null},$7:{$6:null},_:{$8:null}},b:{$11:{$10:null},$13:{$12:null},$20:{$14:null},$40:{$35:null},$50:{$45:null}},_:{c:null}}", id() );
}
};
@@ -1067,7 +1073,7 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 24, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 15, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$50:{$1:{$0:null},$3:{$2:null},$20:{$14:null},$30:{$25:null},$40:{$35:null},_:{$45:null}},b:{$60:{$55:null},$70:{$65:null},$80:{$75:null},$90:{$85:null},$100:{$95:null}},_:{c:null}}", id() );
+ ArtificialTree::checkStructure( "{$50:{$1:{$0:null},$3:{$2:null},$20:{$14:null},$30:{$25:null},$40:{$35:null},_:{$45:null}},b:{$60:{$55:null},$70:{$65:null},$80:{$75:null},$90:{$85:null},$100:{$95:null}},_:{c:null}}", id() );
}
};
@@ -1084,8 +1090,8 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 11, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 3, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$6:{$1:null,$2:null,$3:null,$4:null,$5:null},_:{$10:null,$20:null,$30:null,$50:null,a:null}}", id() );
- }
+ ArtificialTree::checkStructure( "{$6:{$1:null,$2:null,$3:null,$4:null,$5:null},_:{$10:null,$20:null,$30:null,$50:null,a:null}}", id() );
+ }
};
class PackEmpty : public Base {
@@ -1115,7 +1121,7 @@ namespace BtreeTests {
}
};
};
-
+
class PackedDataSizeEmpty : public Base {
public:
void run() {
@@ -1137,9 +1143,9 @@ namespace BtreeTests {
ASSERT_EQUALS( 0, t->packedDataSize( zero ) );
ASSERT( !( t->flags & Packed ) );
}
- };
+ };
};
-
+
class BalanceSingleParentKeyPackParent : public Base {
public:
void run() {
@@ -1155,8 +1161,8 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 11, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 3, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$6:{$1:null,$2:null,$3:null,$4:null,$5:null},_:{$10:null,$20:null,$30:null,$50:null,a:null}}", id() );
- }
+ ArtificialTree::checkStructure( "{$6:{$1:null,$2:null,$3:null,$4:null,$5:null},_:{$10:null,$20:null,$30:null,$50:null,a:null}}", id() );
+ }
};
class BalanceSplitParent : public Base {
@@ -1172,8 +1178,8 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 21, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 6, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$500:{$30:{$1:null,$2:null,$4:null,$10$10:null,$20:null},$100:{$40:null,$50:null,$60:null,$70:null,$80:null},$200:null,$300:null,$400:null},_:{$600:null,$700:null,$800:null,$900:null,_:{c:null}}}", id() );
- }
+ ArtificialTree::checkStructure( "{$500:{$30:{$1:null,$2:null,$4:null,$10$10:null,$20:null},$100:{$40:null,$50:null,$60:null,$70:null,$80:null},$200:null,$300:null,$400:null},_:{$600:null,$700:null,$800:null,$900:null,_:{c:null}}}", id() );
+ }
};
class RebalancedSeparatorBase : public Base {
@@ -1192,7 +1198,7 @@ namespace BtreeTests {
}
};
};
-
+
class EvenRebalanceLeft : public RebalancedSeparatorBase {
virtual string treeSpec() const { return "{$7:{$1:null,$2$31f:null,$3:null,$4$31f:null,$5:null,$6:null},_:{$8:null,$9:null,$10$31e:null}}"; }
virtual int expectedSeparator() const { return 4; }
@@ -1202,7 +1208,7 @@ namespace BtreeTests {
virtual string treeSpec() const { return "{$6:{$1:null,$2$31f:null,$3:null,$4$31f:null,$5:null},_:{$7:null,$8:null,$9$31e:null,$10:null}}"; }
virtual int expectedSeparator() const { return 4; }
};
-
+
class EvenRebalanceRight : public RebalancedSeparatorBase {
virtual string treeSpec() const { return "{$3:{$1:null,$2$31f:null},_:{$4$31f:null,$5:null,$6:null,$7:null,$8$31e:null,$9:null,$10:null}}"; }
virtual int expectedSeparator() const { return 4; }
@@ -1212,12 +1218,12 @@ namespace BtreeTests {
virtual string treeSpec() const { return "{$4$31f:{$1:null,$2$31f:null,$3:null},_:{$5:null,$6:null,$7$31e:null,$8:null,$9:null,$10:null}}"; }
virtual int expectedSeparator() const { return 4; }
};
-
+
class EvenRebalanceCenter : public RebalancedSeparatorBase {
virtual string treeSpec() const { return "{$5:{$1:null,$2$31f:null,$3:null,$4$31f:null},_:{$6:null,$7$31e:null,$8:null,$9:null,$10:null}}"; }
- virtual int expectedSeparator() const { return 4; }
+ virtual int expectedSeparator() const { return 4; }
};
-
+
class OddRebalanceLeft : public RebalancedSeparatorBase {
virtual string treeSpec() const { return "{$6$31f:{$1:null,$2:null,$3:null,$4:null,$5:null},_:{$7:null,$8:null,$9:null,$10:null}}"; }
virtual int expectedSeparator() const { return 4; }
@@ -1232,7 +1238,7 @@ namespace BtreeTests {
virtual string treeSpec() const { return "{$5:{$1:null,$2:null,$3:null,$4:null},_:{$6:null,$7:null,$8:null,$9:null,$10$31f:null}}"; }
virtual int expectedSeparator() const { return 4; }
};
-
+
class RebalanceEmptyRight : public RebalancedSeparatorBase {
virtual string treeSpec() const { return "{$a:{$1:null,$2:null,$3:null,$4:null,$5:null,$6:null,$7:null,$8:null,$9:null},_:{$b:null}}"; }
virtual void modTree() {
@@ -1250,7 +1256,7 @@ namespace BtreeTests {
}
virtual int expectedSeparator() const { return 4; }
};
-
+
class NoMoveAtLowWaterMarkRight : public MergeSizeJustRightRight {
virtual int rightSize() const { return MergeSizeJustRightRight::rightSize() + 1; }
virtual void initCheck() { _oldTop = bt()->keyNode( 0 ).key; }
@@ -1275,14 +1281,14 @@ namespace BtreeTests {
protected:
BSONObj _oldTop;
};
-
+
class MoveBelowLowWaterMarkLeft : public NoMoveAtLowWaterMarkLeft {
virtual int leftSize() const { return MergeSizeJustRightLeft::leftSize(); }
virtual int rightSize() const { return MergeSizeJustRightLeft::rightSize() + 1; }
// different top means we rebalanced
virtual void validate() { ASSERT( !( _oldTop == bt()->keyNode( 0 ).key ) ); }
};
-
+
class PreferBalanceLeft : public Base {
public:
void run() {
@@ -1296,8 +1302,8 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 12, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 4, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$5:{$1:null,$2:null,$3:null,$4:null},$20:{$6:null,$10:null,$11:null,$13:null,$14:null},_:{$30:null}}", id() );
- }
+ ArtificialTree::checkStructure( "{$5:{$1:null,$2:null,$3:null,$4:null},$20:{$6:null,$10:null,$11:null,$13:null,$14:null},_:{$30:null}}", id() );
+ }
};
class PreferBalanceRight : public Base {
@@ -1313,8 +1319,8 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 12, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 4, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$10:{$1:null},$31:{$11:null,$13:null,$14:null,$20:null},_:{$32:null,$33:null,$34:null,$35:null,$36:null}}", id() );
- }
+ ArtificialTree::checkStructure( "{$10:{$1:null},$31:{$11:null,$13:null,$14:null,$20:null},_:{$32:null,$33:null,$34:null,$35:null,$36:null}}", id() );
+ }
};
class RecursiveMergeThenBalance : public Base {
@@ -1330,10 +1336,10 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 14, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 4, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$40:{$8:{$1:null,$2:null,$5:null,$6:null},$10:null,$20:null,$30:null},_:{$50:null,$60:null,$70:null,$80:null,$90:null}}", id() );
+ ArtificialTree::checkStructure( "{$40:{$8:{$1:null,$2:null,$5:null,$6:null},$10:null,$20:null,$30:null},_:{$50:null,$60:null,$70:null,$80:null,$90:null}}", id() );
}
};
-
+
class MergeRightEmpty : public MergeSizeBase {
protected:
virtual int rightAdditional() const { return 1; }
@@ -1341,7 +1347,7 @@ namespace BtreeTests {
virtual const char * delKeys() const { return "lz"; }
virtual int rightSize() const { return 0; }
virtual int leftSize() const { return BtreeBucket::bodySize() - biggestSize() - sizeof( _KeyNode ); }
- };
+ };
class MergeMinRightEmpty : public MergeSizeBase {
protected:
@@ -1350,8 +1356,8 @@ namespace BtreeTests {
virtual const char * delKeys() const { return "z"; }
virtual int rightSize() const { return 0; }
virtual int leftSize() const { return bigSize() + sizeof( _KeyNode ); }
- };
-
+ };
+
class MergeLeftEmpty : public MergeSizeBase {
protected:
virtual int rightAdditional() const { return 1; }
@@ -1359,7 +1365,7 @@ namespace BtreeTests {
virtual const char * delKeys() const { return "zl"; }
virtual int leftSize() const { return 0; }
virtual int rightSize() const { return BtreeBucket::bodySize() - biggestSize() - sizeof( _KeyNode ); }
- };
+ };
class MergeMinLeftEmpty : public MergeSizeBase {
protected:
@@ -1368,8 +1374,8 @@ namespace BtreeTests {
virtual const char * delKeys() const { return "l"; }
virtual int leftSize() const { return 0; }
virtual int rightSize() const { return bigSize() + sizeof( _KeyNode ); }
- };
-
+ };
+
class BalanceRightEmpty : public MergeRightEmpty {
protected:
virtual int leftSize() const { return BtreeBucket::bodySize() - biggestSize() - sizeof( _KeyNode ) + 1; }
@@ -1403,7 +1409,7 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 1, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 1, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{b:null}", id() );
+ ArtificialTree::checkStructure( "{b:null}", id() );
}
};
@@ -1420,10 +1426,10 @@ namespace BtreeTests {
// dump();
ASSERT_EQUALS( 3, bt()->fullValidate( dl(), order(), 0, true ) );
ASSERT_EQUALS( 1, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{a:null,c:null,d:null}", id() );
+ ArtificialTree::checkStructure( "{a:null,c:null,d:null}", id() );
}
};
-
+
class DelInternal : public Base {
public:
void run() {
@@ -1440,10 +1446,10 @@ namespace BtreeTests {
ASSERT_EQUALS( 3, bt()->fullValidate( dl(), order(), &unused, true ) );
ASSERT_EQUALS( 0, unused );
ASSERT_EQUALS( 1, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{a:null,b:null,d:null}", id() );
+ ArtificialTree::checkStructure( "{a:null,b:null,d:null}", id() );
}
};
-
+
class DelInternalReplaceWithUnused : public Base {
public:
void run() {
@@ -1463,10 +1469,10 @@ namespace BtreeTests {
ASSERT_EQUALS( 1, unused );
ASSERT_EQUALS( 1, nsdetails( ns.c_str() )->stats.nrecords );
// doesn't discriminate between used and unused
- ArtificialTree::checkStructure( "{a:null,b:null,d:null}", id() );
+ ArtificialTree::checkStructure( "{a:null,b:null,d:null}", id() );
}
};
-
+
class DelInternalReplaceRight : public Base {
public:
void run() {
@@ -1484,10 +1490,10 @@ namespace BtreeTests {
ASSERT_EQUALS( 1, bt()->fullValidate( dl(), order(), &unused, true ) );
ASSERT_EQUALS( 0, unused );
ASSERT_EQUALS( 1, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{b:null}", id() );
+ ArtificialTree::checkStructure( "{b:null}", id() );
}
};
-
+
class DelInternalPromoteKey : public Base {
public:
void run() {
@@ -1505,7 +1511,7 @@ namespace BtreeTests {
ASSERT_EQUALS( 6, bt()->fullValidate( dl(), order(), &unused, true ) );
ASSERT_EQUALS( 0, unused );
ASSERT_EQUALS( 3, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{a:null,e:{c:{b:null},d:null},z:null}", id() );
+ ArtificialTree::checkStructure( "{a:null,e:{c:{b:null},d:null},z:null}", id() );
}
};
@@ -1526,10 +1532,10 @@ namespace BtreeTests {
ASSERT_EQUALS( 3, bt()->fullValidate( dl(), order(), &unused, true ) );
ASSERT_EQUALS( 0, unused );
ASSERT_EQUALS( 2, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{c:null,_:{e:null,f:null}}", id() );
+ ArtificialTree::checkStructure( "{c:null,_:{e:null,f:null}}", id() );
}
};
-
+
class DelInternalReplacementPrevNonNull : public Base {
public:
void run() {
@@ -1546,10 +1552,10 @@ namespace BtreeTests {
ASSERT_EQUALS( 4, bt()->fullValidate( dl(), order(), &unused, true ) );
ASSERT_EQUALS( 1, unused );
ASSERT_EQUALS( 3, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{a:null,d:{c:{b:null}},e:null}", id() );
+ ArtificialTree::checkStructure( "{a:null,d:{c:{b:null}},e:null}", id() );
ASSERT( bt()->keyNode( 1 ).recordLoc.getOfs() & 1 ); // check 'unused' key
}
- };
+ };
class DelInternalReplacementNextNonNull : public Base {
public:
@@ -1567,11 +1573,11 @@ namespace BtreeTests {
ASSERT_EQUALS( 2, bt()->fullValidate( dl(), order(), &unused, true ) );
ASSERT_EQUALS( 1, unused );
ASSERT_EQUALS( 3, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{a:null,_:{c:null,_:{d:null}}}", id() );
+ ArtificialTree::checkStructure( "{a:null,_:{c:null,_:{d:null}}}", id() );
ASSERT( bt()->keyNode( 0 ).recordLoc.getOfs() & 1 ); // check 'unused' key
}
};
-
+
class DelInternalSplitPromoteLeft : public Base {
public:
void run() {
@@ -1588,7 +1594,7 @@ namespace BtreeTests {
ASSERT_EQUALS( 12, bt()->fullValidate( dl(), order(), &unused, true ) );
ASSERT_EQUALS( 0, unused );
ASSERT_EQUALS( 4, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$60:{$10:null,$20:null,$27:{$23:null,$25:null},$40:null,$50:null},_:{$70:null,$80:null,$90:null,$100:null}}", id() );
+ ArtificialTree::checkStructure( "{$60:{$10:null,$20:null,$27:{$23:null,$25:null},$40:null,$50:null},_:{$70:null,$80:null,$90:null,$100:null}}", id() );
}
};
@@ -1608,16 +1614,16 @@ namespace BtreeTests {
ASSERT_EQUALS( 12, bt()->fullValidate( dl(), order(), &unused, true ) );
ASSERT_EQUALS( 0, unused );
ASSERT_EQUALS( 4, nsdetails( ns.c_str() )->stats.nrecords );
- ArtificialTree::checkStructure( "{$80:{$10:null,$20:null,$30:null,$40:null,$50:null,$60:null,$70:null},_:{$90:null,$97:{$93:null,$95:null}}}", id() );
+ ArtificialTree::checkStructure( "{$80:{$10:null,$20:null,$30:null,$40:null,$50:null,$60:null,$70:null},_:{$90:null,$97:{$93:null,$95:null}}}", id() );
}
};
-
+
class All : public Suite {
public:
- All() : Suite( "btree" ){
+ All() : Suite( "btree" ) {
}
-
- void setupTests(){
+
+ void setupTests() {
add< Create >();
add< SimpleInsertDelete >();
add< SplitRightHeavyBucket >();
diff --git a/dbtests/clienttests.cpp b/dbtests/clienttests.cpp
index 58287e90bde..317aad92365 100644
--- a/dbtests/clienttests.cpp
+++ b/dbtests/clienttests.cpp
@@ -20,40 +20,40 @@
#include "../client/dbclient.h"
#include "dbtests.h"
#include "../db/concurrency.h"
-
+
namespace ClientTests {
-
+
class Base {
public:
-
- Base( string coll ){
+
+ Base( string coll ) {
_ns = (string)"test." + coll;
}
-
- virtual ~Base(){
+
+ virtual ~Base() {
db.dropCollection( _ns );
}
-
- const char * ns(){ return _ns.c_str(); }
-
+
+ const char * ns() { return _ns.c_str(); }
+
string _ns;
DBDirectClient db;
};
-
+
class DropIndex : public Base {
public:
- DropIndex() : Base( "dropindex" ){}
- void run(){
+ DropIndex() : Base( "dropindex" ) {}
+ void run() {
db.insert( ns() , BSON( "x" << 2 ) );
ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
-
+
db.ensureIndex( ns() , BSON( "x" << 1 ) );
ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
-
+
db.dropIndex( ns() , BSON( "x" << 1 ) );
ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
-
+
db.ensureIndex( ns() , BSON( "x" << 1 ) );
ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
@@ -61,18 +61,18 @@ namespace ClientTests {
ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
}
};
-
+
class ReIndex : public Base {
public:
- ReIndex() : Base( "reindex" ){}
- void run(){
-
+ ReIndex() : Base( "reindex" ) {}
+ void run() {
+
db.insert( ns() , BSON( "x" << 2 ) );
ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
-
+
db.ensureIndex( ns() , BSON( "x" << 1 ) );
ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
-
+
db.reIndex( ns() );
ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
}
@@ -81,15 +81,15 @@ namespace ClientTests {
class ReIndex2 : public Base {
public:
- ReIndex2() : Base( "reindex2" ){}
- void run(){
-
+ ReIndex2() : Base( "reindex2" ) {}
+ void run() {
+
db.insert( ns() , BSON( "x" << 2 ) );
ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
-
+
db.ensureIndex( ns() , BSON( "x" << 1 ) );
ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
-
+
BSONObj out;
ASSERT( db.runCommand( "test" , BSON( "reIndex" << "reindex2" ) , out ) );
ASSERT_EQUALS( 2 , out["nIndexes"].number() );
@@ -106,7 +106,7 @@ namespace ClientTests {
for( int i = 0; i < 1111; ++i )
db.insert( ns(), BSON( "a" << i << "b" << longs ) );
db.ensureIndex( ns(), BSON( "a" << 1 << "b" << 1 ) );
-
+
auto_ptr< DBClientCursor > c = db.query( ns(), Query().sort( BSON( "a" << 1 << "b" << 1 ) ) );
ASSERT_EQUALS( 1111, c->itcount() );
}
@@ -164,10 +164,10 @@ namespace ClientTests {
class All : public Suite {
public:
- All() : Suite( "client" ){
+ All() : Suite( "client" ) {
}
- void setupTests(){
+ void setupTests() {
add<DropIndex>();
add<ReIndex>();
add<ReIndex2>();
@@ -175,6 +175,6 @@ namespace ClientTests {
add<PushBack>();
add<Create>();
}
-
+
} all;
}
diff --git a/dbtests/commandtests.cpp b/dbtests/commandtests.cpp
index fa0014dae1b..fa6204d25fd 100644
--- a/dbtests/commandtests.cpp
+++ b/dbtests/commandtests.cpp
@@ -23,19 +23,19 @@ using namespace mongo;
namespace CommandTests {
// one namespace per command
- namespace FileMD5{
+ namespace FileMD5 {
struct Base {
- Base(){
+ Base() {
db.dropCollection(ns());
db.ensureIndex(ns(), BSON( "files_id" << 1 << "n" << 1 ));
}
const char* ns() { return "test.fs.chunks"; }
-
+
DBDirectClient db;
};
struct Type0 : Base {
- void run(){
+ void run() {
{
BSONObjBuilder b;
b.genOID();
@@ -58,8 +58,8 @@ namespace CommandTests {
ASSERT_EQUALS( string("5eb63bbbe01eeed093cb22bb8f5acdc3") , result["md5"].valuestr() );
}
};
- struct Type2 : Base{
- void run(){
+ struct Type2 : Base {
+ void run() {
{
BSONObjBuilder b;
b.genOID();
@@ -86,13 +86,13 @@ namespace CommandTests {
class All : public Suite {
public:
- All() : Suite( "commands" ){
+ All() : Suite( "commands" ) {
}
- void setupTests(){
+ void setupTests() {
add< FileMD5::Type0 >();
add< FileMD5::Type2 >();
}
-
+
} all;
}
diff --git a/dbtests/cursortests.cpp b/dbtests/cursortests.cpp
index 954c8b01a1a..ddd7b03b9b3 100644
--- a/dbtests/cursortests.cpp
+++ b/dbtests/cursortests.cpp
@@ -25,12 +25,12 @@
#include "dbtests.h"
namespace CursorTests {
-
+
namespace BtreeCursorTests {
// The ranges expressed in these tests are impossible given our query
// syntax, so going to do them a hacky way.
-
+
class Base {
protected:
FieldRangeVector *vec( int *vals, int len, int direction = 1 ) {
@@ -40,7 +40,8 @@ namespace CursorTests {
FieldRangeSet s2( "", _objs.back() );
if ( i == 0 ) {
s.range( "a" ) = s2.range( "a" );
- } else {
+ }
+ else {
s.range( "a" ) |= s2.range( "a" );
}
}
@@ -49,7 +50,7 @@ namespace CursorTests {
private:
vector< BSONObj > _objs;
};
-
+
class MultiRange : public Base {
public:
void run() {
@@ -103,7 +104,7 @@ namespace CursorTests {
ASSERT( !c.ok() );
}
};
-
+
class MultiRangeReverse : public Base {
public:
void run() {
@@ -129,7 +130,7 @@ namespace CursorTests {
ASSERT( !c.ok() );
}
};
-
+
class Base2 {
public:
virtual ~Base2() { _c.dropCollection( ns() ); }
@@ -167,7 +168,7 @@ namespace CursorTests {
dblock _lk;
vector< BSONObj > _objs;
};
-
+
class EqEq : public Base2 {
public:
void run() {
@@ -194,7 +195,7 @@ namespace CursorTests {
check( BSON( "a" << 4 << "b" << BSON( "$gte" << 1 << "$lte" << 10 ) ) );
}
virtual BSONObj idx() const { return BSON( "a" << 1 << "b" << 1 ); }
- };
+ };
class EqIn : public Base2 {
public:
@@ -210,7 +211,7 @@ namespace CursorTests {
check( BSON( "a" << 4 << "b" << BSON( "$in" << BSON_ARRAY( 5 << 6 << 11 ) ) ) );
}
virtual BSONObj idx() const { return BSON( "a" << 1 << "b" << 1 ); }
- };
+ };
class RangeEq : public Base2 {
public:
@@ -227,7 +228,7 @@ namespace CursorTests {
check( BSON( "a" << BSON( "$gte" << 1 << "$lte" << 10 ) << "b" << 4 ) );
}
virtual BSONObj idx() const { return BSON( "a" << 1 << "b" << 1 ); }
- };
+ };
class RangeIn : public Base2 {
public:
@@ -244,15 +245,15 @@ namespace CursorTests {
check( BSON( "a" << BSON( "$gte" << 1 << "$lte" << 10 ) << "b" << BSON( "$in" << BSON_ARRAY( 4 << 6 ) ) ) );
}
virtual BSONObj idx() const { return BSON( "a" << 1 << "b" << 1 ); }
- };
-
+ };
+
} // namespace BtreeCursorTests
-
+
class All : public Suite {
public:
- All() : Suite( "cursor" ){}
-
- void setupTests(){
+ All() : Suite( "cursor" ) {}
+
+ void setupTests() {
add< BtreeCursorTests::MultiRange >();
add< BtreeCursorTests::MultiRangeGap >();
add< BtreeCursorTests::MultiRangeReverse >();
diff --git a/dbtests/d_chunk_manager_tests.cpp b/dbtests/d_chunk_manager_tests.cpp
index 5794d629d61..bcfe9fa9ec1 100644
--- a/dbtests/d_chunk_manager_tests.cpp
+++ b/dbtests/d_chunk_manager_tests.cpp
@@ -32,13 +32,13 @@ namespace {
"unique" << false );
// single-chunk collection
- BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKey" <<
- "ns" << "test.foo" <<
+ BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKey" <<
+ "ns" << "test.foo" <<
"min" << BSON( "a" << MINKEY ) <<
"max" << BSON( "a" << MAXKEY ) ) );
ShardChunkManager s ( collection , chunks );
-
+
BSONObj k1 = BSON( "a" << MINKEY );
ASSERT( s.belongsToMe( k1 ) );
BSONObj k2 = BSON( "a" << MAXKEY );
@@ -57,13 +57,13 @@ namespace {
"unique" << false );
// single-chunk collection
- BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKeyb_MinKey" <<
- "ns" << "test.foo" <<
+ BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKeyb_MinKey" <<
+ "ns" << "test.foo" <<
"min" << BSON( "a" << MINKEY << "b" << MINKEY ) <<
"max" << BSON( "a" << MAXKEY << "b" << MAXKEY ) ) );
ShardChunkManager s ( collection , chunks );
-
+
BSONObj k1 = BSON( "a" << MINKEY << "b" << MINKEY );
ASSERT( s.belongsToMe( k1 ) );
BSONObj k2 = BSON( "a" << MAXKEY << "b" << MAXKEY );
@@ -71,13 +71,13 @@ namespace {
BSONObj k3 = BSON( "a" << MINKEY << "b" << 10 );
ASSERT( s.belongsToMe( k3 ) );
BSONObj k4 = BSON( "a" << 10 << "b" << 20 );
- ASSERT( s.belongsToMe( k4 ) );
+ ASSERT( s.belongsToMe( k4 ) );
}
};
- class RangeTests {
+ class RangeTests {
public:
- void run() {
+ void run() {
BSONObj collection = BSON( "_id" << "x.y" <<
"dropped" << false <<
"key" << BSON( "a" << 1 ) <<
@@ -85,23 +85,23 @@ namespace {
// 3-chunk collection, 2 of them being contiguous
// [min->10) , [10->20) , <gap> , [30->max)
- BSONArray chunks = BSON_ARRAY( BSON( "_id" << "x.y-a_MinKey" <<
- "ns" << "x.y" <<
- "min" << BSON( "a" << MINKEY ) <<
+ BSONArray chunks = BSON_ARRAY( BSON( "_id" << "x.y-a_MinKey" <<
+ "ns" << "x.y" <<
+ "min" << BSON( "a" << MINKEY ) <<
"max" << BSON( "a" << 10 ) ) <<
- BSON( "_id" << "x.y-a_10" <<
- "ns" << "x.y" <<
- "min" << BSON( "a" << 10 ) <<
+ BSON( "_id" << "x.y-a_10" <<
+ "ns" << "x.y" <<
+ "min" << BSON( "a" << 10 ) <<
"max" << BSON( "a" << 20 ) ) <<
- BSON( "_id" << "x.y-a_30" <<
- "ns" << "x.y" <<
- "min" << BSON( "a" << 30 ) <<
+ BSON( "_id" << "x.y-a_30" <<
+ "ns" << "x.y" <<
+ "min" << BSON( "a" << 30 ) <<
"max" << BSON( "a" << MAXKEY ) ) );
ShardChunkManager s ( collection , chunks );
BSONObj k1 = BSON( "a" << 5 );
- ASSERT( s.belongsToMe( k1 ) );
+ ASSERT( s.belongsToMe( k1 ) );
BSONObj k2 = BSON( "a" << 10 );
ASSERT( s.belongsToMe( k2 ) );
BSONObj k3 = BSON( "a" << 25 );
@@ -113,10 +113,10 @@ namespace {
}
};
- class GetNextTests {
+ class GetNextTests {
public:
- void run() {
-
+ void run() {
+
BSONObj collection = BSON( "_id" << "x.y" <<
"dropped" << false <<
"key" << BSON( "a" << 1 ) <<
@@ -140,9 +140,9 @@ namespace {
// [10->20]
BSONObj key_a10 = BSON( "a" << 10 );
BSONObj key_a20 = BSON( "a" << 20 );
- BSONArray chunks2 = BSON_ARRAY( BSON( "_id" << "x.y-a_10" <<
- "ns" << "x.y" <<
- "min" << key_a10 <<
+ BSONArray chunks2 = BSON_ARRAY( BSON( "_id" << "x.y-a_10" <<
+ "ns" << "x.y" <<
+ "min" << key_a10 <<
"max" << key_a20 ) );
ShardChunkManager s2( collection , chunks2 );
ASSERT( s2.getNextChunk( empty , &foundMin , &foundMax ) );
@@ -154,17 +154,17 @@ namespace {
BSONObj key_a30 = BSON( "a" << 30 );
BSONObj key_min = BSON( "a" << MINKEY );
BSONObj key_max = BSON( "a" << MAXKEY );
- BSONArray chunks3 = BSON_ARRAY( BSON( "_id" << "x.y-a_MinKey" <<
- "ns" << "x.y" <<
- "min" << key_min <<
+ BSONArray chunks3 = BSON_ARRAY( BSON( "_id" << "x.y-a_MinKey" <<
+ "ns" << "x.y" <<
+ "min" << key_min <<
"max" << key_a10 ) <<
- BSON( "_id" << "x.y-a_10" <<
- "ns" << "x.y" <<
- "min" << key_a10 <<
+ BSON( "_id" << "x.y-a_10" <<
+ "ns" << "x.y" <<
+ "min" << key_a10 <<
"max" << key_a20 ) <<
- BSON( "_id" << "x.y-a_30" <<
- "ns" << "x.y" <<
- "min" << key_a30 <<
+ BSON( "_id" << "x.y-a_30" <<
+ "ns" << "x.y" <<
+ "min" << key_a30 <<
"max" << key_max ) );
ShardChunkManager s3( collection , chunks3 );
ASSERT( ! s3.getNextChunk( empty , &foundMin , &foundMax ) ); // not eof
@@ -198,8 +198,8 @@ namespace {
"unique" << false );
// 1-chunk collection
// [10,0-20,0)
- BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKey" <<
- "ns" << "test.foo" <<
+ BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKey" <<
+ "ns" << "test.foo" <<
"min" << BSON( "a" << 10 << "b" << 0 ) <<
"max" << BSON( "a" << 20 << "b" << 0 ) ) );
@@ -211,13 +211,13 @@ namespace {
ShardChunkManagerPtr cloned( s.clonePlus( min , max , 1 /* TODO test version */ ) );
BSONObj k1 = BSON( "a" << 5 << "b" << 0 );
- ASSERT( ! cloned->belongsToMe( k1 ) );
+ ASSERT( ! cloned->belongsToMe( k1 ) );
BSONObj k2 = BSON( "a" << 20 << "b" << 0 );
- ASSERT( cloned->belongsToMe( k2 ) );
+ ASSERT( cloned->belongsToMe( k2 ) );
BSONObj k3 = BSON( "a" << 25 << "b" << 0 );
- ASSERT( cloned->belongsToMe( k3 ) );
+ ASSERT( cloned->belongsToMe( k3 ) );
BSONObj k4 = BSON( "a" << 30 << "b" << 0 );
- ASSERT( ! cloned->belongsToMe( k4 ) );
+ ASSERT( ! cloned->belongsToMe( k4 ) );
}
};
@@ -230,8 +230,8 @@ namespace {
"unique" << false );
// 1-chunk collection
// [10,0-20,0)
- BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKey" <<
- "ns" << "test.foo" <<
+ BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKey" <<
+ "ns" << "test.foo" <<
"min" << BSON( "a" << 10 << "b" << 0 ) <<
"max" << BSON( "a" << 20 << "b" << 0 ) ) );
@@ -249,18 +249,18 @@ namespace {
void run() {
BSONObj collection = BSON( "_id" << "x.y" <<
"dropped" << false <<
- "key" << BSON( "a" << 1 << "b" << 1 ) <<
+ "key" << BSON( "a" << 1 << "b" << 1 ) <<
"unique" << false );
// 2-chunk collection
// [10,0->20,0) , <gap> , [30,0->40,0)
- BSONArray chunks = BSON_ARRAY( BSON( "_id" << "x.y-a_10b_0" <<
- "ns" << "x.y" <<
- "min" << BSON( "a" << 10 << "b" << 0 ) <<
+ BSONArray chunks = BSON_ARRAY( BSON( "_id" << "x.y-a_10b_0" <<
+ "ns" << "x.y" <<
+ "min" << BSON( "a" << 10 << "b" << 0 ) <<
"max" << BSON( "a" << 20 << "b" << 0 ) ) <<
- BSON( "_id" << "x.y-a_30b_0" <<
- "ns" << "x.y" <<
- "min" << BSON( "a" << 30 << "b" << 0 ) <<
+ BSON( "_id" << "x.y-a_30b_0" <<
+ "ns" << "x.y" <<
+ "min" << BSON( "a" << 30 << "b" << 0 ) <<
"max" << BSON( "a" << 40 << "b" << 0 ) ) );
ShardChunkManager s ( collection , chunks );
@@ -271,9 +271,9 @@ namespace {
ShardChunkManagerPtr cloned( s.cloneMinus( min , max , 1 /* TODO test version */ ) );
BSONObj k1 = BSON( "a" << 5 << "b" << 0 );
- ASSERT( ! cloned->belongsToMe( k1 ) );
+ ASSERT( ! cloned->belongsToMe( k1 ) );
BSONObj k2 = BSON( "a" << 15 << "b" << 0 );
- ASSERT( ! cloned->belongsToMe( k2 ) );
+ ASSERT( ! cloned->belongsToMe( k2 ) );
BSONObj k3 = BSON( "a" << 30 << "b" << 0 );
ASSERT( cloned->belongsToMe( k3 ) );
BSONObj k4 = BSON( "a" << 35 << "b" << 0 );
@@ -288,18 +288,18 @@ namespace {
void run() {
BSONObj collection = BSON( "_id" << "x.y" <<
"dropped" << false <<
- "key" << BSON( "a" << 1 << "b" << 1 ) <<
+ "key" << BSON( "a" << 1 << "b" << 1 ) <<
"unique" << false );
// 2-chunk collection
// [10,0->20,0) , <gap> , [30,0->40,0)
- BSONArray chunks = BSON_ARRAY( BSON( "_id" << "x.y-a_10b_0" <<
- "ns" << "x.y" <<
- "min" << BSON( "a" << 10 << "b" << 0 ) <<
+ BSONArray chunks = BSON_ARRAY( BSON( "_id" << "x.y-a_10b_0" <<
+ "ns" << "x.y" <<
+ "min" << BSON( "a" << 10 << "b" << 0 ) <<
"max" << BSON( "a" << 20 << "b" << 0 ) ) <<
- BSON( "_id" << "x.y-a_30b_0" <<
- "ns" << "x.y" <<
- "min" << BSON( "a" << 30 << "b" << 0 ) <<
+ BSON( "_id" << "x.y-a_30b_0" <<
+ "ns" << "x.y" <<
+ "min" << BSON( "a" << 30 << "b" << 0 ) <<
"max" << BSON( "a" << 40 << "b" << 0 ) ) );
ShardChunkManager s ( collection , chunks );
@@ -328,9 +328,9 @@ namespace {
// [10,0-20,0)
BSONObj min = BSON( "a" << 10 << "b" << 0 );
BSONObj max = BSON( "a" << 20 << "b" << 0 );
- BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKey"
- << "ns" << "test.foo"
- << "min" << min
+ BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKey"
+ << "ns" << "test.foo"
+ << "min" << min
<< "max" << max ) );
ShardChunkManager s ( collection , chunks );
@@ -339,7 +339,7 @@ namespace {
BSONObj split2 = BSON( "a" << 18 << "b" << 0 );
vector<BSONObj> splitKeys;
splitKeys.push_back( split1 );
- splitKeys.push_back( split2 );
+ splitKeys.push_back( split2 );
ShardChunkVersion version( 1 , 99 ); // first chunk 1|99 , second 1|100
ShardChunkManagerPtr cloned( s.cloneSplit( min , max , splitKeys , version ) );
@@ -349,9 +349,9 @@ namespace {
ASSERT_EQUALS( s.getNumChunks() , 1u );
ASSERT_EQUALS( cloned->getNumChunks() , 3u );
ASSERT( cloned->belongsToMe( min ) );
- ASSERT( cloned->belongsToMe( split1 ) );
- ASSERT( cloned->belongsToMe( split2 ) );
- ASSERT( ! cloned->belongsToMe( max ) );
+ ASSERT( cloned->belongsToMe( split1 ) );
+ ASSERT( cloned->belongsToMe( split2 ) );
+ ASSERT( ! cloned->belongsToMe( max ) );
}
};
@@ -367,8 +367,8 @@ namespace {
BSONObj min = BSON( "a" << 10 << "b" << 0 );
BSONObj max = BSON( "a" << 20 << "b" << 0 );
BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_MinKey"
- << "ns" << "test.foo"
- << "min" << min
+ << "ns" << "test.foo"
+ << "min" << min
<< "max" << max ) );
ShardChunkManager s ( collection , chunks );
@@ -415,8 +415,8 @@ namespace {
// 1-chunk collection
// [10->20)
- BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_10" <<
- "ns" << "test.foo" <<
+ BSONArray chunks = BSON_ARRAY( BSON( "_id" << "test.foo-a_10" <<
+ "ns" << "test.foo" <<
"min" << BSON( "a" << 10 ) <<
"max" << BSON( "a" << 20 ) ) );
@@ -451,7 +451,7 @@ namespace {
add< BasicTests >();
add< BasicCompoundTests >();
add< RangeTests >();
- add< GetNextTests >();
+ add< GetNextTests >();
add< DeletedTests >();
add< ClonePlusTests >();
add< ClonePlusExceptionTests >();
diff --git a/dbtests/directclienttests.cpp b/dbtests/directclienttests.cpp
index e30fa3a29cb..204bf927a63 100644
--- a/dbtests/directclienttests.cpp
+++ b/dbtests/directclienttests.cpp
@@ -46,9 +46,9 @@ namespace DirectClientTests {
const char *ns = "a.b";
- class Capped : public ClientBase {
+ class Capped : public ClientBase {
public:
- virtual void run() {
+ virtual void run() {
for( int pass=0; pass < 3; pass++ ) {
client().createCollection(ns, 1024 * 1024, true, 999);
for( int j =0; j < pass*3; j++ )
@@ -68,12 +68,12 @@ namespace DirectClientTests {
}
}
};
-
+
class All : public Suite {
public:
All() : Suite( "directclient" ) {
}
- void setupTests(){
+ void setupTests() {
add< Capped >();
}
} myall;
diff --git a/dbtests/framework.cpp b/dbtests/framework.cpp
index 5f784882b2a..e2e73d37948 100644
--- a/dbtests/framework.cpp
+++ b/dbtests/framework.cpp
@@ -35,7 +35,7 @@
namespace po = boost::program_options;
namespace mongo {
-
+
CmdLine cmdLine;
namespace regression {
@@ -47,21 +47,21 @@ namespace mongo {
Result( string name ) : _name( name ) , _rc(0) , _tests(0) , _fails(0) , _asserts(0) {
}
- string toString(){
+ string toString() {
stringstream ss;
char result[128];
sprintf(result, "%-20s | tests: %4d | fails: %4d | assert calls: %6d\n", _name.c_str(), _tests, _fails, _asserts);
ss << result;
- for ( list<string>::iterator i=_messages.begin(); i!=_messages.end(); i++ ){
+ for ( list<string>::iterator i=_messages.begin(); i!=_messages.end(); i++ ) {
ss << "\t" << *i << '\n';
}
-
+
return ss.str();
}
- int rc(){
+ int rc() {
return _rc;
}
@@ -78,7 +78,7 @@ namespace mongo {
Result * Result::cur = 0;
- Result * Suite::run( const string& filter ){
+ Result * Suite::run( const string& filter ) {
tlogLevel = -1;
log(1) << "\t about to setupTests" << endl;
@@ -91,53 +91,53 @@ namespace mongo {
/* see note in SavedContext */
//writelock lk("");
- for ( list<TestCase*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ){
+ for ( list<TestCase*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ) {
TestCase * tc = *i;
- if ( filter.size() && tc->getName().find( filter ) == string::npos ){
+ if ( filter.size() && tc->getName().find( filter ) == string::npos ) {
log(1) << "\t skipping test: " << tc->getName() << " because doesn't match filter" << endl;
continue;
}
r->_tests++;
-
+
bool passes = false;
-
+
log(1) << "\t going to run test: " << tc->getName() << endl;
-
+
stringstream err;
err << tc->getName() << "\t";
-
+
try {
tc->run();
passes = true;
}
- catch ( MyAssertionException * ae ){
+ catch ( MyAssertionException * ae ) {
err << ae->ss.str();
delete( ae );
}
- catch ( std::exception& e ){
+ catch ( std::exception& e ) {
err << " exception: " << e.what();
}
- catch ( int x ){
+ catch ( int x ) {
err << " caught int : " << x << endl;
}
- catch ( ... ){
+ catch ( ... ) {
cerr << "unknown exception in test: " << tc->getName() << endl;
}
-
- if ( ! passes ){
+
+ if ( ! passes ) {
string s = err.str();
log() << "FAIL: " << s << endl;
r->_fails++;
r->_messages.push_back( s );
- }
+ }
}
-
+
if ( r->_fails )
r->_rc = 17;
log(1) << "\t DONE running tests" << endl;
-
+
return r;
}
@@ -156,23 +156,23 @@ namespace mongo {
po::positional_options_description positional_options;
shell_options.add_options()
- ("help,h", "show this usage information")
- ("dbpath", po::value<string>(&dbpathSpec)->default_value(default_dbpath),
- "db data path for this test run. NOTE: the contents of this "
- "directory will be overwritten if it already exists")
- ("debug", "run tests with verbose output")
- ("list,l", "list available test suites")
- ("bigfiles", "use big datafiles instead of smallfiles which is the default")
- ("filter,f" , po::value<string>() , "string substring filter on test name" )
- ("verbose,v", "verbose")
- ("dur", "enable journaling")
- ("nodur", "disable journaling (currently the default)")
- ("seed", po::value<unsigned long long>(&seed), "random number seed")
- ;
-
+ ("help,h", "show this usage information")
+ ("dbpath", po::value<string>(&dbpathSpec)->default_value(default_dbpath),
+ "db data path for this test run. NOTE: the contents of this "
+ "directory will be overwritten if it already exists")
+ ("debug", "run tests with verbose output")
+ ("list,l", "list available test suites")
+ ("bigfiles", "use big datafiles instead of smallfiles which is the default")
+ ("filter,f" , po::value<string>() , "string substring filter on test name" )
+ ("verbose,v", "verbose")
+ ("dur", "enable journaling")
+ ("nodur", "disable journaling (currently the default)")
+ ("seed", po::value<unsigned long long>(&seed), "random number seed")
+ ;
+
hidden_options.add_options()
- ("suites", po::value< vector<string> >(), "test suites to run")
- ;
+ ("suites", po::value< vector<string> >(), "test suites to run")
+ ;
positional_options.add("suites", -1);
@@ -189,7 +189,8 @@ namespace mongo {
positional(positional_options).
style(command_line_style).run(), params);
po::notify(params);
- } catch (po::error &e) {
+ }
+ catch (po::error &e) {
cout << "ERROR: " << e.what() << endl << endl;
show_help_text(argv[0], shell_options);
return EXIT_BADOPTIONS;
@@ -200,10 +201,10 @@ namespace mongo {
return EXIT_CLEAN;
}
- if( params.count("nodur") ) {
+ if( params.count("nodur") ) {
cmdLine.dur = false;
}
- if( params.count("dur") || cmdLine.dur ) {
+ if( params.count("dur") || cmdLine.dur ) {
cmdLine.dur = true;
}
@@ -228,21 +229,22 @@ namespace mongo {
}
boost::filesystem::directory_iterator end_iter;
for (boost::filesystem::directory_iterator dir_iter(p);
- dir_iter != end_iter; ++dir_iter) {
+ dir_iter != end_iter; ++dir_iter) {
boost::filesystem::remove_all(*dir_iter);
}
- } else {
+ }
+ else {
boost::filesystem::create_directory(p);
}
string dbpathString = p.native_directory_string();
dbpath = dbpathString.c_str();
-
+
cmdLine.prealloc = false;
// dbtest defaults to smallfiles
cmdLine.smallfiles = true;
- if( params.count("bigfiles") ) {
+ if( params.count("bigfiles") ) {
cmdLine.dur = true;
}
@@ -261,9 +263,9 @@ namespace mongo {
if (params.count("suites")) {
suites = params["suites"].as< vector<string> >();
}
-
+
string filter = "";
- if ( params.count( "filter" ) ){
+ if ( params.count( "filter" ) ) {
filter = params["filter"].as<string>();
}
@@ -274,13 +276,13 @@ namespace mongo {
#if !defined(_WIN32) && !defined(__sunos__)
flock( lockFile, LOCK_UN );
#endif
-
+
cc().shutdown();
dbexit( (ExitCode)ret ); // so everything shuts down cleanly
return ret;
}
- int Suite::run( vector<string> suites , const string& filter ){
+ int Suite::run( vector<string> suites , const string& filter ) {
for ( unsigned int i = 0; i < suites.size(); i++ ) {
if ( _suites->find( suites[i] ) == _suites->end() ) {
cout << "invalid test [" << suites[i] << "], use --list to see valid names" << endl;
@@ -296,7 +298,7 @@ namespace mongo {
list<Result*> results;
- for ( list<string>::iterator i=torun.begin(); i!=torun.end(); i++ ){
+ for ( list<string>::iterator i=torun.begin(); i!=torun.end(); i++ ) {
string name = *i;
Suite * s = (*_suites)[name];
assert( s );
@@ -317,12 +319,12 @@ namespace mongo {
int fails = 0;
int asserts = 0;
- for ( list<Result*>::iterator i=results.begin(); i!=results.end(); i++ ){
+ for ( list<Result*>::iterator i=results.begin(); i!=results.end(); i++ ) {
Result * r = *i;
cout << r->toString();
if ( abs( r->rc() ) > abs( rc ) )
rc = r->rc();
-
+
tests += r->_tests;
fails += r->_fails;
asserts += r->_asserts;
@@ -332,13 +334,13 @@ namespace mongo {
totals._tests = tests;
totals._fails = fails;
totals._asserts = asserts;
-
+
cout << totals.toString(); // includes endl
return rc;
}
- void Suite::registerSuite( string name , Suite * s ){
+ void Suite::registerSuite( string name , Suite * s ) {
if ( ! _suites )
_suites = new map<string,Suite*>();
Suite*& m = (*_suites)[name];
@@ -346,37 +348,37 @@ namespace mongo {
m = s;
}
- void assert_pass(){
+ void assert_pass() {
Result::cur->_asserts++;
}
- void assert_fail( const char * exp , const char * file , unsigned line ){
+ void assert_fail( const char * exp , const char * file , unsigned line ) {
Result::cur->_asserts++;
-
+
MyAssertionException * e = new MyAssertionException();
e->ss << "ASSERT FAILED! " << file << ":" << line << endl;
throw e;
}
- void fail( const char * exp , const char * file , unsigned line ){
+ void fail( const char * exp , const char * file , unsigned line ) {
assert(0);
}
- MyAssertionException * MyAsserts::getBase(){
+ MyAssertionException * MyAsserts::getBase() {
MyAssertionException * e = new MyAssertionException();
e->ss << _file << ":" << _line << " " << _aexp << " != " << _bexp << " ";
return e;
}
-
- void MyAsserts::printLocation(){
+
+ void MyAsserts::printLocation() {
log() << _file << ":" << _line << " " << _aexp << " != " << _bexp << " ";
}
- void MyAsserts::_gotAssert(){
+ void MyAsserts::_gotAssert() {
Result::cur->_asserts++;
}
}
- void setupSignals( bool inFork ){}
+ void setupSignals( bool inFork ) {}
}
diff --git a/dbtests/framework.h b/dbtests/framework.h
index bec14a2f28d..29ba58bd96b 100644
--- a/dbtests/framework.h
+++ b/dbtests/framework.h
@@ -49,7 +49,7 @@ namespace mongo {
class TestCase {
public:
- virtual ~TestCase(){}
+ virtual ~TestCase() {}
virtual void run() = 0;
virtual string getName() = 0;
};
@@ -57,15 +57,15 @@ namespace mongo {
template< class T >
class TestHolderBase : public TestCase {
public:
- TestHolderBase(){}
- virtual ~TestHolderBase(){}
- virtual void run(){
+ TestHolderBase() {}
+ virtual ~TestHolderBase() {}
+ virtual void run() {
auto_ptr<T> t;
t.reset( create() );
t->run();
}
virtual T * create() = 0;
- virtual string getName(){
+ virtual string getName() {
return demangleName( typeid(T) );
}
};
@@ -73,7 +73,7 @@ namespace mongo {
template< class T >
class TestHolder0 : public TestHolderBase<T> {
public:
- virtual T * create(){
+ virtual T * create() {
return new T();
}
};
@@ -81,8 +81,8 @@ namespace mongo {
template< class T , typename A >
class TestHolder1 : public TestHolderBase<T> {
public:
- TestHolder1( const A& a ) : _a(a){}
- virtual T * create(){
+ TestHolder1( const A& a ) : _a(a) {}
+ virtual T * create() {
return new T( _a );
}
const A& _a;
@@ -90,25 +90,25 @@ namespace mongo {
class Suite {
public:
- Suite( string name ) : _name( name ){
+ Suite( string name ) : _name( name ) {
registerSuite( name , this );
_ran = 0;
}
virtual ~Suite() {
- if ( _ran ){
+ if ( _ran ) {
DBDirectClient c;
c.dropDatabase( "unittests" );
}
}
template<class T>
- void add(){
+ void add() {
_tests.push_back( new TestHolder0<T>() );
}
template<class T , typename A >
- void add( const A& a ){
+ void add( const A& a ) {
_tests.push_back( new TestHolder1<T,A>(a) );
}
@@ -137,7 +137,7 @@ namespace mongo {
class MyAssertionException : boost::noncopyable {
public:
- MyAssertionException(){
+ MyAssertionException() {
ss << "assertion: ";
}
stringstream ss;
@@ -148,32 +148,32 @@ namespace mongo {
class MyAsserts {
public:
MyAsserts( const char * aexp , const char * bexp , const char * file , unsigned line )
- : _aexp( aexp ) , _bexp( bexp ) , _file( file ) , _line( line ){
+ : _aexp( aexp ) , _bexp( bexp ) , _file( file ) , _line( line ) {
}
-
+
template<typename A,typename B>
- void ae( A a , B b ){
+ void ae( A a , B b ) {
_gotAssert();
if ( a == b )
return;
-
+
printLocation();
-
+
MyAssertionException * e = getBase();
e->ss << a << " != " << b << endl;
log() << e->ss.str() << endl;
throw e;
}
-
+
template<typename A,typename B>
- void nae( A a , B b ){
+ void nae( A a , B b ) {
_gotAssert();
if ( a != b )
return;
-
+
printLocation();
-
+
MyAssertionException * e = getBase();
e->ss << a << " == " << b << endl;
log() << e->ss.str() << endl;
@@ -182,13 +182,13 @@ namespace mongo {
void printLocation();
-
+
private:
-
+
void _gotAssert();
-
+
MyAssertionException * getBase();
-
+
string _aexp;
string _bexp;
string _file;
diff --git a/dbtests/histogram_test.cpp b/dbtests/histogram_test.cpp
index 5a8970d3333..e9cbb5bdf25 100644
--- a/dbtests/histogram_test.cpp
+++ b/dbtests/histogram_test.cpp
@@ -25,9 +25,9 @@ namespace mongo {
using mongo::Histogram;
- class BoundariesInit{
+ class BoundariesInit {
public:
- void run(){
+ void run() {
Histogram::Options opts;
opts.numBuckets = 3;
opts.bucketSize = 10;
@@ -45,9 +45,9 @@ namespace mongo {
}
};
- class BoundariesExponential{
+ class BoundariesExponential {
public:
- void run(){
+ void run() {
Histogram::Options opts;
opts.numBuckets = 4;
opts.bucketSize = 125;
@@ -57,13 +57,13 @@ namespace mongo {
ASSERT_EQUALS( h.getBoundary( 0 ), 125u );
ASSERT_EQUALS( h.getBoundary( 1 ), 250u );
ASSERT_EQUALS( h.getBoundary( 2 ), 500u );
- ASSERT_EQUALS( h.getBoundary( 3 ), numeric_limits<uint32_t>::max() );
+ ASSERT_EQUALS( h.getBoundary( 3 ), numeric_limits<uint32_t>::max() );
}
};
- class BoundariesFind{
+ class BoundariesFind {
public:
- void run(){
+ void run() {
Histogram::Options opts;
opts.numBuckets = 3;
opts.bucketSize = 10;
@@ -81,14 +81,14 @@ namespace mongo {
class HistogramSuite : public Suite {
public:
- HistogramSuite() : Suite( "histogram" ){}
+ HistogramSuite() : Suite( "histogram" ) {}
- void setupTests(){
+ void setupTests() {
add< BoundariesInit >();
add< BoundariesExponential >();
add< BoundariesFind >();
// TODO: complete the test suite
- }
+ }
} histogramSuite;
} // anonymous namespace
diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp
index e1e7f04e95d..a8570e15bfb 100644
--- a/dbtests/jsobjtests.cpp
+++ b/dbtests/jsobjtests.cpp
@@ -150,7 +150,7 @@ namespace JsobjTests {
class MultiKeySortOrder : public Base {
public:
- void run(){
+ void run() {
ASSERT( BSON( "x" << "a" ).woCompare( BSON( "x" << "b" ) ) < 0 );
ASSERT( BSON( "x" << "b" ).woCompare( BSON( "x" << "a" ) ) > 0 );
@@ -255,9 +255,9 @@ namespace JsobjTests {
}
};
- class AsTempObj{
+ class AsTempObj {
public:
- void run(){
+ void run() {
{
BSONObjBuilder bb;
bb << "a" << 1;
@@ -267,7 +267,7 @@ namespace JsobjTests {
ASSERT(tmp.hasField("a"));
ASSERT(!tmp.hasField("b"));
ASSERT(tmp == BSON("a" << 1));
-
+
bb << "b" << 2;
BSONObj obj = bb.obj();
ASSERT_EQUALS(obj.objsize() , 4+(1+2+4)+(1+2+4)+1);
@@ -285,7 +285,7 @@ namespace JsobjTests {
ASSERT(tmp.hasField("a"));
ASSERT(!tmp.hasField("b"));
ASSERT(tmp == BSON("a" << BSON("$gt" << 1)));
-
+
bb << "b" << LT << 2;
BSONObj obj = bb.obj();
ASSERT(obj.objsize() == 4+(1+2+(4+1+4+4+1))+(1+2+(4+1+4+4+1))+1);
@@ -293,7 +293,7 @@ namespace JsobjTests {
ASSERT(obj.hasField("a"));
ASSERT(obj.hasField("b"));
ASSERT(obj == BSON("a" << BSON("$gt" << 1)
- << "b" << BSON("$lt" << 2)));
+ << "b" << BSON("$lt" << 2)));
}
{
BSONObjBuilder bb(32);
@@ -304,10 +304,10 @@ namespace JsobjTests {
ASSERT(tmp.hasField("a"));
ASSERT(!tmp.hasField("b"));
ASSERT(tmp == BSON("a" << 1));
-
+
//force a realloc
BSONArrayBuilder arr;
- for (int i=0; i < 10000; i++){
+ for (int i=0; i < 10000; i++) {
arr << i;
}
bb << "b" << arr.arr();
@@ -319,8 +319,8 @@ namespace JsobjTests {
}
};
- struct AppendIntOrLL{
- void run(){
+ struct AppendIntOrLL {
+ void run() {
const long long billion = 1000*1000*1000;
BSONObjBuilder b;
b.appendIntOrLL("i1", 1);
@@ -362,16 +362,16 @@ namespace JsobjTests {
};
struct AppendNumber {
- void run(){
+ void run() {
BSONObjBuilder b;
b.appendNumber( "a" , 5 );
b.appendNumber( "b" , 5.5 );
b.appendNumber( "c" , (1024LL*1024*1024)-1 );
b.appendNumber( "d" , (1024LL*1024*1024*1024)-1 );
b.appendNumber( "e" , 1024LL*1024*1024*1024*1024*1024 );
-
+
BSONObj o = b.obj();
-
+
ASSERT( o["a"].type() == NumberInt );
ASSERT( o["b"].type() == NumberDouble );
ASSERT( o["c"].type() == NumberInt );
@@ -380,7 +380,7 @@ namespace JsobjTests {
}
};
-
+
class ToStringArray {
public:
void run() {
@@ -391,28 +391,28 @@ namespace JsobjTests {
class ToStringNumber {
public:
-
- void run(){
+
+ void run() {
BSONObjBuilder b;
b.append( "a" , (int)4 );
b.append( "b" , (double)5 );
b.append( "c" , (long long)6 );
-
+
b.append( "d" , 123.456789123456789123456789123456789 );
b.append( "e" , 123456789.123456789123456789123456789 );
b.append( "f" , 1234567891234567891234.56789123456789 );
b.append( "g" , -123.456 );
-
+
BSONObj x = b.obj();
ASSERT_EQUALS( "4", x["a"].toString( false , true ) );
ASSERT_EQUALS( "5.0", x["b"].toString( false , true ) );
- ASSERT_EQUALS( "6", x["c"].toString( false , true ) );
+ ASSERT_EQUALS( "6", x["c"].toString( false , true ) );
ASSERT_EQUALS( "123.4567891234568" , x["d"].toString( false , true ) );
ASSERT_EQUALS( "123456789.1234568" , x["e"].toString( false , true ) );
// ASSERT_EQUALS( "1.234567891234568e+21" , x["f"].toString( false , true ) ); // windows and *nix are different - TODO, work around for test or not bother?
-
+
ASSERT_EQUALS( "-123.456" , x["g"].toString( false , true ) );
}
@@ -441,7 +441,7 @@ namespace JsobjTests {
}
};
-
+
class AppendAs {
public:
void run() {
@@ -468,7 +468,7 @@ namespace JsobjTests {
ASSERT_EQUALS( 4, a.nFields() );
}
};
-
+
namespace Validation {
class Base {
@@ -718,12 +718,12 @@ namespace JsobjTests {
a.valid();
BSONObj b = fromjson( "{\"one\":2, \"two\":5, \"three\": {},"
- "\"four\": { \"five\": { \"six\" : 11 } },"
- "\"seven\": [ \"a\", \"bb\", \"ccc\", 5 ],"
- "\"eight\": Dbref( \"rrr\", \"01234567890123456789aaaa\" ),"
- "\"_id\": ObjectId( \"deadbeefdeadbeefdeadbeef\" ),"
- "\"nine\": { \"$binary\": \"abc=\", \"$type\": \"00\" },"
- "\"ten\": Date( 44 ), \"eleven\": /foooooo/i }" );
+ "\"four\": { \"five\": { \"six\" : 11 } },"
+ "\"seven\": [ \"a\", \"bb\", \"ccc\", 5 ],"
+ "\"eight\": Dbref( \"rrr\", \"01234567890123456789aaaa\" ),"
+ "\"_id\": ObjectId( \"deadbeefdeadbeefdeadbeef\" ),"
+ "\"nine\": { \"$binary\": \"abc=\", \"$type\": \"00\" },"
+ "\"ten\": Date( 44 ), \"eleven\": /foooooo/i }" );
fuzz( b );
b.valid();
}
@@ -750,7 +750,7 @@ namespace JsobjTests {
class init1 {
public:
- void run(){
+ void run() {
OID a;
OID b;
@@ -763,7 +763,7 @@ namespace JsobjTests {
class initParse1 {
public:
- void run(){
+ void run() {
OID a;
OID b;
@@ -777,7 +777,7 @@ namespace JsobjTests {
class append {
public:
- void run(){
+ void run() {
BSONObjBuilder b;
b.appendOID( "a" , 0 );
b.appendOID( "b" , 0 , false );
@@ -793,18 +793,18 @@ namespace JsobjTests {
class increasing {
public:
- BSONObj g(){
+ BSONObj g() {
BSONObjBuilder b;
b.appendOID( "_id" , 0 , true );
return b.obj();
}
- void run(){
+ void run() {
BSONObj a = g();
BSONObj b = g();
-
+
ASSERT( a.woCompare( b ) < 0 );
-
- // yes, there is a 1/1000 chance this won't increase time(0)
+
+ // yes, there is a 1/1000 chance this won't increase time(0)
// and therefore inaccurately say the function is behaving
// buf if its broken, it will fail 999/1000, so i think that's good enough
sleepsecs( 1 );
@@ -815,7 +815,7 @@ namespace JsobjTests {
class ToDate {
public:
- void run(){
+ void run() {
OID oid;
{
@@ -839,7 +839,7 @@ namespace JsobjTests {
class FromDate {
public:
- void run(){
+ void run() {
OID min, oid, max;
Date_t now = jsTime();
oid.init(); // slight chance this has different time. If its a problem, can change.
@@ -917,26 +917,26 @@ namespace JsobjTests {
class LabelMulti : public LabelBase {
BSONObj expected() {
return BSON( "z" << "q"
- << "a" << BSON( "$gt" << 1 << "$lte" << "x" )
- << "b" << BSON( "$ne" << 1 << "$ne" << "f" << "$ne" << 22.3 )
- << "x" << "p" );
+ << "a" << BSON( "$gt" << 1 << "$lte" << "x" )
+ << "b" << BSON( "$ne" << 1 << "$ne" << "f" << "$ne" << 22.3 )
+ << "x" << "p" );
}
BSONObj actual() {
return BSON( "z" << "q"
- << "a" << GT << 1 << LTE << "x"
- << "b" << NE << 1 << NE << "f" << NE << 22.3
- << "x" << "p" );
+ << "a" << GT << 1 << LTE << "x"
+ << "b" << NE << 1 << NE << "f" << NE << 22.3
+ << "x" << "p" );
}
};
class LabelishOr : public LabelBase {
BSONObj expected() {
return BSON( "$or" << BSON_ARRAY(
- BSON("a" << BSON( "$gt" << 1 << "$lte" << "x" ))
- << BSON("b" << BSON( "$ne" << 1 << "$ne" << "f" << "$ne" << 22.3 ))
- << BSON("x" << "p" )));
+ BSON("a" << BSON( "$gt" << 1 << "$lte" << "x" ))
+ << BSON("b" << BSON( "$ne" << 1 << "$ne" << "f" << "$ne" << 22.3 ))
+ << BSON("x" << "p" )));
}
BSONObj actual() {
- return OR( BSON( "a" << GT << 1 << LTE << "x"),
+ return OR( BSON( "a" << GT << 1 << LTE << "x"),
BSON( "b" << NE << 1 << NE << "f" << NE << 22.3),
BSON( "x" << "p" ) );
}
@@ -952,7 +952,7 @@ namespace JsobjTests {
class ElementAppend {
public:
- void run(){
+ void run() {
BSONObj a = BSON( "a" << 17 );
BSONObj b = BSON( "b" << a["a"] );
ASSERT_EQUALS( NumberInt , a["a"].type() );
@@ -1044,20 +1044,20 @@ namespace JsobjTests {
class MinMaxElementTest {
public:
- BSONObj min( int t ){
+ BSONObj min( int t ) {
BSONObjBuilder b;
b.appendMinForType( "a" , t );
return b.obj();
}
- BSONObj max( int t ){
+ BSONObj max( int t ) {
BSONObjBuilder b;
b.appendMaxForType( "a" , t );
return b.obj();
}
- void run(){
- for ( int t=1; t<JSTypeMax; t++ ){
+ void run() {
+ for ( int t=1; t<JSTypeMax; t++ ) {
stringstream ss;
ss << "type: " << t;
string s = ss.str();
@@ -1072,7 +1072,7 @@ namespace JsobjTests {
class ExtractFieldsTest {
public:
- void run(){
+ void run() {
BSONObj x = BSON( "a" << 10 << "b" << 11 );
assert( BSON( "a" << 10 ).woCompare( x.extractFields( BSON( "a" << 1 ) ) ) == 0 );
assert( BSON( "b" << 11 ).woCompare( x.extractFields( BSON( "b" << 1 ) ) ) == 0 );
@@ -1084,10 +1084,10 @@ namespace JsobjTests {
class ComparatorTest {
public:
- BSONObj one( string s ){
+ BSONObj one( string s ) {
return BSON( "x" << s );
}
- BSONObj two( string x , string y ){
+ BSONObj two( string x , string y ) {
BSONObjBuilder b;
b.append( "x" , x );
if ( y.size() )
@@ -1097,7 +1097,7 @@ namespace JsobjTests {
return b.obj();
}
- void test( BSONObj order , BSONObj l , BSONObj r , bool wanted ){
+ void test( BSONObj order , BSONObj l , BSONObj r , bool wanted ) {
BSONObjCmp c( order );
bool got = c(l,r);
if ( got == wanted )
@@ -1105,11 +1105,11 @@ namespace JsobjTests {
cout << " order: " << order << " l: " << l << "r: " << r << " wanted: " << wanted << " got: " << got << endl;
}
- void lt( BSONObj order , BSONObj l , BSONObj r ){
+ void lt( BSONObj order , BSONObj l , BSONObj r ) {
test( order , l , r , 1 );
}
- void run(){
+ void run() {
BSONObj s = BSON( "x" << 1 );
BSONObj c = BSON( "x" << 1 << "y" << 1 );
test( s , one( "A" ) , one( "B" ) , 1 );
@@ -1133,7 +1133,7 @@ namespace JsobjTests {
namespace external_sort {
class Basic1 {
public:
- void run(){
+ void run() {
BSONObjExternalSorter sorter;
sorter.add( BSON( "x" << 10 ) , 5 , 1);
sorter.add( BSON( "x" << 2 ) , 3 , 1 );
@@ -1141,14 +1141,14 @@ namespace JsobjTests {
sorter.add( BSON( "x" << 5 ) , 7 , 1 );
sorter.sort();
-
+
auto_ptr<BSONObjExternalSorter::Iterator> i = sorter.iterator();
int num=0;
- while ( i->more() ){
+ while ( i->more() ) {
pair<BSONObj,DiskLoc> p = i->next();
if ( num == 0 )
assert( p.first["x"].number() == 2 );
- else if ( num <= 2 ){
+ else if ( num <= 2 ) {
assert( p.first["x"].number() == 5 );
}
else if ( num == 3 )
@@ -1157,15 +1157,15 @@ namespace JsobjTests {
ASSERT( 0 );
num++;
}
-
-
+
+
ASSERT_EQUALS( 0 , sorter.numFiles() );
}
};
class Basic2 {
public:
- void run(){
+ void run() {
BSONObjExternalSorter sorter( BSONObj() , 10 );
sorter.add( BSON( "x" << 10 ) , 5 , 11 );
sorter.add( BSON( "x" << 2 ) , 3 , 1 );
@@ -1173,18 +1173,18 @@ namespace JsobjTests {
sorter.add( BSON( "x" << 5 ) , 7 , 1 );
sorter.sort();
-
+
auto_ptr<BSONObjExternalSorter::Iterator> i = sorter.iterator();
int num=0;
- while ( i->more() ){
+ while ( i->more() ) {
pair<BSONObj,DiskLoc> p = i->next();
- if ( num == 0 ){
+ if ( num == 0 ) {
assert( p.first["x"].number() == 2 );
ASSERT_EQUALS( p.second.toString() , "3:1" );
}
else if ( num <= 2 )
assert( p.first["x"].number() == 5 );
- else if ( num == 3 ){
+ else if ( num == 3 ) {
assert( p.first["x"].number() == 10 );
ASSERT_EQUALS( p.second.toString() , "5:b" );
}
@@ -1198,7 +1198,7 @@ namespace JsobjTests {
class Basic3 {
public:
- void run(){
+ void run() {
BSONObjExternalSorter sorter( BSONObj() , 10 );
sorter.sort();
@@ -1211,23 +1211,23 @@ namespace JsobjTests {
class ByDiskLock {
public:
- void run(){
+ void run() {
BSONObjExternalSorter sorter;
sorter.add( BSON( "x" << 10 ) , 5 , 4);
sorter.add( BSON( "x" << 2 ) , 3 , 0 );
sorter.add( BSON( "x" << 5 ) , 6 , 2 );
sorter.add( BSON( "x" << 5 ) , 7 , 3 );
sorter.add( BSON( "x" << 5 ) , 2 , 1 );
-
+
sorter.sort();
auto_ptr<BSONObjExternalSorter::Iterator> i = sorter.iterator();
int num=0;
- while ( i->more() ){
+ while ( i->more() ) {
pair<BSONObj,DiskLoc> p = i->next();
if ( num == 0 )
assert( p.first["x"].number() == 2 );
- else if ( num <= 3 ){
+ else if ( num <= 3 ) {
assert( p.first["x"].number() == 5 );
}
else if ( num == 4 )
@@ -1245,9 +1245,9 @@ namespace JsobjTests {
class Big1 {
public:
- void run(){
+ void run() {
BSONObjExternalSorter sorter( BSONObj() , 2000 );
- for ( int i=0; i<10000; i++ ){
+ for ( int i=0; i<10000; i++ ) {
sorter.add( BSON( "x" << rand() % 10000 ) , 5 , i );
}
@@ -1256,7 +1256,7 @@ namespace JsobjTests {
auto_ptr<BSONObjExternalSorter::Iterator> i = sorter.iterator();
int num=0;
double prev = 0;
- while ( i->more() ){
+ while ( i->more() ) {
pair<BSONObj,DiskLoc> p = i->next();
num++;
double cur = p.first["x"].number();
@@ -1266,22 +1266,22 @@ namespace JsobjTests {
assert( num == 10000 );
}
};
-
+
class Big2 {
public:
- void run(){
+ void run() {
const int total = 100000;
BSONObjExternalSorter sorter( BSONObj() , total * 2 );
- for ( int i=0; i<total; i++ ){
+ for ( int i=0; i<total; i++ ) {
sorter.add( BSON( "a" << "b" ) , 5 , i );
}
sorter.sort();
-
+
auto_ptr<BSONObjExternalSorter::Iterator> i = sorter.iterator();
int num=0;
double prev = 0;
- while ( i->more() ){
+ while ( i->more() ) {
pair<BSONObj,DiskLoc> p = i->next();
num++;
double cur = p.first["x"].number();
@@ -1295,21 +1295,21 @@ namespace JsobjTests {
class D1 {
public:
- void run(){
-
+ void run() {
+
BSONObjBuilder b;
b.appendNull("");
BSONObj x = b.obj();
-
+
BSONObjExternalSorter sorter;
sorter.add(x, DiskLoc(3,7));
sorter.add(x, DiskLoc(4,7));
sorter.add(x, DiskLoc(2,7));
sorter.add(x, DiskLoc(1,7));
sorter.add(x, DiskLoc(3,77));
-
+
sorter.sort();
-
+
auto_ptr<BSONObjExternalSorter::Iterator> i = sorter.iterator();
while( i->more() ) {
BSONObjExternalSorter::Data d = i->next();
@@ -1320,14 +1320,14 @@ namespace JsobjTests {
}
};
}
-
+
class CompatBSON {
public:
-
+
#define JSONBSONTEST(j,s,m) ASSERT_EQUALS( fromjson( j ).objsize() , s ); ASSERT_EQUALS( fromjson( j ).md5() , m );
#define RAWBSONTEST(j,s,m) ASSERT_EQUALS( j.objsize() , s ); ASSERT_EQUALS( j.md5() , m );
- void run(){
+ void run() {
JSONBSONTEST( "{ 'x' : true }" , 9 , "6fe24623e4efc5cf07f027f9c66b5456" );
JSONBSONTEST( "{ 'x' : null }" , 8 , "12d43430ff6729af501faf0638e68888" );
@@ -1337,20 +1337,20 @@ namespace JsobjTests {
JSONBSONTEST( "{ 'a' : { 'b' : 1.1 } }" , 24 , "31887a4b9d55cd9f17752d6a8a45d51f" );
JSONBSONTEST( "{ 'x' : 5.2 , 'y' : { 'a' : 'eliot' , b : true } , 'z' : null }" , 44 , "b3de8a0739ab329e7aea138d87235205" );
JSONBSONTEST( "{ 'x' : 5.2 , 'y' : [ 'a' , 'eliot' , 'b' , true ] , 'z' : null }" , 62 , "cb7bad5697714ba0cbf51d113b6a0ee8" );
-
+
RAWBSONTEST( BSON( "x" << 4 ) , 12 , "d1ed8dbf79b78fa215e2ded74548d89d" );
-
+
}
};
-
+
class CompareDottedFieldNamesTest {
public:
- void t( FieldCompareResult res , const string& l , const string& r ){
+ void t( FieldCompareResult res , const string& l , const string& r ) {
ASSERT_EQUALS( res , compareDottedFieldNames( l , r ) );
ASSERT_EQUALS( -1 * res , compareDottedFieldNames( r , l ) );
}
-
- void run(){
+
+ void run() {
t( SAME , "x" , "x" );
t( SAME , "x.a" , "x.a" );
t( LEFT_BEFORE , "a" , "b" );
@@ -1360,13 +1360,13 @@ namespace JsobjTests {
}
};
- struct NestedDottedConversions{
- void t(const BSONObj& nest, const BSONObj& dot){
+ struct NestedDottedConversions {
+ void t(const BSONObj& nest, const BSONObj& dot) {
ASSERT_EQUALS( nested2dotted(nest), dot);
ASSERT_EQUALS( nest, dotted2nested(dot));
}
- void run(){
+ void run() {
t( BSON("a" << BSON("b" << 1)), BSON("a.b" << 1) );
t( BSON("a" << BSON("b" << 1 << "c" << 1)), BSON("a.b" << 1 << "a.c" << 1) );
t( BSON("a" << BSON("b" << 1 << "c" << 1) << "d" << 1), BSON("a.b" << 1 << "a.c" << 1 << "d" << 1) );
@@ -1374,8 +1374,8 @@ namespace JsobjTests {
}
};
- struct BSONArrayBuilderTest{
- void run(){
+ struct BSONArrayBuilderTest {
+ void run() {
int i = 0;
BSONObjBuilder objb;
BSONArrayBuilder arrb;
@@ -1414,13 +1414,13 @@ namespace JsobjTests {
ASSERT_EQUALS(o["arr2"].type(), Array);
}
};
-
- struct ArrayMacroTest{
- void run(){
+
+ struct ArrayMacroTest {
+ void run() {
BSONArray arr = BSON_ARRAY( "hello" << 1 << BSON( "foo" << BSON_ARRAY( "bar" << "baz" << "qux" ) ) );
BSONObj obj = BSON( "0" << "hello"
- << "1" << 1
- << "2" << BSON( "foo" << BSON_ARRAY( "bar" << "baz" << "qux" ) ) );
+ << "1" << 1
+ << "2" << BSON( "foo" << BSON_ARRAY( "bar" << "baz" << "qux" ) ) );
ASSERT_EQUALS(arr, obj);
ASSERT_EQUALS(arr["2"].type(), Object);
@@ -1430,25 +1430,25 @@ namespace JsobjTests {
class NumberParsing {
public:
- void run(){
+ void run() {
BSONObjBuilder a;
BSONObjBuilder b;
a.append( "a" , (int)1 );
ASSERT( b.appendAsNumber( "a" , "1" ) );
-
+
a.append( "b" , 1.1 );
ASSERT( b.appendAsNumber( "b" , "1.1" ) );
a.append( "c" , (int)-1 );
ASSERT( b.appendAsNumber( "c" , "-1" ) );
-
+
a.append( "d" , -1.1 );
ASSERT( b.appendAsNumber( "d" , "-1.1" ) );
a.append( "e" , (long long)32131231231232313LL );
ASSERT( b.appendAsNumber( "e" , "32131231231232313" ) );
-
+
ASSERT( ! b.appendAsNumber( "f" , "zz" ) );
ASSERT( ! b.appendAsNumber( "f" , "5zz" ) );
ASSERT( ! b.appendAsNumber( "f" , "zz5" ) );
@@ -1456,10 +1456,10 @@ namespace JsobjTests {
ASSERT_EQUALS( a.obj() , b.obj() );
}
};
-
+
class bson2settest {
public:
- void run(){
+ void run() {
BSONObj o = BSON( "z" << 1 << "a" << 2 << "m" << 3 << "c" << 4 );
BSONObjIteratorSorted i( o );
stringstream ss;
@@ -1469,7 +1469,7 @@ namespace JsobjTests {
{
Timer t;
- for ( int i=0; i<10000; i++ ){
+ for ( int i=0; i<10000; i++ ) {
BSONObjIteratorSorted j( o );
int l = 0;
while ( j.more() )
@@ -1484,22 +1484,22 @@ namespace JsobjTests {
class checkForStorageTests {
public:
-
- void good( string s ){
+
+ void good( string s ) {
BSONObj o = fromjson( s );
if ( o.okForStorage() )
return;
throw UserException( 12528 , (string)"should be ok for storage:" + s );
}
- void bad( string s ){
+ void bad( string s ) {
BSONObj o = fromjson( s );
if ( ! o.okForStorage() )
return;
throw UserException( 12529 , (string)"should NOT be ok for storage:" + s );
}
- void run(){
+ void run() {
good( "{x:1}" );
bad( "{'x.y':1}" );
@@ -1510,7 +1510,7 @@ namespace JsobjTests {
class InvalidIDFind {
public:
- void run(){
+ void run() {
BSONObj x = BSON( "_id" << 5 << "t" << 2 );
{
char * crap = (char*)malloc( x.objsize() );
@@ -1519,7 +1519,7 @@ namespace JsobjTests {
ASSERT_EQUALS( x , y );
free( crap );
}
-
+
{
char * crap = (char*)malloc( x.objsize() );
memcpy( crap , x.objdata() , x.objsize() );
@@ -1530,21 +1530,21 @@ namespace JsobjTests {
BSONObj y( crap , false );
state = 1;
}
- catch ( std::exception& e ){
+ catch ( std::exception& e ) {
state = 2;
ASSERT( strstr( e.what() , "_id: 5" ) > 0 );
}
free( crap );
ASSERT_EQUALS( 2 , state );
}
-
-
+
+
}
};
class ElementSetTest {
public:
- void run(){
+ void run() {
BSONObj x = BSON( "a" << 1 << "b" << 1 << "c" << 2 );
BSONElement a = x["a"];
BSONElement b = x["b"];
@@ -1552,7 +1552,7 @@ namespace JsobjTests {
cout << "c: " << c << endl;
ASSERT( a.woCompare( b ) != 0 );
ASSERT( a.woCompare( b , false ) == 0 );
-
+
BSONElementSet s;
s.insert( a );
ASSERT_EQUALS( 1U , s.size() );
@@ -1563,8 +1563,8 @@ namespace JsobjTests {
ASSERT( s.find( a ) != s.end() );
ASSERT( s.find( b ) != s.end() );
ASSERT( s.find( c ) == s.end() );
-
-
+
+
s.insert( c );
ASSERT_EQUALS( 2U , s.size() );
@@ -1581,7 +1581,7 @@ namespace JsobjTests {
BSONElementSet x;
BSONObj o = fromjson( "{ 'a' : [ 1 , 2 , 1 ] }" );
BSONObjIterator i( o["a"].embeddedObjectUserCheck() );
- while ( i.more() ){
+ while ( i.more() ) {
x.insert( i.next() );
}
ASSERT_EQUALS( 2U , x.size() );
@@ -1591,7 +1591,7 @@ namespace JsobjTests {
class EmbeddedNumbers {
public:
- void run(){
+ void run() {
BSONObj x = BSON( "a" << BSON( "b" << 1 ) );
BSONObj y = BSON( "a" << BSON( "b" << 1.0 ) );
ASSERT_EQUALS( x , y );
@@ -1601,12 +1601,12 @@ namespace JsobjTests {
class BuilderPartialItearte {
public:
- void run(){
+ void run() {
{
BSONObjBuilder b;
b.append( "x" , 1 );
b.append( "y" , 2 );
-
+
BSONObjIterator i = b.iterator();
ASSERT( i.more() );
ASSERT_EQUALS( 1 , i.next().numberInt() );
@@ -1627,13 +1627,13 @@ namespace JsobjTests {
ASSERT_EQUALS( BSON( "x" << 1 << "y" << 2 << "z" << 3 ) , b.obj() );
}
-
+
}
};
class BSONFieldTests {
public:
- void run(){
+ void run() {
{
BSONField<int> x("x");
BSONObj o = BSON( x << 5 );
@@ -1660,11 +1660,11 @@ namespace JsobjTests {
class BSONForEachTest {
public:
- void run(){
+ void run() {
BSONObj obj = BSON("a" << 1 << "a" << 2 << "a" << 3);
-
+
int count = 0;
- BSONForEach(e, obj){
+ BSONForEach(e, obj) {
ASSERT_EQUALS( e.fieldName() , string("a") );
count += e.Int();
}
@@ -1675,7 +1675,7 @@ namespace JsobjTests {
class StringDataTest {
public:
- void run(){
+ void run() {
StringData a( string( "aaa" ) );
ASSERT_EQUALS( 3u , a.size() );
@@ -1695,8 +1695,8 @@ namespace JsobjTests {
class CompareOps {
public:
- void run(){
-
+ void run() {
+
BSONObj a = BSON("a"<<1);
BSONObj b = BSON("a"<<1);
BSONObj c = BSON("a"<<2);
@@ -1707,7 +1707,7 @@ namespace JsobjTests {
ASSERT( ! ( a < b ) );
ASSERT( a <= b );
ASSERT( a < c );
-
+
ASSERT( f > d );
ASSERT( f >= e );
ASSERT( ! ( f > e ) );
@@ -1716,12 +1716,12 @@ namespace JsobjTests {
class HashingTest {
public:
- void run(){
+ void run() {
int N = 100000;
- BSONObj x = BSON( "name" << "eliot was here"
+ BSONObj x = BSON( "name" << "eliot was here"
<< "x" << 5
<< "asdasdasdas" << "asldkasldjasldjasldjlasjdlasjdlasdasdasdasdasdasdasd" );
-
+
{
Timer t;
for ( int i=0; i<N; i++ )
@@ -1729,7 +1729,7 @@ namespace JsobjTests {
int millis = t.millis();
cout << "md5 : " << millis << endl;
}
-
+
{
Timer t;
for ( int i=0; i<N; i++ )
@@ -1744,17 +1744,17 @@ namespace JsobjTests {
checksum( x.objdata() , x.objsize() );
int millis = t.millis();
cout << "checksum : " << millis << endl;
- }
-
+ }
+
}
};
-
+
class All : public Suite {
public:
- All() : Suite( "jsobj" ){
+ All() : Suite( "jsobj" ) {
}
- void setupTests(){
+ void setupTests() {
add< BufBuilderBasic >();
add< BSONElementBasic >();
add< BSONObjTests::Create >();
@@ -1859,6 +1859,6 @@ namespace JsobjTests {
add< HashingTest >();
}
} myall;
-
+
} // namespace JsobjTests
diff --git a/dbtests/jsontests.cpp b/dbtests/jsontests.cpp
index 990558e361c..b63052342ed 100644
--- a/dbtests/jsontests.cpp
+++ b/dbtests/jsontests.cpp
@@ -205,11 +205,11 @@ namespace JsonTests {
b.appendDBRef( "a", "namespace", oid );
BSONObj built = b.done();
ASSERT_EQUALS( "{ \"a\" : { \"$ref\" : \"namespace\", \"$id\" : \"ffffffffffffffffffffffff\" } }",
- built.jsonString( Strict ) );
+ built.jsonString( Strict ) );
ASSERT_EQUALS( "{ \"a\" : { \"$ref\" : \"namespace\", \"$id\" : \"ffffffffffffffffffffffff\" } }",
- built.jsonString( JS ) );
+ built.jsonString( JS ) );
ASSERT_EQUALS( "{ \"a\" : Dbref( \"namespace\", \"ffffffffffffffffffffffff\" ) }",
- built.jsonString( TenGen ) );
+ built.jsonString( TenGen ) );
}
};
@@ -221,7 +221,7 @@ namespace JsonTests {
BSONObjBuilder b;
b.appendDBRef( "a", "namespace", oid );
ASSERT_EQUALS( "{ \"a\" : { \"$ref\" : \"namespace\", \"$id\" : \"000000000000000000000000\" } }",
- b.done().jsonString( Strict ) );
+ b.done().jsonString( Strict ) );
}
};
@@ -234,9 +234,9 @@ namespace JsonTests {
b.appendOID( "a", &oid );
BSONObj built = b.done();
ASSERT_EQUALS( "{ \"a\" : { \"$oid\" : \"ffffffffffffffffffffffff\" } }",
- built.jsonString( Strict ) );
+ built.jsonString( Strict ) );
ASSERT_EQUALS( "{ \"a\" : ObjectId( \"ffffffffffffffffffffffff\" ) }",
- built.jsonString( TenGen ) );
+ built.jsonString( TenGen ) );
}
};
@@ -258,12 +258,12 @@ namespace JsonTests {
BSONObjBuilder c;
c.appendBinData( "a", 2, BinDataGeneral, z );
ASSERT_EQUALS( "{ \"a\" : { \"$binary\" : \"YWI=\", \"$type\" : \"00\" } }",
- c.done().jsonString( Strict ) );
+ c.done().jsonString( Strict ) );
BSONObjBuilder d;
d.appendBinData( "a", 1, BinDataGeneral, z );
ASSERT_EQUALS( "{ \"a\" : { \"$binary\" : \"YQ==\", \"$type\" : \"00\" } }",
- d.done().jsonString( Strict ) );
+ d.done().jsonString( Strict ) );
}
};
@@ -295,7 +295,7 @@ namespace JsonTests {
b.appendRegex( "a", "abc", "i" );
BSONObj built = b.done();
ASSERT_EQUALS( "{ \"a\" : { \"$regex\" : \"abc\", \"$options\" : \"i\" } }",
- built.jsonString( Strict ) );
+ built.jsonString( Strict ) );
ASSERT_EQUALS( "{ \"a\" : /abc/i }", built.jsonString( TenGen ) );
ASSERT_EQUALS( "{ \"a\" : /abc/i }", built.jsonString( JS ) );
}
@@ -308,7 +308,7 @@ namespace JsonTests {
b.appendRegex( "a", "/\"", "i" );
BSONObj built = b.done();
ASSERT_EQUALS( "{ \"a\" : { \"$regex\" : \"/\\\"\", \"$options\" : \"i\" } }",
- built.jsonString( Strict ) );
+ built.jsonString( Strict ) );
ASSERT_EQUALS( "{ \"a\" : /\\/\\\"/i }", built.jsonString( TenGen ) );
ASSERT_EQUALS( "{ \"a\" : /\\/\\\"/i }", built.jsonString( JS ) );
}
@@ -321,7 +321,7 @@ namespace JsonTests {
b.appendRegex( "a", "z", "abcgimx" );
BSONObj built = b.done();
ASSERT_EQUALS( "{ \"a\" : { \"$regex\" : \"z\", \"$options\" : \"abcgimx\" } }",
- built.jsonString( Strict ) );
+ built.jsonString( Strict ) );
ASSERT_EQUALS( "{ \"a\" : /z/gim }", built.jsonString( TenGen ) );
ASSERT_EQUALS( "{ \"a\" : /z/gim }", built.jsonString( JS ) );
}
@@ -329,17 +329,17 @@ namespace JsonTests {
class CodeTests {
public:
- void run(){
+ void run() {
BSONObjBuilder b;
b.appendCode( "x" , "function(){ return 1; }" );
BSONObj o = b.obj();
ASSERT_EQUALS( "{ \"x\" : function(){ return 1; } }" , o.jsonString() );
}
};
-
+
class TimestampTests {
public:
- void run(){
+ void run() {
BSONObjBuilder b;
b.appendTimestamp( "x" , 4000 , 10 );
BSONObj o = b.obj();
@@ -349,7 +349,7 @@ namespace JsonTests {
class NullString {
public:
- void run(){
+ void run() {
BSONObjBuilder b;
b.append( "x" , "a\0b" , 4 );
BSONObj o = b.obj();
@@ -359,7 +359,7 @@ namespace JsonTests {
class AllTypes {
public:
- void run(){
+ void run() {
OID oid;
oid.init();
@@ -384,12 +384,12 @@ namespace JsonTests {
b.appendTimestamp( "s" , 123123123123123LL );
b.append( "t" , 12321312312LL );
b.appendMaxKey( "u" );
-
+
BSONObj o = b.obj();
cout << o.jsonString() << endl;
}
};
-
+
} // namespace JsonStringTests
namespace FromJsonTests {
@@ -504,7 +504,7 @@ namespace JsonTests {
virtual ~FancyNumber() {}
void run() {
ASSERT_EQUALS( int( 1000000 * bson().firstElement().number() ),
- int( 1000000 * fromjson( json() ).firstElement().number() ) );
+ int( 1000000 * fromjson( json() ).firstElement().number() ) );
}
virtual BSONObj bson() const {
BSONObjBuilder b;
@@ -978,8 +978,8 @@ namespace JsonTests {
};
class NumericTypes : public Base {
- public:
- void run(){
+ public:
+ void run() {
Base::run();
BSONObj o = fromjson(json());
@@ -990,12 +990,12 @@ namespace JsonTests {
ASSERT(o["long"].numberLong() == 9223372036854775807ll);
}
-
+
virtual BSONObj bson() const {
return BSON( "int" << 123
- << "long" << 9223372036854775807ll // 2**63 - 1
- << "double" << 3.14
- );
+ << "long" << 9223372036854775807ll // 2**63 - 1
+ << "double" << 3.14
+ );
}
virtual string json() const {
return "{ \"int\": 123, \"long\": 9223372036854775807, \"double\": 3.14 }";
@@ -1003,8 +1003,8 @@ namespace JsonTests {
};
class NegativeNumericTypes : public Base {
- public:
- void run(){
+ public:
+ void run() {
Base::run();
BSONObj o = fromjson(json());
@@ -1015,12 +1015,12 @@ namespace JsonTests {
ASSERT(o["long"].numberLong() == -9223372036854775807ll);
}
-
+
virtual BSONObj bson() const {
return BSON( "int" << -123
- << "long" << -9223372036854775807ll // -1 * (2**63 - 1)
- << "double" << -3.14
- );
+ << "long" << -9223372036854775807ll // -1 * (2**63 - 1)
+ << "double" << -3.14
+ );
}
virtual string json() const {
return "{ \"int\": -123, \"long\": -9223372036854775807, \"double\": -3.14 }";
@@ -1029,8 +1029,8 @@ namespace JsonTests {
class EmbeddedDatesBase : public Base {
public:
-
- virtual void run(){
+
+ virtual void run() {
BSONObj o = fromjson( json() );
ASSERT_EQUALS( 3 , (o["time.valid"].type()) );
BSONObj e = o["time.valid"].embeddedObjectUserCheck();
@@ -1038,7 +1038,7 @@ namespace JsonTests {
ASSERT_EQUALS( 9 , e["$lt"].type() );
Base::run();
}
-
+
BSONObj bson() const {
BSONObjBuilder e;
e.appendDate( "$gt" , 1257829200000LL );
@@ -1082,10 +1082,10 @@ namespace JsonTests {
class All : public Suite {
public:
- All() : Suite( "json" ){
+ All() : Suite( "json" ) {
}
- void setupTests(){
+ void setupTests() {
add< JsonStringTests::Empty >();
add< JsonStringTests::SingleStringMember >();
add< JsonStringTests::EscapedCharacters >();
@@ -1116,7 +1116,7 @@ namespace JsonTests {
add< JsonStringTests::TimestampTests >();
add< JsonStringTests::NullString >();
add< JsonStringTests::AllTypes >();
-
+
add< FromJsonTests::Empty >();
add< FromJsonTests::EmptyWithSpace >();
add< FromJsonTests::SingleString >();
diff --git a/dbtests/jstests.cpp b/dbtests/jstests.cpp
index d502b42aa76..c33b2005b38 100644
--- a/dbtests/jstests.cpp
+++ b/dbtests/jstests.cpp
@@ -1,4 +1,4 @@
-// javajstests.cpp
+// javajstests.cpp
//
/**
@@ -31,7 +31,7 @@ namespace mongo {
} // namespace mongo
namespace JSTests {
-
+
class Fundamental {
public:
void run() {
@@ -43,26 +43,26 @@ namespace JSTests {
globalScriptEngine->runTest();
}
};
-
+
class BasicScope {
public:
- void run(){
+ void run() {
auto_ptr<Scope> s;
s.reset( globalScriptEngine->newScope() );
s->setNumber( "x" , 5 );
ASSERT( 5 == s->getNumber( "x" ) );
-
+
s->setNumber( "x" , 1.67 );
ASSERT( 1.67 == s->getNumber( "x" ) );
s->setString( "s" , "eliot was here" );
ASSERT( "eliot was here" == s->getString( "s" ) );
-
+
s->setBoolean( "b" , true );
ASSERT( s->getBoolean( "b" ) );
- if ( 0 ){
+ if ( 0 ) {
s->setBoolean( "b" , false );
ASSERT( ! s->getBoolean( "b" ) );
}
@@ -71,12 +71,12 @@ namespace JSTests {
class ResetScope {
public:
- void run(){
+ void run() {
// Not worrying about this for now SERVER-446.
/*
auto_ptr<Scope> s;
s.reset( globalScriptEngine->newScope() );
-
+
s->setBoolean( "x" , true );
ASSERT( s->getBoolean( "x" ) );
@@ -85,36 +85,36 @@ namespace JSTests {
*/
}
};
-
+
class FalseTests {
public:
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
ASSERT( ! s->getBoolean( "x" ) );
-
+
s->setString( "z" , "" );
ASSERT( ! s->getBoolean( "z" ) );
-
-
+
+
delete s ;
}
};
class SimpleFunctions {
public:
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
s->invoke( "x=5;" , BSONObj() );
ASSERT( 5 == s->getNumber( "x" ) );
-
+
s->invoke( "return 17;" , BSONObj() );
ASSERT( 17 == s->getNumber( "return" ) );
-
+
s->invoke( "function(){ return 17; }" , BSONObj() );
ASSERT( 17 == s->getNumber( "return" ) );
-
+
s->setNumber( "x" , 1.76 );
s->invoke( "return x == 1.76; " , BSONObj() );
ASSERT( s->getBoolean( "return" ) );
@@ -122,7 +122,7 @@ namespace JSTests {
s->setNumber( "x" , 1.76 );
s->invoke( "return x == 1.79; " , BSONObj() );
ASSERT( ! s->getBoolean( "return" ) );
-
+
s->invoke( "function( z ){ return 5 + z; }" , BSON( "" << 11 ) );
ASSERT_EQUALS( 16 , s->getNumber( "return" ) );
@@ -132,9 +132,9 @@ namespace JSTests {
class ObjectMapping {
public:
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
-
+
BSONObj o = BSON( "x" << 17 << "y" << "eliot" << "z" << "sara" );
s->setObject( "blah" , o );
@@ -155,7 +155,7 @@ namespace JSTests {
s->invoke( "this.z == 'asara';" , BSONObj() );
ASSERT_EQUALS( false , s->getBoolean( "return" ) );
-
+
s->invoke( "return this.x == 17;" , BSONObj() );
ASSERT_EQUALS( true , s->getBoolean( "return" ) );
@@ -170,28 +170,28 @@ namespace JSTests {
s->invoke( "function (){ return this.x == 17; }" , BSONObj() );
ASSERT_EQUALS( true , s->getBoolean( "return" ) );
-
+
s->invoke( "function z(){ return this.x == 18; }" , BSONObj() );
ASSERT_EQUALS( false , s->getBoolean( "return" ) );
s->invoke( "function (){ this.x == 17; }" , BSONObj() );
ASSERT_EQUALS( false , s->getBoolean( "return" ) );
-
+
s->invoke( "function z(){ this.x == 18; }" , BSONObj() );
ASSERT_EQUALS( false , s->getBoolean( "return" ) );
s->invoke( "x = 5; for( ; x <10; x++){ a = 1; }" , BSONObj() );
ASSERT_EQUALS( 10 , s->getNumber( "x" ) );
-
+
delete s;
}
};
class ObjectDecoding {
public:
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
-
+
s->invoke( "z = { num : 1 };" , BSONObj() );
BSONObj out = s->getObject( "z" );
ASSERT_EQUALS( 1 , out["num"].number() );
@@ -201,43 +201,43 @@ namespace JSTests {
out = s->getObject( "z" );
ASSERT_EQUALS( (string)"eliot" , out["x"].valuestr() );
ASSERT_EQUALS( 1 , out.nFields() );
-
+
BSONObj o = BSON( "x" << 17 );
- s->setObject( "blah" , o );
+ s->setObject( "blah" , o );
out = s->getObject( "blah" );
ASSERT_EQUALS( 17 , out["x"].number() );
-
+
delete s;
}
};
-
+
class JSOIDTests {
public:
- void run(){
+ void run() {
#ifdef MOZJS
Scope * s = globalScriptEngine->newScope();
-
+
s->localConnect( "blah" );
-
+
s->invoke( "z = { _id : new ObjectId() , a : 123 };" , BSONObj() );
BSONObj out = s->getObject( "z" );
ASSERT_EQUALS( 123 , out["a"].number() );
ASSERT_EQUALS( jstOID , out["_id"].type() );
-
+
OID save = out["_id"].__oid();
-
+
s->setObject( "a" , out );
-
- s->invoke( "y = { _id : a._id , a : 124 };" , BSONObj() );
+
+ s->invoke( "y = { _id : a._id , a : 124 };" , BSONObj() );
out = s->getObject( "y" );
ASSERT_EQUALS( 124 , out["a"].number() );
- ASSERT_EQUALS( jstOID , out["_id"].type() );
+ ASSERT_EQUALS( jstOID , out["_id"].type() );
ASSERT_EQUALS( out["_id"].__oid().str() , save.str() );
- s->invoke( "y = { _id : new ObjectId( a._id ) , a : 125 };" , BSONObj() );
+ s->invoke( "y = { _id : new ObjectId( a._id ) , a : 125 };" , BSONObj() );
out = s->getObject( "y" );
ASSERT_EQUALS( 125 , out["a"].number() );
- ASSERT_EQUALS( jstOID , out["_id"].type() );
+ ASSERT_EQUALS( jstOID , out["_id"].type() );
ASSERT_EQUALS( out["_id"].__oid().str() , save.str() );
delete s;
@@ -268,9 +268,9 @@ namespace JSTests {
class ObjectModReadonlyTests {
public:
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
-
+
BSONObj o = BSON( "x" << 17 << "y" << "eliot" << "z" << "sara" << "zz" << BSONObj() );
s->setObject( "blah" , o , true );
@@ -289,16 +289,16 @@ namespace JSTests {
s->setObject( "blah.zz", BSON( "a" << 19 ) );
out = s->getObject( "blah" );
ASSERT( out["zz"].embeddedObject()["a"].eoo() );
-
+
s->invoke( "delete blah['x']" , BSONObj() );
out = s->getObject( "blah" );
ASSERT( !out["x"].eoo() );
-
+
// read-only object itself can be overwritten
s->invoke( "blah = {}", BSONObj() );
out = s->getObject( "blah" );
ASSERT( out.isEmpty() );
-
+
// test array - can't implement this in v8
// o = fromjson( "{a:[1,2,3]}" );
// s->setObject( "blah", o, true );
@@ -308,45 +308,47 @@ namespace JSTests {
// out = s->getObject( "blah" );
// ASSERT_EQUALS( 1.0, out[ "a" ].embeddedObject()[ 0 ].number() );
// ASSERT_EQUALS( 3.0, out[ "a" ].embeddedObject()[ 2 ].number() );
-
+
delete s;
}
};
class OtherJSTypes {
public:
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
-
- { // date
+
+ {
+ // date
BSONObj o;
- {
+ {
BSONObjBuilder b;
b.appendDate( "d" , 123456789 );
o = b.obj();
}
s->setObject( "x" , o );
-
+
s->invoke( "return x.d.getTime() != 12;" , BSONObj() );
ASSERT_EQUALS( true, s->getBoolean( "return" ) );
-
+
s->invoke( "z = x.d.getTime();" , BSONObj() );
ASSERT_EQUALS( 123456789 , s->getNumber( "z" ) );
-
+
s->invoke( "z = { z : x.d }" , BSONObj() );
BSONObj out = s->getObject( "z" );
ASSERT( out["z"].type() == Date );
}
- { // regex
+ {
+ // regex
BSONObj o;
- {
+ {
BSONObjBuilder b;
b.appendRegex( "r" , "^a" , "i" );
o = b.obj();
}
s->setObject( "x" , o );
-
+
s->invoke( "z = x.r.test( 'b' );" , BSONObj() );
ASSERT_EQUALS( false , s->getBoolean( "z" ) );
@@ -363,26 +365,26 @@ namespace JSTests {
ASSERT_EQUALS( (string)"i" , out["a"].regexFlags() );
}
-
+
// array
{
BSONObj o = fromjson( "{r:[1,2,3]}" );
- s->setObject( "x", o, false );
+ s->setObject( "x", o, false );
BSONObj out = s->getObject( "x" );
ASSERT_EQUALS( Array, out.firstElement().type() );
- s->setObject( "x", o, true );
+ s->setObject( "x", o, true );
out = s->getObject( "x" );
ASSERT_EQUALS( Array, out.firstElement().type() );
}
-
+
delete s;
}
};
class SpecialDBTypes {
public:
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
BSONObjBuilder b;
@@ -390,7 +392,7 @@ namespace JSTests {
b.appendMinKey( "b" );
b.appendMaxKey( "c" );
b.appendTimestamp( "d" , 1234000 , 9876 );
-
+
{
BSONObj t = b.done();
@@ -399,7 +401,7 @@ namespace JSTests {
}
s->setObject( "z" , b.obj() );
-
+
ASSERT( s->invoke( "y = { a : z.a , b : z.b , c : z.c , d: z.d }" , BSONObj() ) == 0 );
BSONObj out = s->getObject( "y" );
@@ -415,14 +417,14 @@ namespace JSTests {
delete s;
}
};
-
+
class TypeConservation {
public:
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
-
+
// -- A --
-
+
BSONObj o;
{
BSONObjBuilder b ;
@@ -432,7 +434,7 @@ namespace JSTests {
}
ASSERT_EQUALS( NumberInt , o["a"].type() );
ASSERT_EQUALS( NumberDouble , o["b"].type() );
-
+
s->setObject( "z" , o );
s->invoke( "return z" , BSONObj() );
BSONObj out = s->getObject( "return" );
@@ -443,7 +445,7 @@ namespace JSTests {
ASSERT_EQUALS( NumberInt , out["a"].type() );
// -- B --
-
+
{
BSONObjBuilder b ;
b.append( "a" , (int)5 );
@@ -460,31 +462,31 @@ namespace JSTests {
ASSERT_EQUALS( NumberDouble , out["b"].type() );
ASSERT_EQUALS( NumberInt , out["a"].type() );
-
+
// -- C --
-
+
{
BSONObjBuilder b ;
-
+
{
BSONObjBuilder c;
c.append( "0" , 5.5 );
c.append( "1" , 6 );
b.appendArray( "a" , c.obj() );
}
-
+
o = b.obj();
}
-
+
ASSERT_EQUALS( NumberDouble , o["a"].embeddedObjectUserCheck()["0"].type() );
ASSERT_EQUALS( NumberInt , o["a"].embeddedObjectUserCheck()["1"].type() );
-
+
s->setObject( "z" , o , false );
out = s->getObject( "z" );
ASSERT_EQUALS( NumberDouble , out["a"].embeddedObjectUserCheck()["0"].type() );
ASSERT_EQUALS( NumberInt , out["a"].embeddedObjectUserCheck()["1"].type() );
-
+
s->invokeSafe( "z.z = 5;" , BSONObj() );
out = s->getObject( "z" );
ASSERT_EQUALS( 5 , out["z"].number() );
@@ -494,9 +496,9 @@ namespace JSTests {
// Eliot says I don't have to worry about this case
-
+
// // -- D --
-//
+//
// o = fromjson( "{a:3.0,b:4.5}" );
// ASSERT_EQUALS( NumberDouble , o["a"].type() );
// ASSERT_EQUALS( NumberDouble , o["b"].type() );
@@ -506,16 +508,16 @@ namespace JSTests {
// out = s->getObject( "return" );
// ASSERT_EQUALS( 3 , out["a"].number() );
// ASSERT_EQUALS( 4.5 , out["b"].number() );
-//
+//
// ASSERT_EQUALS( NumberDouble , out["b"].type() );
// ASSERT_EQUALS( NumberDouble , out["a"].type() );
-//
-
+//
+
delete s;
}
-
+
};
-
+
class NumberLong {
public:
void run() {
@@ -528,7 +530,7 @@ namespace JSTests {
s->setObject( "a", in );
BSONObj out = s->getObject( "a" );
ASSERT_EQUALS( mongo::NumberLong, out.firstElement().type() );
-
+
ASSERT( s->exec( "printjson( a ); b = {b:a.a}", "foo", false, true, false ) );
out = s->getObject( "b" );
ASSERT_EQUALS( mongo::NumberLong, out.firstElement().type() );
@@ -538,7 +540,7 @@ namespace JSTests {
cout << out.toString() << endl;
ASSERT_EQUALS( val, out.firstElement().numberLong() );
}
-
+
ASSERT( s->exec( "c = {c:a.a.toString()}", "foo", false, true, false ) );
out = s->getObject( "c" );
stringstream ss;
@@ -553,12 +555,12 @@ namespace JSTests {
ASSERT( s->exec( "e = {e:a.a.floatApprox}", "foo", false, true, false ) );
out = s->getObject( "e" );
ASSERT_EQUALS( NumberDouble, out.firstElement().type() );
- ASSERT_EQUALS( double( val ), out.firstElement().number() );
+ ASSERT_EQUALS( double( val ), out.firstElement().number() );
ASSERT( s->exec( "f = {f:a.a.top}", "foo", false, true, false ) );
out = s->getObject( "f" );
ASSERT( NumberDouble == out.firstElement().type() || NumberInt == out.firstElement().type() );
-
+
s->setObject( "z", BSON( "z" << (long long)( 4 ) ) );
ASSERT( s->exec( "y = {y:z.z.top}", "foo", false, true, false ) );
out = s->getObject( "y" );
@@ -567,13 +569,13 @@ namespace JSTests {
ASSERT( s->exec( "x = {x:z.z.floatApprox}", "foo", false, true, false ) );
out = s->getObject( "x" );
ASSERT( NumberDouble == out.firstElement().type() || NumberInt == out.firstElement().type() );
- ASSERT_EQUALS( double( 4 ), out.firstElement().number() );
+ ASSERT_EQUALS( double( 4 ), out.firstElement().number() );
ASSERT( s->exec( "w = {w:z.z}", "foo", false, true, false ) );
out = s->getObject( "w" );
ASSERT_EQUALS( mongo::NumberLong, out.firstElement().type() );
- ASSERT_EQUALS( 4, out.firstElement().numberLong() );
-
+ ASSERT_EQUALS( 4, out.firstElement().numberLong() );
+
}
};
@@ -582,7 +584,7 @@ namespace JSTests {
void run() {
auto_ptr<Scope> s( globalScriptEngine->newScope() );
s->localConnect( "blah" );
-
+
BSONObj in;
{
BSONObjBuilder b;
@@ -595,7 +597,7 @@ namespace JSTests {
in = b.obj();
}
s->setObject( "a" , in );
-
+
ASSERT( s->exec( "x = tojson( a ); " ,"foo" , false , true , false ) );
string outString = s->getString( "x" );
@@ -604,27 +606,27 @@ namespace JSTests {
ASSERT_EQUALS( in , out );
}
};
-
+
class WeirdObjects {
public:
- BSONObj build( int depth ){
+ BSONObj build( int depth ) {
BSONObjBuilder b;
b.append( "0" , depth );
if ( depth > 0 )
b.appendArray( "1" , build( depth - 1 ) );
return b.obj();
}
-
- void run(){
+
+ void run() {
Scope * s = globalScriptEngine->newScope();
s->localConnect( "blah" );
-
- for ( int i=5; i<100 ; i += 10 ){
+
+ for ( int i=5; i<100 ; i += 10 ) {
s->setObject( "a" , build(i) , false );
s->invokeSafe( "tojson( a )" , BSONObj() );
-
+
s->setObject( "a" , build(5) , true );
s->invokeSafe( "tojson( a )" , BSONObj() );
}
@@ -643,7 +645,7 @@ namespace JSTests {
}
DBDirectClient client;
-
+
class Utf8Check {
public:
Utf8Check() { reset(); }
@@ -668,7 +670,7 @@ namespace JSTests {
}
void reset() {
client.dropCollection( ns() );
- }
+ }
static const char *ns() { return "unittest.jstests.utf8check"; }
};
@@ -684,13 +686,13 @@ namespace JSTests {
private:
void reset() {
client.dropCollection( ns() );
- }
+ }
static const char *ns() { return "unittest.jstests.longutf8string"; }
};
class InvalidUTF8Check {
public:
- void run(){
+ void run() {
if( !globalScriptEngine->utf8Ok() )
return;
@@ -706,24 +708,24 @@ namespace JSTests {
crap[2] = (char) 128;
crap[3] = 17;
crap[4] = 0;
-
+
BSONObjBuilder bb;
bb.append( "x" , crap );
b = bb.obj();
}
-
+
//cout << "ELIOT: " << b.jsonString() << endl;
s->setThis( &b );
// its ok if this is handled by js, just can't create a c++ exception
- s->invoke( "x=this.x.length;" , BSONObj() );
+ s->invoke( "x=this.x.length;" , BSONObj() );
}
};
-
+
class CodeTests {
public:
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
-
+
{
BSONObjBuilder b;
b.append( "a" , 1 );
@@ -732,10 +734,10 @@ namespace JSTests {
b.appendCodeWScope( "d" , "function(){ out.d = 13 + bleh; }" , BSON( "bleh" << 5 ) );
s->setObject( "foo" , b.obj() );
}
-
+
s->invokeSafe( "out = {}; out.a = foo.a; foo.b(); foo.c();" , BSONObj() );
BSONObj out = s->getObject( "out" );
-
+
ASSERT_EQUALS( 1 , out["a"].number() );
ASSERT_EQUALS( 11 , out["b"].number() );
ASSERT_EQUALS( 12 , out["c"].number() );
@@ -744,7 +746,7 @@ namespace JSTests {
//s->invokeSafe( "foo.d() " , BSONObj() );
//out = s->getObject( "out" );
//ASSERT_EQUALS( 18 , out["d"].number() );
-
+
delete s;
}
@@ -752,19 +754,19 @@ namespace JSTests {
class DBRefTest {
public:
- DBRefTest(){
+ DBRefTest() {
_a = "unittest.dbref.a";
_b = "unittest.dbref.b";
reset();
}
- ~DBRefTest(){
+ ~DBRefTest() {
//reset();
}
-
- void run(){
+
+ void run() {
client.insert( _a , BSON( "a" << "17" ) );
-
+
{
BSONObj fromA = client.findOne( _a , BSONObj() );
assert( fromA.valid() );
@@ -774,28 +776,28 @@ namespace JSTests {
b.appendDBRef( "c" , "dbref.a" , fromA["_id"].__oid() );
client.insert( _b , b.obj() );
}
-
+
ASSERT( client.eval( "unittest" , "x = db.dbref.b.findOne(); assert.eq( 17 , x.c.fetch().a , 'ref working' );" ) );
-
+
// BSON DBRef <=> JS DBPointer
ASSERT( client.eval( "unittest", "x = db.dbref.b.findOne(); db.dbref.b.drop(); x.c = new DBPointer( x.c.ns, x.c.id ); db.dbref.b.insert( x );" ) );
ASSERT_EQUALS( DBRef, client.findOne( "unittest.dbref.b", "" )[ "c" ].type() );
-
+
// BSON Object <=> JS DBRef
ASSERT( client.eval( "unittest", "x = db.dbref.b.findOne(); db.dbref.b.drop(); x.c = new DBRef( x.c.ns, x.c.id ); db.dbref.b.insert( x );" ) );
ASSERT_EQUALS( Object, client.findOne( "unittest.dbref.b", "" )[ "c" ].type() );
ASSERT_EQUALS( string( "dbref.a" ), client.findOne( "unittest.dbref.b", "" )[ "c" ].embeddedObject().getStringField( "$ref" ) );
}
-
- void reset(){
+
+ void reset() {
client.dropCollection( _a );
client.dropCollection( _b );
}
-
+
const char * _a;
const char * _b;
};
-
+
class InformalDBRef {
public:
void run() {
@@ -805,20 +807,20 @@ namespace JSTests {
client.insert( ns(), BSON( "r" << BSON( "$ref" << "jstests.informaldbref" << "$id" << obj["_id"].__oid() << "foo" << "bar" ) ) );
obj = client.findOne( ns(), BSONObj() );
ASSERT_EQUALS( "bar", obj[ "r" ].embeddedObject()[ "foo" ].str() );
-
+
ASSERT( client.eval( "unittest", "x = db.jstests.informaldbref.findOne(); y = { r:x.r }; db.jstests.informaldbref.drop(); y.r[ \"a\" ] = \"b\"; db.jstests.informaldbref.save( y );" ) );
obj = client.findOne( ns(), BSONObj() );
- ASSERT_EQUALS( "bar", obj[ "r" ].embeddedObject()[ "foo" ].str() );
- ASSERT_EQUALS( "b", obj[ "r" ].embeddedObject()[ "a" ].str() );
+ ASSERT_EQUALS( "bar", obj[ "r" ].embeddedObject()[ "foo" ].str() );
+ ASSERT_EQUALS( "b", obj[ "r" ].embeddedObject()[ "a" ].str() );
}
private:
static const char *ns() { return "unittest.jstests.informaldbref"; }
};
-
+
class BinDataType {
public:
-
- void pp( const char * s , BSONElement e ){
+
+ void pp( const char * s , BSONElement e ) {
int len;
const char * data = e.binData( len );
cout << s << ":" << e.binDataType() << "\t" << len << endl;
@@ -828,12 +830,12 @@ namespace JSTests {
cout << endl;
}
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
s->localConnect( "asd" );
const char * foo = "asdas\0asdasd";
const char * base64 = "YXNkYXMAYXNkYXNk";
-
+
BSONObj in;
{
BSONObjBuilder b;
@@ -842,10 +844,10 @@ namespace JSTests {
in = b.obj();
s->setObject( "x" , in );
}
-
+
s->invokeSafe( "myb = x.b; print( myb ); printjson( myb );" , BSONObj() );
s->invokeSafe( "y = { c : myb };" , BSONObj() );
-
+
BSONObj out = s->getObject( "y" );
ASSERT_EQUALS( BinData , out["c"].type() );
// pp( "in " , in["b"] );
@@ -857,14 +859,14 @@ namespace JSTests {
stringstream expected;
expected << "BinData(" << BinDataGeneral << ",\"" << base64 << "\")";
ASSERT_EQUALS( expected.str(), s->getString( "q" ) );
-
+
stringstream scriptBuilder;
scriptBuilder << "z = { c : new BinData( " << BinDataGeneral << ", \"" << base64 << "\" ) };";
string script = scriptBuilder.str();
s->invokeSafe( script.c_str(), BSONObj() );
out = s->getObject( "z" );
// pp( "out" , out["c"] );
- ASSERT_EQUALS( 0 , in["b"].woCompare( out["c"] , false ) );
+ ASSERT_EQUALS( 0 , in["b"].woCompare( out["c"] , false ) );
s->invokeSafe( "a = { f: new BinData( 128, \"\" ) };", BSONObj() );
out = s->getObject( "a" );
@@ -872,16 +874,16 @@ namespace JSTests {
out[ "f" ].binData( len );
ASSERT_EQUALS( 0, len );
ASSERT_EQUALS( 128, out[ "f" ].binDataType() );
-
+
delete s;
}
};
class VarTests {
public:
- void run(){
+ void run() {
Scope * s = globalScriptEngine->newScope();
-
+
ASSERT( s->exec( "a = 5;" , "a" , false , true , false ) );
ASSERT_EQUALS( 5 , s->getNumber("a" ) );
@@ -893,19 +895,19 @@ namespace JSTests {
class Speed1 {
public:
- void run(){
+ void run() {
BSONObj start = BSON( "x" << 5 );
BSONObj empty;
auto_ptr<Scope> s;
s.reset( globalScriptEngine->newScope() );
-
+
ScriptingFunction f = s->createFunction( "return this.x + 6;" );
s->setThis( &start );
-
+
Timer t;
double n = 0;
- for ( ; n < 100000; n++ ){
+ for ( ; n < 100000; n++ ) {
s->invoke( f , empty );
ASSERT_EQUALS( 11 , s->getNumber( "return" ) );
}
@@ -915,10 +917,10 @@ namespace JSTests {
class ScopeOut {
public:
- void run(){
+ void run() {
auto_ptr<Scope> s;
s.reset( globalScriptEngine->newScope() );
-
+
s->invokeSafe( "x = 5;" , BSONObj() );
{
BSONObjBuilder b;
@@ -942,14 +944,14 @@ namespace JSTests {
class RenameTest {
public:
- void run(){
+ void run() {
auto_ptr<Scope> s;
s.reset( globalScriptEngine->newScope() );
-
+
s->setNumber( "x" , 5 );
ASSERT_EQUALS( 5 , s->getNumber( "x" ) );
ASSERT_EQUALS( Undefined , s->type( "y" ) );
-
+
s->rename( "x" , "y" );
ASSERT_EQUALS( 5 , s->getNumber( "y" ) );
ASSERT_EQUALS( Undefined , s->type( "x" ) );
@@ -959,20 +961,20 @@ namespace JSTests {
ASSERT_EQUALS( Undefined , s->type( "y" ) );
}
};
-
+
class All : public Suite {
public:
All() : Suite( "js" ) {
}
-
- void setupTests(){
+
+ void setupTests() {
add< Fundamental >();
add< BasicScope >();
add< ResetScope >();
add< FalseTests >();
add< SimpleFunctions >();
-
+
add< ObjectMapping >();
add< ObjectDecoding >();
add< JSOIDTests >();
@@ -990,9 +992,9 @@ namespace JSTests {
add< DBRefTest >();
add< InformalDBRef >();
add< BinDataType >();
-
+
add< VarTests >();
-
+
add< Speed1 >();
add< InvalidUTF8Check >();
@@ -1002,6 +1004,6 @@ namespace JSTests {
add< ScopeOut >();
}
} myall;
-
+
} // namespace JavaJSTests
diff --git a/dbtests/matchertests.cpp b/dbtests/matchertests.cpp
index e418343712b..380b8b802d4 100644
--- a/dbtests/matchertests.cpp
+++ b/dbtests/matchertests.cpp
@@ -37,26 +37,26 @@ namespace MatcherTests {
ASSERT( m.matches( fromjson( "{\"a\":\"b\"}" ) ) );
}
};
-
+
class DoubleEqual {
public:
void run() {
BSONObj query = fromjson( "{\"a\":5}" );
Matcher m( query );
- ASSERT( m.matches( fromjson( "{\"a\":5}" ) ) );
+ ASSERT( m.matches( fromjson( "{\"a\":5}" ) ) );
}
};
-
+
class MixedNumericEqual {
public:
void run() {
BSONObjBuilder query;
query.append( "a", 5 );
Matcher m( query.done() );
- ASSERT( m.matches( fromjson( "{\"a\":5}" ) ) );
- }
+ ASSERT( m.matches( fromjson( "{\"a\":5}" ) ) );
+ }
};
-
+
class MixedNumericGt {
public:
void run() {
@@ -65,16 +65,16 @@ namespace MatcherTests {
BSONObjBuilder b;
b.append( "a", 5 );
ASSERT( m.matches( b.done() ) );
- }
+ }
};
-
+
class MixedNumericIN {
public:
- void run(){
+ void run() {
BSONObj query = fromjson( "{ a : { $in : [4,6] } }" );
ASSERT_EQUALS( 4 , query["a"].embeddedObject()["$in"].embeddedObject()["0"].number() );
ASSERT_EQUALS( NumberInt , query["a"].embeddedObject()["$in"].embeddedObject()["0"].type() );
-
+
Matcher m( query );
{
@@ -95,19 +95,19 @@ namespace MatcherTests {
b.append( "a" , 4 );
ASSERT( m.matches( b.done() ) );
}
-
+
}
};
class MixedNumericEmbedded {
public:
- void run(){
+ void run() {
Matcher m( BSON( "a" << BSON( "x" << 1 ) ) );
ASSERT( m.matches( BSON( "a" << BSON( "x" << 1 ) ) ) );
ASSERT( m.matches( BSON( "a" << BSON( "x" << 1.0 ) ) ) );
}
};
-
+
class Size {
public:
void run() {
@@ -116,16 +116,16 @@ namespace MatcherTests {
ASSERT( !m.matches( fromjson( "{a:[1,2,3]}" ) ) );
ASSERT( !m.matches( fromjson( "{a:[1,2,3,'a','b']}" ) ) );
ASSERT( !m.matches( fromjson( "{a:[[1,2,3,4]]}" ) ) );
- }
+ }
};
-
-
+
+
class TimingBase {
public:
- long time( const BSONObj& patt , const BSONObj& obj ){
+ long time( const BSONObj& patt , const BSONObj& obj ) {
Matcher m( patt );
Timer t;
- for ( int i=0; i<10000; i++ ){
+ for ( int i=0; i<10000; i++ ) {
ASSERT( m.matches( obj ) );
}
return t.millis();
@@ -134,20 +134,20 @@ namespace MatcherTests {
class AllTiming : public TimingBase {
public:
- void run(){
+ void run() {
long normal = time( BSON( "x" << 5 ) , BSON( "x" << 5 ) );
long all = time( BSON( "x" << BSON( "$all" << BSON_ARRAY( 5 ) ) ) , BSON( "x" << 5 ) );
-
+
cout << "normal: " << normal << " all: " << all << endl;
}
};
class All : public Suite {
public:
- All() : Suite( "matcher" ){
+ All() : Suite( "matcher" ) {
}
-
- void setupTests(){
+
+ void setupTests() {
add< Basic >();
add< DoubleEqual >();
add< MixedNumericEqual >();
@@ -158,6 +158,6 @@ namespace MatcherTests {
add< AllTiming >();
}
} dball;
-
+
} // namespace MatcherTests
diff --git a/dbtests/mmaptests.cpp b/dbtests/mmaptests.cpp
index e83bf45d599..2773987d276 100755..100644
--- a/dbtests/mmaptests.cpp
+++ b/dbtests/mmaptests.cpp
@@ -26,15 +26,17 @@ namespace MMapTests {
class LeakTest {
const string fn;
public:
- LeakTest() :
- fn( (path(dbpath) / "testfile.map").string() )
+ LeakTest() :
+ fn( (path(dbpath) / "testfile.map").string() )
{ }
- ~LeakTest() {
- try { boost::filesystem::remove(fn); } catch(...) { }
+ ~LeakTest() {
+ try { boost::filesystem::remove(fn); }
+ catch(...) { }
}
void run() {
- try { boost::filesystem::remove(fn); } catch(...) { }
+ try { boost::filesystem::remove(fn); }
+ catch(...) { }
writelock lk;
@@ -48,7 +50,7 @@ namespace MMapTests {
// write something to the private view as a test
strcpy(p, "hello");
}
- if( cmdLine.dur ) {
+ if( cmdLine.dur ) {
char *w = (char *) f.view_write();
strcpy(w + 6, "world");
}
@@ -77,24 +79,24 @@ namespace MMapTests {
assert(p);
strcpy(p, "zzz");
}
- if( cmdLine.dur ) {
+ if( cmdLine.dur ) {
char *w = (char *) f.view_write();
if( i % 2 == 0 )
++(*w);
assert( w[6] == 'w' );
}
}
- if( t.millis() > 10000 ) {
+ if( t.millis() > 10000 ) {
log() << "warning: MMap LeakTest is unusually slow N:" << N << ' ' << t.millis() << "ms" << endl;
}
}
};
-
+
class All : public Suite {
public:
- All() : Suite( "mmap" ){}
- void setupTests(){
+ All() : Suite( "mmap" ) {}
+ void setupTests() {
add< LeakTest >();
}
} myall;
@@ -139,10 +141,10 @@ namespace MMapTests {
cout << "view unview: " << t.millis() << "ms" << endl;
}
- f.flush(true);
+ f.flush(true);
/* plain old mmaped writes */
- {
+ {
Timer t;
for( int i = 0; i < 10; i++ ) {
memset(p+100, 'c', 200 * 1024 * 1024);
@@ -150,10 +152,10 @@ namespace MMapTests {
cout << "traditional writes: " << t.millis() << "ms" << endl;
}
- f.flush(true);
+ f.flush(true);
/* test doing some writes */
- {
+ {
Timer t;
char *q = (char *) f.testGetCopyOnWriteView();
for( int i = 0; i < 10; i++ ) {
@@ -166,7 +168,7 @@ namespace MMapTests {
}
/* test doing some writes */
- {
+ {
Timer t;
for( int i = 0; i < 10; i++ ) {
char *q = (char *) f.testGetCopyOnWriteView();
@@ -179,7 +181,7 @@ namespace MMapTests {
}
/* more granular */
- {
+ {
Timer t;
for( int i = 0; i < 100; i++ ) {
char *q = (char *) f.testGetCopyOnWriteView();
@@ -189,17 +191,17 @@ namespace MMapTests {
}
cout << "more granular some writes: " << t.millis() << "ms" << endl;
- }
+ }
- p[10] = 0;
- cout << p << endl;
+ p[10] = 0;
+ cout << p << endl;
}
};
-
+
class All : public Suite {
public:
- All() : Suite( "mmap" ){}
- void setupTests(){
+ All() : Suite( "mmap" ) {}
+ void setupTests() {
add< CopyOnWriteSpeedTest >();
}
} myall;
diff --git a/dbtests/mockdbclient.h b/dbtests/mockdbclient.h
index 9119075b9ba..fda09630a18 100644
--- a/dbtests/mockdbclient.h
+++ b/dbtests/mockdbclient.h
@@ -64,8 +64,8 @@ public:
virtual void afterCommand() {}
};
DirectDBClientConnection( ReplPair *rp, ConnectionCallback *cc = 0 ) :
- rp_( rp ),
- cc_( cc ) {
+ rp_( rp ),
+ cc_( cc ) {
}
virtual BSONObj findOne(const string &ns, const Query& query, const BSONObj *fieldsToReturn = 0, int queryOptions = 0) {
BSONObj c = query.obj.copy();
diff --git a/dbtests/namespacetests.cpp b/dbtests/namespacetests.cpp
index 3ebb8d1d34b..c2be0b0439e 100644
--- a/dbtests/namespacetests.cpp
+++ b/dbtests/namespacetests.cpp
@@ -32,7 +32,7 @@ namespace NamespaceTests {
dblock lk;
Client::Context _context;
public:
- Base() : _context(ns()){
+ Base() : _context(ns()) {
}
virtual ~Base() {
if ( id_.info.isNull() )
@@ -323,7 +323,7 @@ namespace NamespaceTests {
return k.obj();
}
};
-
+
class ArraySubobjectSingleMissing : public Base {
public:
void run() {
@@ -336,7 +336,7 @@ namespace NamespaceTests {
elts.push_back( simpleBC( i ) );
BSONObjBuilder b;
b.append( "a", elts );
-
+
BSONObjSetDefaultOrder keys;
id().getKeysFromObject( b.done(), keys );
checkSize( 4, keys );
@@ -353,7 +353,7 @@ namespace NamespaceTests {
return aDotB();
}
};
-
+
class ArraySubobjectMissing : public Base {
public:
void run() {
@@ -376,7 +376,7 @@ namespace NamespaceTests {
return aDotB();
}
};
-
+
class MissingField : public Base {
public:
void run() {
@@ -391,7 +391,7 @@ namespace NamespaceTests {
return BSON( "a" << 1 );
}
};
-
+
class SubobjectMissing : public Base {
public:
void run() {
@@ -406,12 +406,12 @@ namespace NamespaceTests {
return aDotB();
}
};
-
+
class CompoundMissing : public Base {
public:
- void run(){
+ void run() {
create();
-
+
{
BSONObjSetDefaultOrder keys;
id().getKeysFromObject( fromjson( "{x:'a',y:'b'}" ) , keys );
@@ -428,16 +428,16 @@ namespace NamespaceTests {
b.appendNull( "" );
assertEquals( b.obj() , *keys.begin() );
}
-
+
}
private:
virtual BSONObj key() const {
return BSON( "x" << 1 << "y" << 1 );
}
-
+
};
-
+
class ArraySubelementComplex : public Base {
public:
void run() {
@@ -508,17 +508,17 @@ namespace NamespaceTests {
return aDotB();
}
};
-
+
class EmptyArray : Base {
public:
- void run(){
+ void run() {
create();
BSONObjSetDefaultOrder keys;
id().getKeysFromObject( fromjson( "{a:[1,2]}" ), keys );
checkSize(2, keys );
keys.clear();
-
+
id().getKeysFromObject( fromjson( "{a:[1]}" ), keys );
checkSize(1, keys );
keys.clear();
@@ -535,14 +535,14 @@ namespace NamespaceTests {
class MultiEmptyArray : Base {
public:
- void run(){
+ void run() {
create();
BSONObjSetDefaultOrder keys;
id().getKeysFromObject( fromjson( "{a:1,b:[1,2]}" ), keys );
checkSize(2, keys );
keys.clear();
-
+
id().getKeysFromObject( fromjson( "{a:1,b:[1]}" ), keys );
checkSize(1, keys );
keys.clear();
@@ -551,7 +551,7 @@ namespace NamespaceTests {
//cout << "YO : " << *(keys.begin()) << endl;
checkSize(1, keys );
keys.clear();
-
+
id().getKeysFromObject( fromjson( "{a:1,b:[]}" ), keys );
checkSize(1, keys );
//cout << "YO : " << *(keys.begin()) << endl;
@@ -600,7 +600,7 @@ namespace NamespaceTests {
if ( fileNo == -1 )
continue;
for ( int j = i.ext()->firstRecord.getOfs(); j != DiskLoc::NullOfs;
- j = DiskLoc( fileNo, j ).rec()->nextOfs ) {
+ j = DiskLoc( fileNo, j ).rec()->nextOfs ) {
++count;
}
}
@@ -700,7 +700,7 @@ namespace NamespaceTests {
}
};
- /* test NamespaceDetails::cappedTruncateAfter(const char *ns, DiskLoc loc)
+ /* test NamespaceDetails::cappedTruncateAfter(const char *ns, DiskLoc loc)
*/
class TruncateCapped : public Base {
virtual string spec() const {
@@ -820,15 +820,15 @@ namespace NamespaceTests {
ASSERT_EQUALS( 496U, sizeof( NamespaceDetails ) );
}
};
-
+
} // namespace NamespaceDetailsTests
class All : public Suite {
public:
- All() : Suite( "namespace" ){
+ All() : Suite( "namespace" ) {
}
- void setupTests(){
+ void setupTests() {
add< IndexDetailsTests::Create >();
add< IndexDetailsTests::GetKeysFromObjectSimple >();
add< IndexDetailsTests::GetKeysFromObjectDotted >();
diff --git a/dbtests/pairingtests.cpp b/dbtests/pairingtests.cpp
index 68d4c0ee215..9cca5480efe 100644
--- a/dbtests/pairingtests.cpp
+++ b/dbtests/pairingtests.cpp
@@ -37,7 +37,7 @@ namespace PairingTests {
~Base() {
pairSync = backup;
dblock lk;
- Helpers::emptyCollection( "local.pair.sync" );
+ Helpers::emptyCollection( "local.pair.sync" );
if ( pairSync->initialSyncCompleted() ) {
// save to db
pairSync->setInitialSyncCompleted();
@@ -63,7 +63,7 @@ namespace PairingTests {
private:
static void init() {
dblock lk;
- Helpers::emptyCollection( "local.pair.sync" );
+ Helpers::emptyCollection( "local.pair.sync" );
if ( synced != 0 && notSynced != 0 )
return;
notSynced = new PairSync();
@@ -71,7 +71,7 @@ namespace PairingTests {
synced = new PairSync();
synced->init();
synced->setInitialSyncCompleted();
- Helpers::emptyCollection( "local.pair.sync" );
+ Helpers::emptyCollection( "local.pair.sync" );
}
PairSync *backup;
static PairSync *synced;
@@ -199,24 +199,24 @@ namespace PairingTests {
TestableReplPair rp4( true, fromjson( "{ok:1,you_are:1}" ) );
rp4.arbitrate();
- ASSERT( rp4.state == ReplPair::State_Master );
+ ASSERT( rp4.state == ReplPair::State_Master );
TestableReplPair rp5( true, fromjson( "{ok:1,you_are:0}" ) );
rp5.arbitrate();
- ASSERT( rp5.state == ReplPair::State_Slave );
+ ASSERT( rp5.state == ReplPair::State_Slave );
TestableReplPair rp6( true, fromjson( "{ok:1,you_are:-1}" ) );
rp6.arbitrate();
// unchanged from initial value
- ASSERT( rp6.state == ReplPair::State_Negotiating );
+ ASSERT( rp6.state == ReplPair::State_Negotiating );
}
private:
class TestableReplPair : public ReplPair {
public:
TestableReplPair( bool connect, const BSONObj &one ) :
- ReplPair( "a", "z" ),
- connect_( connect ),
- one_( one ) {
+ ReplPair( "a", "z" ),
+ connect_( connect ),
+ one_( one ) {
}
virtual
DBClientConnection *newClientConnection() const {
@@ -326,10 +326,10 @@ namespace PairingTests {
class All : public Suite {
public:
- All() : Suite( "pairing" ){
+ All() : Suite( "pairing" ) {
}
-
- void setupTests(){
+
+ void setupTests() {
add< ReplPairTests::Create >();
add< ReplPairTests::Dominant >();
add< ReplPairTests::SetMaster >();
diff --git a/dbtests/pdfiletests.cpp b/dbtests/pdfiletests.cpp
index 1d02a1a175e..3345ba520ee 100644
--- a/dbtests/pdfiletests.cpp
+++ b/dbtests/pdfiletests.cpp
@@ -31,7 +31,7 @@ namespace PdfileTests {
class Base {
public:
- Base() : _context( ns() ){
+ Base() : _context( ns() ) {
}
virtual ~Base() {
if ( !nsd() )
@@ -268,11 +268,11 @@ namespace PdfileTests {
};
} // namespace ScanCapped
-
+
namespace Insert {
class Base {
public:
- Base() : _context( ns() ){
+ Base() : _context( ns() ) {
}
virtual ~Base() {
if ( !nsd() )
@@ -291,7 +291,7 @@ namespace PdfileTests {
dblock lk_;
Client::Context _context;
};
-
+
class UpdateDate : public Base {
public:
void run() {
@@ -308,33 +308,33 @@ namespace PdfileTests {
class ExtentSizing {
public:
struct SmallFilesControl {
- SmallFilesControl(){
+ SmallFilesControl() {
old = cmdLine.smallfiles;
cmdLine.smallfiles = false;
}
- ~SmallFilesControl(){
+ ~SmallFilesControl() {
cmdLine.smallfiles = old;
}
bool old;
};
- void run(){
+ void run() {
SmallFilesControl c;
// test that no matter what we start with, we always get to max extent size
- for ( int obj=16; obj<BSONObjMaxUserSize; obj += 111 ){
+ for ( int obj=16; obj<BSONObjMaxUserSize; obj += 111 ) {
int sz = Extent::initialSize( obj );
- for ( int i=0; i<100; i++ ){
+ for ( int i=0; i<100; i++ ) {
sz = Extent::followupSize( obj , sz );
}
ASSERT_EQUALS( Extent::maxSize() , sz );
}
}
};
-
+
class ExtentAllocOrder {
public:
- void run(){
+ void run() {
string dbname = "unittest_ex";
-
+
string c1 = dbname + ".x1";
string c2 = dbname + ".x2";
@@ -345,23 +345,23 @@ namespace PdfileTests {
dblock mylock;
Client::Context cx( dbname );
-
+
bool isnew;
Database * d = dbHolder.getOrCreate( dbname , dbpath , isnew );
assert( d );
int big = 10 * 1024;
//int small = 1024;
-
+
unsigned long long l = 0;
- while ( 1 ){
+ while ( 1 ) {
MongoDataFile * f = d->addAFile( big , false );
cout << f->length() << endl;
if ( f->length() == l )
break;
l = f->length();
}
-
+
int start = d->numFiles();
for ( int i=0; i<start; i++ )
d->allocExtent( c1.c_str() , d->getFile( i )->getHeader()->unusedLength , false );
@@ -374,12 +374,12 @@ namespace PdfileTests {
}
};
-
+
class All : public Suite {
public:
- All() : Suite( "pdfile" ){}
-
- void setupTests(){
+ All() : Suite( "pdfile" ) {}
+
+ void setupTests() {
add< ScanCapped::Empty >();
add< ScanCapped::EmptyLooped >();
add< ScanCapped::EmptyMultiExtentLooped >();
diff --git a/dbtests/perf/btreeperf.cpp b/dbtests/perf/btreeperf.cpp
index 005cf66d819..7d68d8f5cc7 100644
--- a/dbtests/perf/btreeperf.cpp
+++ b/dbtests/perf/btreeperf.cpp
@@ -58,7 +58,7 @@ protected:
* Helper functions for converting a sample value to a sample object with
* specified _id, to be inserted or removed.
*/
-
+
template< class T >
BSONObj insertObjWithVal( const T &val ) {
BSONObjBuilder b;
@@ -177,7 +177,7 @@ protected:
b2.append( "$gte", val );
b2.done();
return b1.obj();
- }
+ }
virtual T insertVal() = 0;
virtual T removeVal() = 0;
};
@@ -190,8 +190,8 @@ protected:
class UniformInsertRangedUniformRemoveInteger : public InsertAndRangedRemoveStrategy< long long > {
public:
UniformInsertRangedUniformRemoveInteger() :
- _uniform_int( 0ULL, ~0ULL ),
- _nextLongLong( randomNumberGenerator, _uniform_int ) {
+ _uniform_int( 0ULL, ~0ULL ),
+ _nextLongLong( randomNumberGenerator, _uniform_int ) {
}
/** Small likelihood of duplicates */
virtual long long insertVal() { return _nextLongLong(); }
@@ -216,10 +216,10 @@ private:
class UniformInsertRangedUniformRemoveString : public InsertAndRangedRemoveStrategy< string > {
public:
UniformInsertRangedUniformRemoveString() :
- _geometric_distribution( 0.9 ),
- _nextLength( randomNumberGenerator, _geometric_distribution ),
- _uniform_char( 'a', 'z' ),
- _nextChar( randomNumberGenerator, _uniform_char ) {
+ _geometric_distribution( 0.9 ),
+ _nextLength( randomNumberGenerator, _geometric_distribution ),
+ _uniform_char( 'a', 'z' ),
+ _nextChar( randomNumberGenerator, _uniform_char ) {
}
/** Small likelihood of duplicates */
virtual string insertVal() { return nextString(); }
@@ -256,7 +256,7 @@ private:
class IncreasingInsertRangedUniformRemoveOID : public InsertAndRangedRemoveStrategy< OID > {
public:
IncreasingInsertRangedUniformRemoveOID() :
- _max( -1 ) {
+ _max( -1 ) {
}
virtual OID insertVal() { return oidFromULL( ++_max ); }
virtual OID removeVal() {
@@ -290,10 +290,10 @@ private:
class IncreasingInsertIncreasingRemoveInteger : public InsertAndRemoveStrategy {
public:
IncreasingInsertIncreasingRemoveInteger() :
- // Start with a large value so data type will be preserved if we round
- // trip through json.
- _min( 1LL << 32 ),
- _max( 1LL << 32 ) {
+ // Start with a large value so data type will be preserved if we round
+ // trip through json.
+ _min( 1LL << 32 ),
+ _max( 1LL << 32 ) {
}
virtual BSONObj insertObj() { return insertObjWithVal( ++_max ); }
virtual BSONObj removeObj() { return removeObjWithVal( _min < _max ? ++_min : _min ); }
@@ -311,27 +311,28 @@ public:
* specify 5 for this argument.
*/
BernoulliGenerator( int excessFalsePercent ) :
- _bernoulli_distribution( 1.0 / ( 2.0 + excessFalsePercent / 100.0 ) ),
- _generator( randomNumberGenerator, _bernoulli_distribution ) {
+ _bernoulli_distribution( 1.0 / ( 2.0 + excessFalsePercent / 100.0 ) ),
+ _generator( randomNumberGenerator, _bernoulli_distribution ) {
}
bool operator()() { return _generator(); }
private:
bernoulli_distribution<> _bernoulli_distribution;
- variate_generator< mt19937&, bernoulli_distribution<> > _generator;
+ variate_generator< mt19937&, bernoulli_distribution<> > _generator;
};
/** Runs a strategy on a connection, with specified mix of inserts and removes. */
class InsertAndRemoveRunner {
public:
InsertAndRemoveRunner( DBClientConnection &conn, InsertAndRemoveStrategy &strategy, int excessInsertPercent ) :
- _conn( conn ),
- _strategy( strategy ),
- _nextOpTypeRemove( excessInsertPercent ) {
+ _conn( conn ),
+ _strategy( strategy ),
+ _nextOpTypeRemove( excessInsertPercent ) {
}
void writeOne() {
if ( _nextOpTypeRemove() ) {
_conn.remove( ns, _strategy.removeObj(), true );
- } else {
+ }
+ else {
_conn.insert( ns, _strategy.insertObj() );
}
}
@@ -356,14 +357,15 @@ private:
class InsertAndRemoveScriptGenerator {
public:
InsertAndRemoveScriptGenerator( InsertAndRemoveStrategy &strategy, int excessInsertPercent ) :
- _strategy( strategy ),
- _nextOpTypeRemove( excessInsertPercent ) {
+ _strategy( strategy ),
+ _nextOpTypeRemove( excessInsertPercent ) {
}
void writeOne() {
if ( _nextOpTypeRemove() ) {
- cout << "r " << _strategy.removeObj().jsonString() << endl;
- } else {
- cout << "i " << _strategy.insertObj().jsonString() << endl;
+ cout << "r " << _strategy.removeObj().jsonString() << endl;
+ }
+ else {
+ cout << "i " << _strategy.insertObj().jsonString() << endl;
}
}
private:
@@ -379,14 +381,15 @@ private:
class InsertAndRemoveScriptRunner {
public:
InsertAndRemoveScriptRunner( DBClientConnection &conn ) :
- _conn( conn ) {
+ _conn( conn ) {
}
void writeOne() {
cin.getline( _buf, 1024 );
BSONObj val = fromjson( _buf + 2 );
if ( _buf[ 0 ] == 'r' ) {
_conn.remove( ns, val, true );
- } else {
+ }
+ else {
_conn.insert( ns, val );
}
}
@@ -396,7 +399,7 @@ private:
};
int main( int argc, const char **argv ) {
-
+
DBClientConnection conn;
conn.connect( "127.0.0.1:27017" );
conn.dropCollection( ns );
@@ -410,13 +413,13 @@ int main( int argc, const char **argv ) {
// IncreasingInsertIncreasingRemoveInteger strategy;
// InsertAndRemoveScriptGenerator runner( strategy, 5 );
InsertAndRemoveScriptRunner runner( conn );
-
+
Timer t;
BSONObj statsCmd = BSON( "collstats" << index_collection );
-
+
// Print header, unless we are generating a script (in that case, comment this out).
cout << "ops,milliseconds,docs,totalBucketSize" << endl;
-
+
long long i = 0;
long long n = 10000000000;
while( i < n ) {
diff --git a/dbtests/perf/perftest.cpp b/dbtests/perf/perftest.cpp
index f86a1c3235f..e233f5c3d21 100644
--- a/dbtests/perf/perftest.cpp
+++ b/dbtests/perf/perftest.cpp
@@ -81,7 +81,7 @@ public:
class RunnerSuite : public Suite {
public:
- RunnerSuite( string name ) : Suite( name ){}
+ RunnerSuite( string name ) : Suite( name ) {}
protected:
template< class T >
void add() {
@@ -168,9 +168,9 @@ namespace Insert {
class All : public RunnerSuite {
public:
- All() : RunnerSuite( "insert" ){}
+ All() : RunnerSuite( "insert" ) {}
- void setupTests(){
+ void setupTests() {
add< IdIndex >();
add< TwoIndex >();
add< TenIndex >();
@@ -252,8 +252,8 @@ namespace Update {
class All : public RunnerSuite {
public:
- All() : RunnerSuite( "update" ){}
- void setupTests(){
+ All() : RunnerSuite( "update" ) {}
+ void setupTests() {
add< Smaller >();
add< Bigger >();
add< Inc >();
@@ -266,33 +266,33 @@ namespace Update {
namespace BSON {
const char *sample =
- "{\"one\":2, \"two\":5, \"three\": {},"
- "\"four\": { \"five\": { \"six\" : 11 } },"
- "\"seven\": [ \"a\", \"bb\", \"ccc\", 5 ],"
- "\"eight\": Dbref( \"rrr\", \"01234567890123456789aaaa\" ),"
- "\"_id\": ObjectId( \"deadbeefdeadbeefdeadbeef\" ),"
- "\"nine\": { \"$binary\": \"abc=\", \"$type\": \"02\" },"
- "\"ten\": Date( 44 ), \"eleven\": /foooooo/i }";
+ "{\"one\":2, \"two\":5, \"three\": {},"
+ "\"four\": { \"five\": { \"six\" : 11 } },"
+ "\"seven\": [ \"a\", \"bb\", \"ccc\", 5 ],"
+ "\"eight\": Dbref( \"rrr\", \"01234567890123456789aaaa\" ),"
+ "\"_id\": ObjectId( \"deadbeefdeadbeefdeadbeef\" ),"
+ "\"nine\": { \"$binary\": \"abc=\", \"$type\": \"02\" },"
+ "\"ten\": Date( 44 ), \"eleven\": /foooooo/i }";
const char *shopwikiSample =
- "{ '_id' : '289780-80f85380b5c1d4a0ad75d1217673a4a2' , 'site_id' : 289780 , 'title'"
- ": 'Jubilee - Margaret Walker' , 'image_url' : 'http://www.heartlanddigsandfinds.c"
- "om/store/graphics/Product_Graphics/Product_8679.jpg' , 'url' : 'http://www.heartla"
- "nddigsandfinds.com/store/store_product_detail.cfm?Product_ID=8679&Category_ID=2&Su"
- "b_Category_ID=910' , 'url_hash' : 3450626119933116345 , 'last_update' : null , '"
- "features' : { '$imagePrefetchDate' : '2008Aug30 22:39' , '$image.color.rgb' : '5a7"
- "574' , 'Price' : '$10.99' , 'Description' : 'Author--s 1st Novel. A Houghton Miffl"
- "in Literary Fellowship Award novel by the esteemed poet and novelist who has demon"
- "strated a lifelong commitment to the heritage of black culture. An acclaimed story"
- "of Vyry, a negro slave during the 19th Century, facing the biggest challenge of h"
- "er lifetime - that of gaining her freedom, fighting for all the things she had nev"
- "er known before. The author, great-granddaughter of Vyry, reveals what the Civil W"
- "ar in America meant to the Negroes. Slavery W' , '$priceHistory-1' : '2008Dec03 $1"
- "0.99' , 'Brand' : 'Walker' , '$brands_in_title' : 'Walker' , '--path' : '//HTML[1]"
- "/BODY[1]/TABLE[1]/TR[1]/TD[1]/P[1]/TABLE[1]/TR[1]/TD[1]/TABLE[1]/TR[2]/TD[2]/TABLE"
- "[1]/TR[1]/TD[1]/P[1]/TABLE[1]/TR[1]' , '~location' : 'en_US' , '$crawled' : '2009J"
- "an11 03:22' , '$priceHistory-2' : '2008Nov15 $10.99' , '$priceHistory-0' : '2008De"
- "c24 $10.99'}}";
+ "{ '_id' : '289780-80f85380b5c1d4a0ad75d1217673a4a2' , 'site_id' : 289780 , 'title'"
+ ": 'Jubilee - Margaret Walker' , 'image_url' : 'http://www.heartlanddigsandfinds.c"
+ "om/store/graphics/Product_Graphics/Product_8679.jpg' , 'url' : 'http://www.heartla"
+ "nddigsandfinds.com/store/store_product_detail.cfm?Product_ID=8679&Category_ID=2&Su"
+ "b_Category_ID=910' , 'url_hash' : 3450626119933116345 , 'last_update' : null , '"
+ "features' : { '$imagePrefetchDate' : '2008Aug30 22:39' , '$image.color.rgb' : '5a7"
+ "574' , 'Price' : '$10.99' , 'Description' : 'Author--s 1st Novel. A Houghton Miffl"
+ "in Literary Fellowship Award novel by the esteemed poet and novelist who has demon"
+ "strated a lifelong commitment to the heritage of black culture. An acclaimed story"
+ "of Vyry, a negro slave during the 19th Century, facing the biggest challenge of h"
+ "er lifetime - that of gaining her freedom, fighting for all the things she had nev"
+ "er known before. The author, great-granddaughter of Vyry, reveals what the Civil W"
+ "ar in America meant to the Negroes. Slavery W' , '$priceHistory-1' : '2008Dec03 $1"
+ "0.99' , 'Brand' : 'Walker' , '$brands_in_title' : 'Walker' , '--path' : '//HTML[1]"
+ "/BODY[1]/TABLE[1]/TR[1]/TD[1]/P[1]/TABLE[1]/TR[1]/TD[1]/TABLE[1]/TR[2]/TD[2]/TABLE"
+ "[1]/TR[1]/TD[1]/P[1]/TABLE[1]/TR[1]' , '~location' : 'en_US' , '$crawled' : '2009J"
+ "an11 03:22' , '$priceHistory-2' : '2008Nov15 $10.99' , '$priceHistory-0' : '2008De"
+ "c24 $10.99'}}";
class Parse {
public:
@@ -332,8 +332,8 @@ namespace BSON {
class All : public RunnerSuite {
public:
- All() : RunnerSuite( "bson" ){}
- void setupTests(){
+ All() : RunnerSuite( "bson" ) {}
+ void setupTests() {
add< Parse >();
add< ShopwikiParse >();
add< Json >();
@@ -402,8 +402,8 @@ namespace Index {
class All : public RunnerSuite {
public:
- All() : RunnerSuite( "index" ){}
- void setupTests(){
+ All() : RunnerSuite( "index" ) {}
+ void setupTests() {
add< Int >();
add< ObjectId >();
add< String >();
@@ -435,7 +435,7 @@ namespace QueryTests {
}
void run() {
client_->findOne( ns_.c_str(),
- QUERY( "a" << "b" ).hint( BSON( "_id" << 1 ) ) );
+ QUERY( "a" << "b" ).hint( BSON( "_id" << 1 ) ) );
}
string ns_;
};
@@ -465,7 +465,7 @@ namespace QueryTests {
}
void run() {
auto_ptr< DBClientCursor > c =
- client_->query( ns_.c_str(), Query( BSONObj() ).sort( BSON( "_id" << 1 ) ) );
+ client_->query( ns_.c_str(), Query( BSONObj() ).sort( BSON( "_id" << 1 ) ) );
int i = 0;
for( ; c->more(); c->nextSafe(), ++i );
ASSERT_EQUALS( 50000, i );
@@ -481,7 +481,7 @@ namespace QueryTests {
}
void run() {
auto_ptr< DBClientCursor > c =
- client_->query( ns_.c_str(), Query( BSONObj() ).sort( BSON( "_id" << 1 ) ) );
+ client_->query( ns_.c_str(), Query( BSONObj() ).sort( BSON( "_id" << 1 ) ) );
int i = 0;
for( ; c->more(); c->nextSafe(), ++i );
ASSERT_EQUALS( 50000, i );
@@ -541,8 +541,8 @@ namespace QueryTests {
class All : public RunnerSuite {
public:
- All() : RunnerSuite( "query" ){}
- void setupTests(){
+ All() : RunnerSuite( "query" ) {}
+ void setupTests() {
add< NoMatch >();
add< NoMatchIndex >();
add< NoMatchLong >();
@@ -602,8 +602,8 @@ namespace Count {
class All : public RunnerSuite {
public:
- All() : RunnerSuite( "count" ){}
- void setupTests(){
+ All() : RunnerSuite( "count" ) {}
+ void setupTests() {
add< Count >();
add< CountIndex >();
add< CountSimpleIndex >();
@@ -677,8 +677,8 @@ namespace Plan {
class All : public RunnerSuite {
public:
- All() : RunnerSuite("plan" ){}
- void setupTests(){
+ All() : RunnerSuite("plan" ) {}
+ void setupTests() {
add< Hint >();
add< Sort >();
add< Query >();
diff --git a/dbtests/perftests.cpp b/dbtests/perftests.cpp
index 2b59aca646b..980fab0dbf6 100644
--- a/dbtests/perftests.cpp
+++ b/dbtests/perftests.cpp
@@ -1,6 +1,6 @@
/** @file perftests.cpp.cpp : unit tests relating to performance
- The idea herein is tests that run fast and can be part of the normal CI suite. So no tests herein that take
+ The idea herein is tests that run fast and can be part of the normal CI suite. So no tests herein that take
a long time to run. Obviously we need those too, but they will be separate.
These tests use DBDirectClient; they are a bit white-boxish.
@@ -65,14 +65,14 @@ namespace PerfTests {
DBClientType ClientBase::_client;
// todo: use a couple threads. not a very good test yet.
- class DefInvoke {
+ class DefInvoke {
static int tot;
- struct V {
+ struct V {
int val;
static void go(const V &v) { tot += v.val; }
};
public:
- void run() {
+ void run() {
tot = 0;
TaskQueue<V> d;
int x = 0;
@@ -92,11 +92,10 @@ namespace PerfTests {
};
int DefInvoke::tot;
- class CappedTest : public ClientBase {
+ class CappedTest : public ClientBase {
};
- class B : public ClientBase
- {
+ class B : public ClientBase {
string _ns;
protected:
const char *ns() { return _ns.c_str(); }
@@ -113,11 +112,11 @@ namespace PerfTests {
virtual unsigned long long expectation() = 0;
virtual int howLongMillis() { return 5000; }
public:
- void say(unsigned long long n, int ms, string s) {
+ void say(unsigned long long n, int ms, string s) {
cout << setw(36) << left << s << ' ' << right << setw(7) << n*1000/ms << "/sec " << setw(4) << ms << "ms" << endl;
cout << dur::stats.curr->_asObj().toString() << endl;
}
- void run() {
+ void run() {
_ns = string("perftest.") + name();
client().dropCollection(ns());
@@ -130,17 +129,18 @@ namespace PerfTests {
Timer t;
unsigned long long n = 0;
const unsigned Batch = 50;
- do {
+ do {
unsigned i;
for( i = 0; i < Batch; i++ )
timed();
n += i;
- } while( t.millis() < hlm );
+ }
+ while( t.millis() < hlm );
client().getLastError(); // block until all ops are finished
int ms = t.millis();
say(n, ms, name());
- if( n < expectation() ) {
+ if( n < expectation() ) {
cout << "\ntest " << name() << " seems slow n:" << n << " ops/sec but expect greater than:" << expectation() << endl;
cout << endl;
}
@@ -151,12 +151,12 @@ namespace PerfTests {
dur::stats.curr->reset();
Timer t;
unsigned long long n = 0;
- while( 1 ) {
+ while( 1 ) {
unsigned i;
for( i = 0; i < Batch; i++ )
timed2();
n += i;
- if( t.millis() > hlm )
+ if( t.millis() > hlm )
break;
}
int ms = t.millis();
@@ -166,14 +166,14 @@ namespace PerfTests {
}
};
- class InsertDup : public B {
+ class InsertDup : public B {
const BSONObj o;
public:
InsertDup() : o( BSON("_id" << 1) ) { } // dup keys
- string name() {
- return "insert duplicate _ids";
+ string name() {
+ return "insert duplicate _ids";
}
- void prep() {
+ void prep() {
client().insert( ns(), o );
}
void timed() {
@@ -184,8 +184,8 @@ namespace PerfTests {
}
unsigned long long expectation() { return 1000; }
};
-
- class Insert1 : public InsertDup {
+
+ class Insert1 : public InsertDup {
const BSONObj x;
public:
Insert1() : x( BSON("x" << 99) ) { }
@@ -199,10 +199,10 @@ namespace PerfTests {
unsigned long long expectation() { return 1000; }
};
- class InsertBig : public InsertDup {
+ class InsertBig : public InsertDup {
BSONObj x;
- virtual int howLongMillis() {
- if( sizeof(void*) == 4 )
+ virtual int howLongMillis() {
+ if( sizeof(void*) == 4 )
return 1000; // could exceed mmapping if run too long, as this function adds a lot fasta
return 5000;
}
@@ -221,10 +221,10 @@ namespace PerfTests {
unsigned long long expectation() { return 20; }
};
- class InsertRandom : public B {
+ class InsertRandom : public B {
public:
string name() { return "random inserts"; }
- void prep() {
+ void prep() {
client().insert( ns(), BSONObj() );
client().ensureIndex(ns(), BSON("x"<<1));
}
@@ -237,17 +237,17 @@ namespace PerfTests {
}
unsigned long long expectation() { return 1000; }
};
-
- /** upserts about 32k records and then keeps updating them
+
+ /** upserts about 32k records and then keeps updating them
2 indexes
*/
- class Update1 : public B {
+ class Update1 : public B {
public:
- static int rand() {
+ static int rand() {
return std::rand() & 0x7fff;
}
string name() { return "random upserts"; }
- void prep() {
+ void prep() {
client().insert( ns(), BSONObj() );
client().ensureIndex(ns(), BSON("x"<<1));
}
@@ -274,12 +274,12 @@ namespace PerfTests {
}
unsigned long long expectation() { return 1000; }
};
-
+
template <typename T>
- class MoreIndexes : public T {
+ class MoreIndexes : public T {
public:
string name() { return T::name() + " with more indexes"; }
- void prep() {
+ void prep() {
T::prep();
this->client().ensureIndex(this->ns(), BSON("y"<<1));
this->client().ensureIndex(this->ns(), BSON("z"<<1));
@@ -290,7 +290,7 @@ namespace PerfTests {
public:
All() : Suite( "perf" ) {
}
- void setupTests(){
+ void setupTests() {
add< DefInvoke >();
add< InsertDup >();
add< Insert1 >();
diff --git a/dbtests/queryoptimizertests.cpp b/dbtests/queryoptimizertests.cpp
index 7c411b286a2..acf92174be3 100644
--- a/dbtests/queryoptimizertests.cpp
+++ b/dbtests/queryoptimizertests.cpp
@@ -27,12 +27,12 @@
namespace mongo {
extern BSONObj id_obj;
- void runQuery(Message& m, QueryMessage& q, Message &response ){
+ void runQuery(Message& m, QueryMessage& q, Message &response ) {
CurOp op( &(cc()) );
op.ensureStarted();
runQuery( m , q , op, response );
}
- void runQuery(Message& m, QueryMessage& q ){
+ void runQuery(Message& m, QueryMessage& q ) {
Message response;
runQuery( m, q, response );
}
@@ -64,14 +64,14 @@ namespace QueryOptimizerTests {
}
}
};
-
+
class NumericBase : public Base {
public:
- NumericBase(){
+ NumericBase() {
o = BSON( "min" << -numeric_limits<double>::max() << "max" << numeric_limits<double>::max() );
}
-
+
virtual BSONElement lower() { return o["min"]; }
virtual BSONElement upper() { return o["max"]; }
private:
@@ -81,7 +81,7 @@ namespace QueryOptimizerTests {
class Empty : public Base {
virtual BSONObj query() { return BSONObj(); }
};
-
+
class Eq : public Base {
public:
Eq() : o_( BSON( "a" << 1 ) ) {}
@@ -94,7 +94,7 @@ namespace QueryOptimizerTests {
class DupEq : public Eq {
public:
virtual BSONObj query() { return BSON( "a" << 1 << "b" << 2 << "a" << 1 ); }
- };
+ };
class Lt : public NumericBase {
public:
@@ -103,13 +103,13 @@ namespace QueryOptimizerTests {
virtual BSONElement upper() { return o_.firstElement(); }
virtual bool upperInclusive() { return false; }
BSONObj o_;
- };
+ };
class Lte : public Lt {
- virtual BSONObj query() { return BSON( "a" << LTE << 1 ); }
+ virtual BSONObj query() { return BSON( "a" << LTE << 1 ); }
virtual bool upperInclusive() { return true; }
};
-
+
class Gt : public NumericBase {
public:
Gt() : o_( BSON( "-" << 1 ) ) {}
@@ -117,23 +117,23 @@ namespace QueryOptimizerTests {
virtual BSONElement lower() { return o_.firstElement(); }
virtual bool lowerInclusive() { return false; }
BSONObj o_;
- };
-
+ };
+
class Gte : public Gt {
- virtual BSONObj query() { return BSON( "a" << GTE << 1 ); }
+ virtual BSONObj query() { return BSON( "a" << GTE << 1 ); }
virtual bool lowerInclusive() { return true; }
};
-
+
class TwoLt : public Lt {
- virtual BSONObj query() { return BSON( "a" << LT << 1 << LT << 5 ); }
+ virtual BSONObj query() { return BSON( "a" << LT << 1 << LT << 5 ); }
};
class TwoGt : public Gt {
- virtual BSONObj query() { return BSON( "a" << GT << 0 << GT << 1 ); }
- };
+ virtual BSONObj query() { return BSON( "a" << GT << 0 << GT << 1 ); }
+ };
class EqGte : public Eq {
- virtual BSONObj query() { return BSON( "a" << 1 << "a" << GTE << 1 ); }
+ virtual BSONObj query() { return BSON( "a" << 1 << "a" << GTE << 1 ); }
};
class EqGteInvalid {
@@ -142,7 +142,7 @@ namespace QueryOptimizerTests {
FieldRangeSet fbs( "ns", BSON( "a" << 1 << "a" << GTE << 2 ) );
ASSERT( !fbs.matchPossible() );
}
- };
+ };
struct RegexBase : Base {
void run() { //need to only look at first interval
@@ -166,7 +166,7 @@ namespace QueryOptimizerTests {
virtual BSONElement upper() { return o2_.firstElement(); }
virtual bool upperInclusive() { return false; }
BSONObj o1_, o2_;
- };
+ };
class RegexObj : public RegexBase {
public:
@@ -177,7 +177,7 @@ namespace QueryOptimizerTests {
virtual bool upperInclusive() { return false; }
BSONObj o1_, o2_;
};
-
+
class UnhelpfulRegex : public RegexBase {
public:
UnhelpfulRegex() {
@@ -191,13 +191,13 @@ namespace QueryOptimizerTests {
BSONObjBuilder b;
b.appendRegex( "a", "abc" );
return b.obj();
- }
+ }
virtual BSONElement lower() { return limits["lower"]; }
virtual BSONElement upper() { return limits["upper"]; }
virtual bool upperInclusive() { return false; }
BSONObj limits;
};
-
+
class In : public Base {
public:
In() : o1_( BSON( "-" << -3 ) ), o2_( BSON( "-" << 44 ) ) {}
@@ -219,7 +219,7 @@ namespace QueryOptimizerTests {
virtual BSONElement upper() { return o2_.firstElement(); }
BSONObj o1_, o2_;
};
-
+
class Equality {
public:
void run() {
@@ -237,7 +237,7 @@ namespace QueryOptimizerTests {
ASSERT( !s6.range( "a" ).equality() );
}
};
-
+
class SimplifiedQuery {
public:
void run() {
@@ -251,7 +251,7 @@ namespace QueryOptimizerTests {
ASSERT( !simple.getObjectField( "e" ).woCompare( fromjson( "{$gte:0,$lte:10}" ) ) );
}
};
-
+
class QueryPatternTest {
public:
void run() {
@@ -277,14 +277,14 @@ namespace QueryOptimizerTests {
return FieldRangeSet( "", query ).pattern( sort );
}
};
-
+
class NoWhere {
public:
void run() {
ASSERT_EQUALS( 0, FieldRangeSet( "ns", BSON( "$where" << 1 ) ).nNontrivialRanges() );
}
};
-
+
class Numeric {
public:
void run() {
@@ -311,7 +311,7 @@ namespace QueryOptimizerTests {
ASSERT( f.range( "a" ).max().woCompare( BSON( "a" << 3.0 ).firstElement(), false ) == 0 );
}
};
-
+
class UnionBound {
public:
void run() {
@@ -321,29 +321,29 @@ namespace QueryOptimizerTests {
ASSERT_EQUALS( 2U, ret.intervals().size() );
}
};
-
- class MultiBound {
- public:
- void run() {
+
+ class MultiBound {
+ public:
+ void run() {
FieldRangeSet frs1( "", fromjson( "{a:{$in:[1,3,5,7,9]}}" ) );
FieldRangeSet frs2( "", fromjson( "{a:{$in:[2,3,5,8,9]}}" ) );
- FieldRange fr1 = frs1.range( "a" );
- FieldRange fr2 = frs2.range( "a" );
- fr1 &= fr2;
+ FieldRange fr1 = frs1.range( "a" );
+ FieldRange fr2 = frs2.range( "a" );
+ fr1 &= fr2;
ASSERT( fr1.min().woCompare( BSON( "a" << 3.0 ).firstElement(), false ) == 0 );
ASSERT( fr1.max().woCompare( BSON( "a" << 9.0 ).firstElement(), false ) == 0 );
- vector< FieldInterval > intervals = fr1.intervals();
- vector< FieldInterval >::const_iterator j = intervals.begin();
- double expected[] = { 3, 5, 9 };
- for( int i = 0; i < 3; ++i, ++j ) {
- ASSERT_EQUALS( expected[ i ], j->_lower._bound.number() );
- ASSERT( j->_lower._inclusive );
- ASSERT( j->_lower == j->_upper );
- }
- ASSERT( j == intervals.end() );
- }
- };
-
+ vector< FieldInterval > intervals = fr1.intervals();
+ vector< FieldInterval >::const_iterator j = intervals.begin();
+ double expected[] = { 3, 5, 9 };
+ for( int i = 0; i < 3; ++i, ++j ) {
+ ASSERT_EQUALS( expected[ i ], j->_lower._bound.number() );
+ ASSERT( j->_lower._inclusive );
+ ASSERT( j->_lower == j->_upper );
+ }
+ ASSERT( j == intervals.end() );
+ }
+ };
+
class DiffBase {
public:
virtual ~DiffBase() {}
@@ -351,7 +351,7 @@ namespace QueryOptimizerTests {
FieldRangeSet frs( "", fromjson( obj().toString() ) );
FieldRange ret = frs.range( "a" );
ret -= frs.range( "b" );
- check( ret );
+ check( ret );
}
protected:
void check( const FieldRange &fr ) {
@@ -376,7 +376,7 @@ namespace QueryOptimizerTests {
class TwoRangeBase : public DiffBase {
public:
TwoRangeBase( string obj, int low, int high, bool lowI, bool highI )
- : _obj( obj ) {
+ : _obj( obj ) {
_n[ 0 ] = low;
_n[ 1 ] = high;
_b[ 0 ] = lowI;
@@ -391,7 +391,7 @@ namespace QueryOptimizerTests {
int _n[ 2 ];
bool _b[ 2 ];
};
-
+
struct Diff1 : public TwoRangeBase {
Diff1() : TwoRangeBase( "{a:{$gt:1,$lt:2},b:{$gt:3,$lt:4}}", 1, 2, false, false ) {}
};
@@ -399,7 +399,7 @@ namespace QueryOptimizerTests {
struct Diff2 : public TwoRangeBase {
Diff2() : TwoRangeBase( "{a:{$gt:1,$lt:2},b:{$gt:2,$lt:4}}", 1, 2, false, false ) {}
};
-
+
struct Diff3 : public TwoRangeBase {
Diff3() : TwoRangeBase( "{a:{$gt:1,$lte:2},b:{$gt:2,$lt:4}}", 1, 2, false, true ) {}
};
@@ -407,11 +407,11 @@ namespace QueryOptimizerTests {
struct Diff4 : public TwoRangeBase {
Diff4() : TwoRangeBase( "{a:{$gt:1,$lt:2},b:{$gte:2,$lt:4}}", 1, 2, false, false) {}
};
-
+
struct Diff5 : public TwoRangeBase {
Diff5() : TwoRangeBase( "{a:{$gt:1,$lte:2},b:{$gte:2,$lt:4}}", 1, 2, false, false) {}
};
-
+
struct Diff6 : public TwoRangeBase {
Diff6() : TwoRangeBase( "{a:{$gt:1,$lte:3},b:{$gte:2,$lt:4}}", 1, 2, false, false) {}
};
@@ -419,7 +419,7 @@ namespace QueryOptimizerTests {
struct Diff7 : public TwoRangeBase {
Diff7() : TwoRangeBase( "{a:{$gt:1,$lte:3},b:{$gt:2,$lt:4}}", 1, 2, false, true) {}
};
-
+
struct Diff8 : public TwoRangeBase {
Diff8() : TwoRangeBase( "{a:{$gt:1,$lt:4},b:{$gt:2,$lt:4}}", 1, 2, false, true) {}
};
@@ -430,12 +430,12 @@ namespace QueryOptimizerTests {
struct Diff10 : public TwoRangeBase {
Diff10() : TwoRangeBase( "{a:{$gt:1,$lte:4},b:{$gt:2,$lte:4}}", 1, 2, false, true) {}
- };
-
+ };
+
class SplitRangeBase : public DiffBase {
public:
SplitRangeBase( string obj, int low1, bool low1I, int high1, bool high1I, int low2, bool low2I, int high2, bool high2I )
- : _obj( obj ) {
+ : _obj( obj ) {
_n[ 0 ] = low1;
_n[ 1 ] = high1;
_n[ 2 ] = low2;
@@ -452,9 +452,9 @@ namespace QueryOptimizerTests {
virtual BSONObj obj() const { return fromjson( _obj ); }
string _obj;
int _n[ 4 ];
- bool _b[ 4 ];
+ bool _b[ 4 ];
};
-
+
struct Diff11 : public SplitRangeBase {
Diff11() : SplitRangeBase( "{a:{$gt:1,$lte:4},b:{$gt:2,$lt:4}}", 1, false, 2, true, 4, true, 4, true) {}
};
@@ -462,11 +462,11 @@ namespace QueryOptimizerTests {
struct Diff12 : public SplitRangeBase {
Diff12() : SplitRangeBase( "{a:{$gt:1,$lt:5},b:{$gt:2,$lt:4}}", 1, false, 2, true, 4, true, 5, false) {}
};
-
+
struct Diff13 : public TwoRangeBase {
Diff13() : TwoRangeBase( "{a:{$gt:1,$lt:5},b:{$gt:1,$lt:4}}", 4, 5, true, false) {}
};
-
+
struct Diff14 : public SplitRangeBase {
Diff14() : SplitRangeBase( "{a:{$gte:1,$lt:5},b:{$gt:1,$lt:4}}", 1, true, 1, true, 4, true, 5, false) {}
};
@@ -514,7 +514,7 @@ namespace QueryOptimizerTests {
struct Diff25 : public TwoRangeBase {
Diff25() : TwoRangeBase( "{a:{$gte:1,$lte:5},b:0}", 1, 5, true, true) {}
};
-
+
struct Diff26 : public TwoRangeBase {
Diff26() : TwoRangeBase( "{a:{$gt:1,$lte:5},b:1}", 1, 5, false, true) {}
};
@@ -530,7 +530,7 @@ namespace QueryOptimizerTests {
struct Diff29 : public TwoRangeBase {
Diff29() : TwoRangeBase( "{a:{$gte:1,$lte:5},b:5}", 1, 5, true, false) {}
};
-
+
struct Diff30 : public TwoRangeBase {
Diff30() : TwoRangeBase( "{a:{$gte:1,$lt:5},b:5}", 1, 5, true, false) {}
};
@@ -538,7 +538,7 @@ namespace QueryOptimizerTests {
struct Diff31 : public TwoRangeBase {
Diff31() : TwoRangeBase( "{a:{$gte:1,$lt:5},b:6}", 1, 5, true, false) {}
};
-
+
struct Diff32 : public TwoRangeBase {
Diff32() : TwoRangeBase( "{a:{$gte:1,$lte:5},b:6}", 1, 5, true, true) {}
};
@@ -546,7 +546,7 @@ namespace QueryOptimizerTests {
class EmptyBase : public DiffBase {
public:
EmptyBase( string obj )
- : _obj( obj ) {}
+ : _obj( obj ) {}
private:
virtual unsigned len() const { return 0; }
virtual const int *nums() const { return 0; }
@@ -554,7 +554,7 @@ namespace QueryOptimizerTests {
virtual BSONObj obj() const { return fromjson( _obj ); }
string _obj;
};
-
+
struct Diff33 : public EmptyBase {
Diff33() : EmptyBase( "{a:{$gte:1,$lte:5},b:{$gt:0,$lt:6}}" ) {}
};
@@ -586,7 +586,7 @@ namespace QueryOptimizerTests {
struct Diff40 : public EmptyBase {
Diff40() : EmptyBase( "{a:{$gt:1,$lte:5},b:{$gt:0,$lte:5}}" ) {}
};
-
+
struct Diff41 : public TwoRangeBase {
Diff41() : TwoRangeBase( "{a:{$gte:1,$lte:5},b:{$gt:0,$lt:5}}", 5, 5, true, true ) {}
};
@@ -654,7 +654,7 @@ namespace QueryOptimizerTests {
struct Diff57 : public EmptyBase {
Diff57() : EmptyBase( "{a:{$gte:1,$lte:5},b:{$gte:1,$lte:5}}" ) {}
};
-
+
struct Diff58 : public TwoRangeBase {
Diff58() : TwoRangeBase( "{a:1,b:{$gt:1,$lt:5}}", 1, 1, true, true ) {}
};
@@ -678,11 +678,11 @@ namespace QueryOptimizerTests {
struct Diff63 : public EmptyBase {
Diff63() : EmptyBase( "{a:5,b:5}" ) {}
};
-
+
struct Diff64 : public TwoRangeBase {
Diff64() : TwoRangeBase( "{a:{$gte:1,$lte:2},b:{$gt:0,$lte:1}}", 1, 2, false, true ) {}
};
-
+
class DiffMulti1 : public DiffBase {
public:
void run() {
@@ -693,7 +693,7 @@ namespace QueryOptimizerTests {
other |= frs.range( "d" );
other |= frs.range( "e" );
ret -= other;
- check( ret );
+ check( ret );
}
protected:
virtual unsigned len() const { return 3; }
@@ -712,7 +712,7 @@ namespace QueryOptimizerTests {
ret |= frs.range( "d" );
ret |= frs.range( "e" );
ret -= mask;
- check( ret );
+ check( ret );
}
protected:
virtual unsigned len() const { return 2; }
@@ -720,7 +720,7 @@ namespace QueryOptimizerTests {
virtual const bool *incs() const { static bool b[] = { false, true, true, false }; return b; }
virtual BSONObj obj() const { return BSONObj(); }
};
-
+
class SetIntersect {
public:
void run() {
@@ -730,9 +730,9 @@ namespace QueryOptimizerTests {
ASSERT_EQUALS( fromjson( "{a:1,b:5,c:7,d:{$gte:8,$lte:9},e:10}" ), frs1.simplifiedQuery( BSONObj() ) );
}
};
-
+
} // namespace FieldRangeTests
-
+
namespace QueryPlanTests {
class Base {
public:
@@ -779,7 +779,7 @@ namespace QueryOptimizerTests {
static DBDirectClient client_;
};
DBDirectClient Base::client_;
-
+
// There's a limit of 10 indexes total, make sure not to exceed this in a given test.
#define INDEXNO(x) nsd()->idxNo( *this->index( BSON(x) ) )
#define INDEX(x) this->index( BSON(x) )
@@ -787,7 +787,7 @@ namespace QueryOptimizerTests {
#define FBS(x) ( FieldRangeSet_GLOBAL.reset( new FieldRangeSet( ns(), x ) ), *FieldRangeSet_GLOBAL )
auto_ptr< FieldRangeSet > FieldRangeSet_GLOBAL2;
#define FBS2(x) ( FieldRangeSet_GLOBAL2.reset( new FieldRangeSet( ns(), x ) ), *FieldRangeSet_GLOBAL2 )
-
+
class NoIndex : public Base {
public:
void run() {
@@ -797,7 +797,7 @@ namespace QueryOptimizerTests {
ASSERT( !p.exactKeyMatch() );
}
};
-
+
class SimpleOrder : public Base {
public:
void run() {
@@ -807,7 +807,7 @@ namespace QueryOptimizerTests {
BSONObjBuilder b2;
b2.appendMaxKey( "" );
BSONObj end = b2.obj();
-
+
QueryPlan p( nsd(), INDEXNO( "a" << 1 ), FBS( BSONObj() ), FBS2( BSONObj() ), BSONObj(), BSON( "a" << 1 ) );
ASSERT( !p.scanAndOrderRequired() );
ASSERT( !startKey( p ).woCompare( start ) );
@@ -820,30 +820,30 @@ namespace QueryOptimizerTests {
ASSERT( !endKey( p3 ).woCompare( end ) );
}
};
-
+
class MoreIndexThanNeeded : public Base {
public:
void run() {
QueryPlan p( nsd(), INDEXNO( "a" << 1 << "b" << 1 ), FBS( BSONObj() ), FBS2( BSONObj() ), BSONObj(), BSON( "a" << 1 ) );
- ASSERT( !p.scanAndOrderRequired() );
+ ASSERT( !p.scanAndOrderRequired() );
}
};
-
+
class IndexSigns : public Base {
public:
void run() {
QueryPlan p( nsd(), INDEXNO( "a" << 1 << "b" << -1 ) , FBS( BSONObj() ), FBS2( BSONObj() ), BSONObj(), BSON( "a" << 1 << "b" << -1 ) );
- ASSERT( !p.scanAndOrderRequired() );
+ ASSERT( !p.scanAndOrderRequired() );
ASSERT_EQUALS( 1, p.direction() );
QueryPlan p2( nsd(), INDEXNO( "a" << 1 << "b" << 1 ), FBS( BSONObj() ), FBS2( BSONObj() ), BSONObj(), BSON( "a" << 1 << "b" << -1 ) );
- ASSERT( p2.scanAndOrderRequired() );
+ ASSERT( p2.scanAndOrderRequired() );
ASSERT_EQUALS( 0, p2.direction() );
QueryPlan p3( nsd(), indexno( id_obj ), FBS( BSONObj() ), FBS2( BSONObj() ), BSONObj(), BSON( "_id" << 1 ) );
ASSERT( !p3.scanAndOrderRequired() );
ASSERT_EQUALS( 1, p3.direction() );
- }
+ }
};
-
+
class IndexReverse : public Base {
public:
void run() {
@@ -856,17 +856,17 @@ namespace QueryOptimizerTests {
b2.appendMinKey( "" );
BSONObj end = b2.obj();
QueryPlan p( nsd(), INDEXNO( "a" << -1 << "b" << 1 ),FBS( BSONObj() ), FBS2( BSONObj() ), BSONObj(), BSON( "a" << 1 << "b" << -1 ) );
- ASSERT( !p.scanAndOrderRequired() );
+ ASSERT( !p.scanAndOrderRequired() );
ASSERT_EQUALS( -1, p.direction() );
ASSERT( !startKey( p ).woCompare( start ) );
ASSERT( !endKey( p ).woCompare( end ) );
QueryPlan p2( nsd(), INDEXNO( "a" << 1 << "b" << 1 ), FBS( BSONObj() ), FBS2( BSONObj() ), BSONObj(), BSON( "a" << -1 << "b" << -1 ) );
- ASSERT( !p2.scanAndOrderRequired() );
+ ASSERT( !p2.scanAndOrderRequired() );
ASSERT_EQUALS( -1, p2.direction() );
QueryPlan p3( nsd(), INDEXNO( "a" << 1 << "b" << -1 ), FBS( BSONObj() ), FBS2( BSONObj() ), BSONObj(), BSON( "a" << -1 << "b" << -1 ) );
- ASSERT( p3.scanAndOrderRequired() );
+ ASSERT( p3.scanAndOrderRequired() );
ASSERT_EQUALS( 0, p3.direction() );
- }
+ }
};
class NoOrder : public Base {
@@ -881,28 +881,28 @@ namespace QueryOptimizerTests {
b2.appendMaxKey( "" );
BSONObj end = b2.obj();
QueryPlan p( nsd(), INDEXNO( "a" << -1 << "b" << 1 ), FBS( BSON( "a" << 3 ) ), FBS2( BSON( "a" << 3 ) ), BSON( "a" << 3 ), BSONObj() );
- ASSERT( !p.scanAndOrderRequired() );
+ ASSERT( !p.scanAndOrderRequired() );
ASSERT( !startKey( p ).woCompare( start ) );
ASSERT( !endKey( p ).woCompare( end ) );
QueryPlan p2( nsd(), INDEXNO( "a" << -1 << "b" << 1 ), FBS( BSON( "a" << 3 ) ), FBS2( BSON( "a" << 3 ) ), BSON( "a" << 3 ), BSONObj() );
- ASSERT( !p2.scanAndOrderRequired() );
+ ASSERT( !p2.scanAndOrderRequired() );
ASSERT( !startKey( p ).woCompare( start ) );
ASSERT( !endKey( p ).woCompare( end ) );
- }
+ }
};
-
+
class EqualWithOrder : public Base {
public:
void run() {
QueryPlan p( nsd(), INDEXNO( "a" << 1 << "b" << 1 ), FBS( BSON( "a" << 4 ) ), FBS2( BSON( "a" << 4 ) ), BSON( "a" << 4 ), BSON( "b" << 1 ) );
- ASSERT( !p.scanAndOrderRequired() );
+ ASSERT( !p.scanAndOrderRequired() );
QueryPlan p2( nsd(), INDEXNO( "a" << 1 << "b" << 1 << "c" << 1 ), FBS( BSON( "b" << 4 ) ), FBS2( BSON( "b" << 4 ) ), BSON( "b" << 4 ), BSON( "a" << 1 << "c" << 1 ) );
- ASSERT( !p2.scanAndOrderRequired() );
+ ASSERT( !p2.scanAndOrderRequired() );
QueryPlan p3( nsd(), INDEXNO( "a" << 1 << "b" << 1 ), FBS( BSON( "b" << 4 ) ), FBS2( BSON( "b" << 4 ) ), BSON( "b" << 4 ), BSON( "a" << 1 << "c" << 1 ) );
- ASSERT( p3.scanAndOrderRequired() );
+ ASSERT( p3.scanAndOrderRequired() );
}
};
-
+
class Optimal : public Base {
public:
void run() {
@@ -926,21 +926,21 @@ namespace QueryOptimizerTests {
ASSERT( p9.optimal() );
}
};
-
+
class MoreOptimal : public Base {
public:
void run() {
- QueryPlan p10( nsd(), INDEXNO( "a" << 1 << "b" << 1 << "c" << 1 ), FBS( BSON( "a" << 1 ) ), FBS2( BSON( "a" << 1 ) ), BSON( "a" << 1 ), BSONObj() );
- ASSERT( p10.optimal() );
- QueryPlan p11( nsd(), INDEXNO( "a" << 1 << "b" << 1 << "c" << 1 ), FBS( BSON( "a" << 1 << "b" << LT << 1 ) ), FBS2( BSON( "a" << 1 << "b" << LT << 1 ) ), BSON( "a" << 1 << "b" << LT << 1 ), BSONObj() );
- ASSERT( p11.optimal() );
- QueryPlan p12( nsd(), INDEXNO( "a" << 1 << "b" << 1 << "c" << 1 ), FBS( BSON( "a" << LT << 1 ) ), FBS2( BSON( "a" << LT << 1 ) ), BSON( "a" << LT << 1 ), BSONObj() );
- ASSERT( p12.optimal() );
- QueryPlan p13( nsd(), INDEXNO( "a" << 1 << "b" << 1 << "c" << 1 ), FBS( BSON( "a" << LT << 1 ) ), FBS2( BSON( "a" << LT << 1 ) ), BSON( "a" << LT << 1 ), BSON( "a" << 1 ) );
- ASSERT( p13.optimal() );
+ QueryPlan p10( nsd(), INDEXNO( "a" << 1 << "b" << 1 << "c" << 1 ), FBS( BSON( "a" << 1 ) ), FBS2( BSON( "a" << 1 ) ), BSON( "a" << 1 ), BSONObj() );
+ ASSERT( p10.optimal() );
+ QueryPlan p11( nsd(), INDEXNO( "a" << 1 << "b" << 1 << "c" << 1 ), FBS( BSON( "a" << 1 << "b" << LT << 1 ) ), FBS2( BSON( "a" << 1 << "b" << LT << 1 ) ), BSON( "a" << 1 << "b" << LT << 1 ), BSONObj() );
+ ASSERT( p11.optimal() );
+ QueryPlan p12( nsd(), INDEXNO( "a" << 1 << "b" << 1 << "c" << 1 ), FBS( BSON( "a" << LT << 1 ) ), FBS2( BSON( "a" << LT << 1 ) ), BSON( "a" << LT << 1 ), BSONObj() );
+ ASSERT( p12.optimal() );
+ QueryPlan p13( nsd(), INDEXNO( "a" << 1 << "b" << 1 << "c" << 1 ), FBS( BSON( "a" << LT << 1 ) ), FBS2( BSON( "a" << LT << 1 ) ), BSON( "a" << LT << 1 ), BSON( "a" << 1 ) );
+ ASSERT( p13.optimal() );
}
};
-
+
class KeyMatch : public Base {
public:
void run() {
@@ -964,15 +964,15 @@ namespace QueryOptimizerTests {
ASSERT( p9.exactKeyMatch() );
}
};
-
+
class MoreKeyMatch : public Base {
public:
void run() {
QueryPlan p( nsd(), INDEXNO( "a" << 1 ), FBS( BSON( "a" << "r" << "b" << NE << "q" ) ), FBS2( BSON( "a" << "r" << "b" << NE << "q" ) ), BSON( "a" << "r" << "b" << NE << "q" ), BSON( "a" << 1 ) );
- ASSERT( !p.exactKeyMatch() );
+ ASSERT( !p.exactKeyMatch() );
}
};
-
+
class ExactKeyQueryTypes : public Base {
public:
void run() {
@@ -991,7 +991,7 @@ namespace QueryOptimizerTests {
ASSERT( !p5.exactKeyMatch() );
}
};
-
+
class Unhelpful : public Base {
public:
void run() {
@@ -1010,13 +1010,13 @@ namespace QueryOptimizerTests {
ASSERT( p4.unhelpful() );
}
};
-
+
} // namespace QueryPlanTests
namespace QueryPlanSetTests {
class Base {
public:
- Base() : _context( ns() ){
+ Base() : _context( ns() ) {
string err;
userCreateNS( ns(), BSONObj(), err, false );
}
@@ -1039,7 +1039,7 @@ namespace QueryOptimizerTests {
if ( fieldsToReturn )
fieldsToReturn->appendSelfToBufBuilder(b);
toSend.setData(dbQuery, b.buf(), b.len());
- }
+ }
protected:
static const char *ns() { return "unittests.QueryPlanSetTests"; }
static NamespaceDetails *nsd() { return nsdetails( ns() ); }
@@ -1047,7 +1047,7 @@ namespace QueryOptimizerTests {
dblock lk_;
Client::Context _context;
};
-
+
class NoIndexes : public Base {
public:
void run() {
@@ -1057,7 +1057,7 @@ namespace QueryOptimizerTests {
ASSERT_EQUALS( 1, s.nPlans() );
}
};
-
+
class Optimal : public Base {
public:
void run() {
@@ -1066,7 +1066,7 @@ namespace QueryOptimizerTests {
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), BSON( "a" << 4 ) ) );
auto_ptr< FieldRangeSet > frsOrig( new FieldRangeSet( *frs ) );
QueryPlanSet s( ns(), frs, frsOrig, BSON( "a" << 4 ), BSONObj() );
- ASSERT_EQUALS( 1, s.nPlans() );
+ ASSERT_EQUALS( 1, s.nPlans() );
}
};
@@ -1093,7 +1093,7 @@ namespace QueryOptimizerTests {
ASSERT_EQUALS( 1, s.nPlans() );
}
};
-
+
class HintSpec : public Base {
public:
void run() {
@@ -1104,7 +1104,7 @@ namespace QueryOptimizerTests {
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), BSON( "a" << 1 ) ) );
auto_ptr< FieldRangeSet > frsOrig( new FieldRangeSet( *frs ) );
QueryPlanSet s( ns(), frs, frsOrig, BSON( "a" << 1 ), BSON( "b" << 1 ), &e );
- ASSERT_EQUALS( 1, s.nPlans() );
+ ASSERT_EQUALS( 1, s.nPlans() );
}
};
@@ -1118,10 +1118,10 @@ namespace QueryOptimizerTests {
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), BSON( "a" << 1 ) ) );
auto_ptr< FieldRangeSet > frsOrig( new FieldRangeSet( *frs ) );
QueryPlanSet s( ns(), frs, frsOrig, BSON( "a" << 1 ), BSON( "b" << 1 ), &e );
- ASSERT_EQUALS( 1, s.nPlans() );
+ ASSERT_EQUALS( 1, s.nPlans() );
}
};
-
+
class NaturalHint : public Base {
public:
void run() {
@@ -1132,7 +1132,7 @@ namespace QueryOptimizerTests {
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), BSON( "a" << 1 ) ) );
auto_ptr< FieldRangeSet > frsOrig( new FieldRangeSet( *frs ) );
QueryPlanSet s( ns(), frs, frsOrig, BSON( "a" << 1 ), BSON( "b" << 1 ), &e );
- ASSERT_EQUALS( 1, s.nPlans() );
+ ASSERT_EQUALS( 1, s.nPlans() );
}
};
@@ -1156,10 +1156,10 @@ namespace QueryOptimizerTests {
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), BSON( "a" << 1 ) ) );
auto_ptr< FieldRangeSet > frsOrig( new FieldRangeSet( *frs ) );
ASSERT_EXCEPTION( QueryPlanSet s( ns(), frs, frsOrig, BSON( "a" << 1 ), BSON( "b" << 1 ), &e ),
- AssertionException );
+ AssertionException );
}
};
-
+
class Count : public Base {
public:
void run() {
@@ -1184,7 +1184,7 @@ namespace QueryOptimizerTests {
ASSERT_EQUALS( 0, runCount( ns(), BSON( "query" << BSON( "a" << GT << 0 << LT << -1 ) ), err ) );
}
};
-
+
class QueryMissingNs : public Base {
public:
QueryMissingNs() { log() << "querymissingns starts" << endl; }
@@ -1202,7 +1202,7 @@ namespace QueryOptimizerTests {
}
};
-
+
class UnhelpfulIndex : public Base {
public:
void run() {
@@ -1211,10 +1211,10 @@ namespace QueryOptimizerTests {
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), BSON( "a" << 1 << "c" << 2 ) ) );
auto_ptr< FieldRangeSet > frsOrig( new FieldRangeSet( *frs ) );
QueryPlanSet s( ns(), frs, frsOrig, BSON( "a" << 1 << "c" << 2 ), BSONObj() );
- ASSERT_EQUALS( 2, s.nPlans() );
+ ASSERT_EQUALS( 2, s.nPlans() );
}
- };
-
+ };
+
class SingleException : public Base {
public:
void run() {
@@ -1258,7 +1258,7 @@ namespace QueryOptimizerTests {
mutable bool youThrow_;
};
};
-
+
class AllException : public Base {
public:
void run() {
@@ -1288,7 +1288,7 @@ namespace QueryOptimizerTests {
virtual long long nscanned() { return 0; }
};
};
-
+
class SaveGoodIndex : public Base {
public:
void run() {
@@ -1302,7 +1302,7 @@ namespace QueryOptimizerTests {
nPlans( 3 );
runQuery();
nPlans( 1 );
-
+
{
DBDirectClient client;
for( int i = 0; i < 34; ++i ) {
@@ -1312,7 +1312,7 @@ namespace QueryOptimizerTests {
}
}
nPlans( 3 );
-
+
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), BSON( "a" << 4 ) ) );
auto_ptr< FieldRangeSet > frsOrig( new FieldRangeSet( *frs ) );
QueryPlanSet s( ns(), frs, frsOrig, BSON( "a" << 4 ), BSON( "b" << 1 ) );
@@ -1334,8 +1334,8 @@ namespace QueryOptimizerTests {
QueryPlanSet s3( ns(), frs3, frsOrig3, BSON( "a" << 4 ), BSON( "b" << 1 << "c" << 1 ) );
TestOp newerOriginal;
s3.runOp( newerOriginal );
- nPlans( 3 );
-
+ nPlans( 3 );
+
runQuery();
nPlans( 1 );
}
@@ -1344,7 +1344,7 @@ namespace QueryOptimizerTests {
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), BSON( "a" << 4 ) ) );
auto_ptr< FieldRangeSet > frsOrig( new FieldRangeSet( *frs ) );
QueryPlanSet s( ns(), frs, frsOrig, BSON( "a" << 4 ), BSON( "b" << 1 ) );
- ASSERT_EQUALS( n, s.nPlans() );
+ ASSERT_EQUALS( n, s.nPlans() );
}
void runQuery() {
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), BSON( "a" << 4 ) ) );
@@ -1369,8 +1369,8 @@ namespace QueryOptimizerTests {
virtual bool mayRecordPlan() const { return false; }
virtual QueryOp *_createChild() const { return new NoRecordTestOp(); }
};
- };
-
+ };
+
class TryAllPlansOnErr : public Base {
public:
void run() {
@@ -1383,7 +1383,7 @@ namespace QueryOptimizerTests {
s.runOp( op );
ASSERT( fromjson( "{$natural:1}" ).woCompare( NamespaceDetailsTransient::_get( ns() ).indexForPattern( s.fbs().pattern( BSON( "b" << 1 ) ) ) ) == 0 );
ASSERT_EQUALS( 1, NamespaceDetailsTransient::_get( ns() ).nScannedForPattern( s.fbs().pattern( BSON( "b" << 1 ) ) ) );
-
+
auto_ptr< FieldRangeSet > frs2( new FieldRangeSet( ns(), BSON( "a" << 4 ) ) );
auto_ptr< FieldRangeSet > frsOrig2( new FieldRangeSet( *frs2 ) );
QueryPlanSet s2( ns(), frs2, frsOrig2, BSON( "a" << 4 ), BSON( "b" << 1 ) );
@@ -1417,7 +1417,7 @@ namespace QueryOptimizerTests {
}
};
};
-
+
class FindOne : public Base {
public:
void run() {
@@ -1425,12 +1425,12 @@ namespace QueryOptimizerTests {
theDataFileMgr.insertWithObjMod( ns(), one );
BSONObj result;
ASSERT( Helpers::findOne( ns(), BSON( "a" << 1 ), result ) );
- ASSERT_EXCEPTION( Helpers::findOne( ns(), BSON( "a" << 1 ), result, true ), AssertionException );
+ ASSERT_EXCEPTION( Helpers::findOne( ns(), BSON( "a" << 1 ), result, true ), AssertionException );
Helpers::ensureIndex( ns(), BSON( "a" << 1 ), false, "a_1" );
- ASSERT( Helpers::findOne( ns(), BSON( "a" << 1 ), result, true ) );
+ ASSERT( Helpers::findOne( ns(), BSON( "a" << 1 ), result, true ) );
}
};
-
+
class Delete : public Base {
public:
void run() {
@@ -1446,7 +1446,7 @@ namespace QueryOptimizerTests {
ASSERT_EQUALS( 1, NamespaceDetailsTransient::_get( ns() ).nScannedForPattern( FieldRangeSet( ns(), BSON( "a" << 1 ) ).pattern() ) );
}
};
-
+
class DeleteOneScan : public Base {
public:
void run() {
@@ -1499,7 +1499,7 @@ namespace QueryOptimizerTests {
runQuery( m, q);
}
ASSERT( BSON( "$natural" << 1 ).woCompare( NamespaceDetailsTransient::_get( ns() ).indexForPattern( FieldRangeSet( ns(), BSON( "b" << 0 << "a" << GTE << 0 ) ).pattern() ) ) == 0 );
-
+
Message m2;
assembleRequest( ns(), QUERY( "b" << 99 << "a" << GTE << 0 ).obj, 2, 0, 0, 0, m2 );
{
@@ -1507,11 +1507,11 @@ namespace QueryOptimizerTests {
QueryMessage q(d);
runQuery( m2, q);
}
- ASSERT( BSON( "a" << 1 ).woCompare( NamespaceDetailsTransient::_get( ns() ).indexForPattern( FieldRangeSet( ns(), BSON( "b" << 0 << "a" << GTE << 0 ) ).pattern() ) ) == 0 );
+ ASSERT( BSON( "a" << 1 ).woCompare( NamespaceDetailsTransient::_get( ns() ).indexForPattern( FieldRangeSet( ns(), BSON( "b" << 0 << "a" << GTE << 0 ) ).pattern() ) ) == 0 );
ASSERT_EQUALS( 3, NamespaceDetailsTransient::_get( ns() ).nScannedForPattern( FieldRangeSet( ns(), BSON( "b" << 0 << "a" << GTE << 0 ) ).pattern() ) );
}
};
-
+
class InQueryIntervals : public Base {
public:
void run() {
@@ -1532,7 +1532,7 @@ namespace QueryOptimizerTests {
ASSERT_EQUALS( expected[ i ], c->current().getField( "a" ).number() );
}
ASSERT( !c->ok() );
-
+
// now check reverse
{
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), fromjson( "{a:{$in:[2,3,6,9,11]}}" ) ) );
@@ -1544,11 +1544,11 @@ namespace QueryOptimizerTests {
for( int i = 0; i < 4; ++i, c->advance() ) {
ASSERT_EQUALS( expected[ i ], c->current().getField( "a" ).number() );
}
- ASSERT( !c->ok() );
+ ASSERT( !c->ok() );
}
}
};
-
+
class EqualityThenIn : public Base {
public:
void run() {
@@ -1559,7 +1559,7 @@ namespace QueryOptimizerTests {
}
BSONObj hint = fromjson( "{$hint:{a:1,b:1}}" );
BSONElement hintElt = hint.firstElement();
- auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), fromjson( "{a:5,b:{$in:[2,3,6,9,11]}}" ) ) );
+ auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns(), fromjson( "{a:5,b:{$in:[2,3,6,9,11]}}" ) ) );
QueryPlan qp( nsd(), 1, *frs, *frs, fromjson( "{a:5,b:{$in:[2,3,6,9,11]}}" ), BSONObj() );
boost::shared_ptr<Cursor> c = qp.newCursor();
double expected[] = { 2, 3, 6, 9 };
@@ -1571,7 +1571,7 @@ namespace QueryOptimizerTests {
ASSERT( !c->ok() );
}
};
-
+
class NotEqualityThenIn : public Base {
public:
void run() {
@@ -1594,7 +1594,7 @@ namespace QueryOptimizerTests {
};
} // namespace QueryPlanSetTests
-
+
class Base {
public:
Base() : _ctx( ns() ) {
@@ -1614,7 +1614,7 @@ namespace QueryOptimizerTests {
dblock lk_;
Client::Context _ctx;
};
-
+
class BestGuess : public Base {
public:
void run() {
@@ -1624,7 +1624,7 @@ namespace QueryOptimizerTests {
theDataFileMgr.insertWithObjMod( ns(), temp );
temp = BSON( "b" << 1 );
theDataFileMgr.insertWithObjMod( ns(), temp );
-
+
boost::shared_ptr< Cursor > c = bestGuessCursor( ns(), BSON( "b" << 1 ), BSON( "a" << 1 ) );
ASSERT_EQUALS( string( "a" ), c->indexKeyPattern().firstElement().fieldName() );
c = bestGuessCursor( ns(), BSON( "a" << 1 ), BSON( "b" << 1 ) );
@@ -1633,22 +1633,22 @@ namespace QueryOptimizerTests {
ASSERT_EQUALS( string( "a" ), m->sub_c()->indexKeyPattern().firstElement().fieldName() );
m = dynamic_pointer_cast< MultiCursor >( bestGuessCursor( ns(), fromjson( "{a:1,$or:[{y:1}]}" ), BSON( "b" << 1 ) ) );
ASSERT_EQUALS( string( "b" ), m->sub_c()->indexKeyPattern().firstElement().fieldName() );
-
+
FieldRangeSet frs( "ns", BSON( "a" << 1 ) );
{
scoped_lock lk(NamespaceDetailsTransient::_qcMutex);
- NamespaceDetailsTransient::get_inlock( ns() ).registerIndexForPattern( frs.pattern( BSON( "b" << 1 ) ), BSON( "a" << 1 ), 0 );
+ NamespaceDetailsTransient::get_inlock( ns() ).registerIndexForPattern( frs.pattern( BSON( "b" << 1 ) ), BSON( "a" << 1 ), 0 );
}
m = dynamic_pointer_cast< MultiCursor >( bestGuessCursor( ns(), fromjson( "{a:1,$or:[{y:1}]}" ), BSON( "b" << 1 ) ) );
ASSERT_EQUALS( string( "b" ), m->sub_c()->indexKeyPattern().firstElement().fieldName() );
}
};
-
+
class All : public Suite {
public:
- All() : Suite( "queryoptimizer" ){}
-
- void setupTests(){
+ All() : Suite( "queryoptimizer" ) {}
+
+ void setupTests() {
add< FieldRangeTests::Empty >();
add< FieldRangeTests::Eq >();
add< FieldRangeTests::DupEq >();
@@ -1780,6 +1780,6 @@ namespace QueryOptimizerTests {
add< BestGuess >();
}
} myall;
-
+
} // namespace QueryOptimizerTests
diff --git a/dbtests/querytests.cpp b/dbtests/querytests.cpp
index e512640bca6..9b86c1c6e90 100644
--- a/dbtests/querytests.cpp
+++ b/dbtests/querytests.cpp
@@ -39,7 +39,7 @@ namespace QueryTests {
dblock lk;
Client::Context _context;
public:
- Base() : _context( ns() ){
+ Base() : _context( ns() ) {
addIndex( fromjson( "{\"a\":1}" ) );
}
~Base() {
@@ -50,7 +50,8 @@ namespace QueryTests {
toDelete.push_back( c->currLoc() );
for( vector< DiskLoc >::iterator i = toDelete.begin(); i != toDelete.end(); ++i )
theDataFileMgr.deleteRecord( ns(), i->rec(), *i, false );
- } catch ( ... ) {
+ }
+ catch ( ... ) {
FAIL( "Exception while cleaning up records" );
}
}
@@ -131,7 +132,7 @@ namespace QueryTests {
ASSERT_EQUALS( 1, runCount( ns(), cmd, err ) );
}
};
-
+
class FindOne : public Base {
public:
void run() {
@@ -214,7 +215,7 @@ namespace QueryTests {
client().dropCollection( ns );
}
- void testLimit(int limit){
+ void testLimit(int limit) {
ASSERT_EQUALS(client().query( ns, BSONObj(), limit )->itcount(), limit);
}
void run() {
@@ -289,7 +290,7 @@ namespace QueryTests {
insert( ns, BSON( "a" << 0 ) );
c = client().query( ns, QUERY( "a" << 1 ).hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable );
ASSERT( 0 != c->getCursorId() );
- ASSERT( !c->isDead() );
+ ASSERT( !c->isDead() );
}
};
@@ -349,7 +350,7 @@ namespace QueryTests {
ASSERT( !client().getLastError().empty() );
}
};
-
+
class TailableQueryOnId : public ClientBase {
public:
~TailableQueryOnId() {
@@ -515,7 +516,7 @@ namespace QueryTests {
static const char *ns() { return "unittests.querytests.AutoResetIndexCache"; }
static const char *idxNs() { return "unittests.system.indexes"; }
void index() const { ASSERT( !client().findOne( idxNs(), BSON( "name" << NE << "_id_" ) ).isEmpty() ); }
- void noIndex() const {
+ void noIndex() const {
BSONObj o = client().findOne( idxNs(), BSON( "name" << NE << "_id_" ) );
if( !o.isEmpty() ) {
cout << o.toString() << endl;
@@ -608,8 +609,8 @@ namespace QueryTests {
client().insert( ns, fromjson( "{a:[1,2,3]}" ) );
ASSERT( client().query( ns, Query( "{a:[1,2,3]}" ) )->more() );
client().ensureIndex( ns, BSON( "a" << 1 ) );
- ASSERT( client().query( ns, Query( "{a:{$in:[1,[1,2,3]]}}" ).hint( BSON( "a" << 1 ) ) )->more() );
- ASSERT( client().query( ns, Query( "{a:[1,2,3]}" ).hint( BSON( "a" << 1 ) ) )->more() ); // SERVER-146
+ ASSERT( client().query( ns, Query( "{a:{$in:[1,[1,2,3]]}}" ).hint( BSON( "a" << 1 ) ) )->more() );
+ ASSERT( client().query( ns, Query( "{a:[1,2,3]}" ).hint( BSON( "a" << 1 ) ) )->more() ); // SERVER-146
}
};
@@ -623,7 +624,7 @@ namespace QueryTests {
client().insert( ns, fromjson( "{a:[[1],2]}" ) );
check( "$natural" );
client().ensureIndex( ns, BSON( "a" << 1 ) );
- check( "a" ); // SERVER-146
+ check( "a" ); // SERVER-146
}
private:
void check( const string &hintField ) {
@@ -766,12 +767,12 @@ namespace QueryTests {
class DifferentNumbers : public ClientBase {
public:
- ~DifferentNumbers(){
+ ~DifferentNumbers() {
client().dropCollection( "unittests.querytests.DifferentNumbers" );
}
- void t( const char * ns ){
+ void t( const char * ns ) {
auto_ptr< DBClientCursor > cursor = client().query( ns, Query().sort( "7" ) );
- while ( cursor->more() ){
+ while ( cursor->more() ) {
BSONObj o = cursor->next();
assert( o.valid() );
//cout << " foo " << o << endl;
@@ -792,37 +793,37 @@ namespace QueryTests {
t(ns);
}
};
-
+
class CollectionBase : public ClientBase {
public:
-
- CollectionBase( string leaf ){
+
+ CollectionBase( string leaf ) {
_ns = "unittests.querytests.";
_ns += leaf;
client().dropCollection( ns() );
}
-
- virtual ~CollectionBase(){
+
+ virtual ~CollectionBase() {
client().dropCollection( ns() );
}
-
- int count(){
+
+ int count() {
return (int) client().count( ns() );
}
- const char * ns(){
+ const char * ns() {
return _ns.c_str();
}
-
+
private:
string _ns;
};
class SymbolStringSame : public CollectionBase {
public:
- SymbolStringSame() : CollectionBase( "symbolstringsame" ){}
+ SymbolStringSame() : CollectionBase( "symbolstringsame" ) {}
- void run(){
+ void run() {
{ BSONObjBuilder b; b.appendSymbol( "x" , "eliot" ); b.append( "z" , 17 ); client().insert( ns() , b.obj() ); }
ASSERT_EQUALS( 17 , client().findOne( ns() , BSONObj() )["z"].number() );
{
@@ -838,46 +839,46 @@ namespace QueryTests {
class TailableCappedRaceCondition : public CollectionBase {
public:
-
- TailableCappedRaceCondition() : CollectionBase( "tailablecappedrace" ){
+
+ TailableCappedRaceCondition() : CollectionBase( "tailablecappedrace" ) {
client().dropCollection( ns() );
_n = 0;
}
- void run(){
+ void run() {
string err;
- writelock lk("");
+ writelock lk("");
Client::Context ctx( "unittests" );
ASSERT( userCreateNS( ns() , fromjson( "{ capped : true , size : 2000 }" ) , err , false ) );
- for ( int i=0; i<100; i++ ){
+ for ( int i=0; i<100; i++ ) {
insertNext();
ASSERT( count() < 45 );
}
-
+
int a = count();
-
+
auto_ptr< DBClientCursor > c = client().query( ns() , QUERY( "i" << GT << 0 ).hint( BSON( "$natural" << 1 ) ), 0, 0, 0, QueryOption_CursorTailable );
int n=0;
- while ( c->more() ){
+ while ( c->more() ) {
BSONObj z = c->next();
n++;
}
-
+
ASSERT_EQUALS( a , n );
insertNext();
ASSERT( c->more() );
- for ( int i=0; i<50; i++ ){
+ for ( int i=0; i<50; i++ ) {
insertNext();
}
- while ( c->more() ){ c->next(); }
+ while ( c->more() ) { c->next(); }
ASSERT( c->isDead() );
}
-
- void insertNext(){
+
+ void insertNext() {
insert( ns() , BSON( "i" << _n++ ) );
}
@@ -886,71 +887,71 @@ namespace QueryTests {
class HelperTest : public CollectionBase {
public:
-
- HelperTest() : CollectionBase( "helpertest" ){
+
+ HelperTest() : CollectionBase( "helpertest" ) {
}
- void run(){
+ void run() {
writelock lk("");
Client::Context ctx( "unittests" );
-
- for ( int i=0; i<50; i++ ){
+
+ for ( int i=0; i<50; i++ ) {
insert( ns() , BSON( "_id" << i << "x" << i * 2 ) );
}
ASSERT_EQUALS( 50 , count() );
-
+
BSONObj res;
ASSERT( Helpers::findOne( ns() , BSON( "_id" << 20 ) , res , true ) );
ASSERT_EQUALS( 40 , res["x"].numberInt() );
-
+
ASSERT( Helpers::findById( cc(), ns() , BSON( "_id" << 20 ) , res ) );
ASSERT_EQUALS( 40 , res["x"].numberInt() );
ASSERT( ! Helpers::findById( cc(), ns() , BSON( "_id" << 200 ) , res ) );
unsigned long long slow , fast;
-
+
int n = 10000;
{
Timer t;
- for ( int i=0; i<n; i++ ){
+ for ( int i=0; i<n; i++ ) {
ASSERT( Helpers::findOne( ns() , BSON( "_id" << 20 ) , res , true ) );
}
slow = t.micros();
}
{
Timer t;
- for ( int i=0; i<n; i++ ){
+ for ( int i=0; i<n; i++ ) {
ASSERT( Helpers::findById( cc(), ns() , BSON( "_id" << 20 ) , res ) );
}
fast = t.micros();
}
-
+
cout << "HelperTest slow:" << slow << " fast:" << fast << endl;
-
+
}
};
class HelperByIdTest : public CollectionBase {
public:
-
- HelperByIdTest() : CollectionBase( "helpertestbyid" ){
+
+ HelperByIdTest() : CollectionBase( "helpertestbyid" ) {
}
- void run(){
+ void run() {
writelock lk("");
Client::Context ctx( "unittests" );
- for ( int i=0; i<1000; i++ ){
+ for ( int i=0; i<1000; i++ ) {
insert( ns() , BSON( "_id" << i << "x" << i * 2 ) );
}
- for ( int i=0; i<1000; i+=2 ){
+ for ( int i=0; i<1000; i+=2 ) {
client_.remove( ns() , BSON( "_id" << i ) );
}
- BSONObj res;
- for ( int i=0; i<1000; i++ ){
+ BSONObj res;
+ for ( int i=0; i<1000; i++ ) {
bool found = Helpers::findById( cc(), ns() , BSON( "_id" << i ) , res );
ASSERT_EQUALS( i % 2 , int(found) );
}
@@ -958,19 +959,19 @@ namespace QueryTests {
}
};
- class ClientCursorTest : public CollectionBase{
- ClientCursorTest() : CollectionBase( "clientcursortest" ){
+ class ClientCursorTest : public CollectionBase {
+ ClientCursorTest() : CollectionBase( "clientcursortest" ) {
}
- void run(){
+ void run() {
writelock lk("");
Client::Context ctx( "unittests" );
-
- for ( int i=0; i<1000; i++ ){
+
+ for ( int i=0; i<1000; i++ ) {
insert( ns() , BSON( "_id" << i << "x" << i * 2 ) );
}
-
+
}
};
@@ -982,19 +983,19 @@ namespace QueryTests {
~FindingStart() {
__findingStartInitialTimeout = _old;
}
-
+
void run() {
BSONObj info;
ASSERT( client().runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "size" << 1000 << "$nExtents" << 5 << "autoIndexId" << false ), info ) );
-
+
int i = 0;
for( int oldCount = -1;
- count() != oldCount;
- oldCount = count(), client().insert( ns(), BSON( "ts" << i++ ) ) );
+ count() != oldCount;
+ oldCount = count(), client().insert( ns(), BSON( "ts" << i++ ) ) );
for( int k = 0; k < 5; ++k ) {
client().insert( ns(), BSON( "ts" << i++ ) );
- int min = client().query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt();
+ int min = client().query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt();
for( int j = -1; j < i; ++j ) {
auto_ptr< DBClientCursor > c = client().query( ns(), QUERY( "ts" << GTE << j ), 0, 0, 0, QueryOption_OplogReplay );
ASSERT( c->more() );
@@ -1004,7 +1005,7 @@ namespace QueryTests {
}
}
}
-
+
private:
int _old;
};
@@ -1017,17 +1018,17 @@ namespace QueryTests {
~FindingStartPartiallyFull() {
__findingStartInitialTimeout = _old;
}
-
+
void run() {
BSONObj info;
ASSERT( client().runCommand( "unittests", BSON( "create" << "querytests.findingstart" << "capped" << true << "size" << 10000 << "$nExtents" << 5 << "autoIndexId" << false ), info ) );
-
+
int i = 0;
for( ; i < 150; client().insert( ns(), BSON( "ts" << i++ ) ) );
-
+
for( int k = 0; k < 5; ++k ) {
client().insert( ns(), BSON( "ts" << i++ ) );
- int min = client().query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt();
+ int min = client().query( ns(), Query().sort( BSON( "$natural" << 1 ) ) )->next()[ "ts" ].numberInt();
for( int j = -1; j < i; ++j ) {
auto_ptr< DBClientCursor > c = client().query( ns(), QUERY( "ts" << GTE << j ), 0, 0, 0, QueryOption_OplogReplay );
ASSERT( c->more() );
@@ -1037,12 +1038,12 @@ namespace QueryTests {
}
}
}
-
+
private:
int _old;
};
-
-
+
+
class WhatsMyUri : public CollectionBase {
public:
WhatsMyUri() : CollectionBase( "whatsmyuri" ) {}
@@ -1052,15 +1053,15 @@ namespace QueryTests {
ASSERT_EQUALS( unknownAddress.toString(), result[ "you" ].str() );
}
};
-
+
namespace parsedtests {
class basic1 {
public:
- void _test( const BSONObj& in ){
+ void _test( const BSONObj& in ) {
ParsedQuery q( "a.b" , 5 , 6 , 9 , in , BSONObj() );
ASSERT_EQUALS( BSON( "x" << 5 ) , q.getFilter() );
}
- void run(){
+ void run() {
_test( BSON( "x" << 5 ) );
_test( BSON( "query" << BSON( "x" << 5 ) ) );
_test( BSON( "$query" << BSON( "x" << 5 ) ) );
@@ -1082,23 +1083,23 @@ namespace QueryTests {
namespace queryobjecttests {
class names1 {
public:
- void run(){
+ void run() {
ASSERT_EQUALS( BSON( "x" << 1 ) , QUERY( "query" << BSON( "x" << 1 ) ).getFilter() );
ASSERT_EQUALS( BSON( "x" << 1 ) , QUERY( "$query" << BSON( "x" << 1 ) ).getFilter() );
}
-
+
};
}
class OrderingTest {
public:
- void run(){
+ void run() {
{
Ordering o = Ordering::make( BSON( "a" << 1 << "b" << -1 << "c" << 1 ) );
ASSERT_EQUALS( 1 , o.get(0) );
ASSERT_EQUALS( -1 , o.get(1) );
ASSERT_EQUALS( 1 , o.get(2) );
-
+
ASSERT( ! o.descending( 1 ) );
ASSERT( o.descending( 1 << 1 ) );
ASSERT( ! o.descending( 1 << 2 ) );
@@ -1109,7 +1110,7 @@ namespace QueryTests {
ASSERT_EQUALS( 1 , o.get(0) );
ASSERT_EQUALS( 1 , o.get(1) );
ASSERT_EQUALS( -1 , o.get(2) );
-
+
ASSERT( ! o.descending( 1 ) );
ASSERT( ! o.descending( 1 << 1 ) );
ASSERT( o.descending( 1 << 2 ) );
@@ -1122,8 +1123,8 @@ namespace QueryTests {
class T1 {
public:
- void run(){
-
+ void run() {
+
Projection m;
m.init( BSON( "a" << 1 ) );
ASSERT_EQUALS( BSON( "a" << 5 ) , m.transform( BSON( "x" << 1 << "a" << 5 ) ) );
@@ -1132,18 +1133,18 @@ namespace QueryTests {
class K1 {
public:
- void run(){
-
+ void run() {
+
Projection m;
m.init( BSON( "a" << 1 ) );
- scoped_ptr<Projection::KeyOnly> x( m.checkKey( BSON( "a" << 1 ) ) );
+ scoped_ptr<Projection::KeyOnly> x( m.checkKey( BSON( "a" << 1 ) ) );
ASSERT( ! x );
x.reset( m.checkKey( BSON( "a" << 1 << "_id" << 1 ) ) );
ASSERT( x );
- ASSERT_EQUALS( BSON( "a" << 5 << "_id" << 17 ) ,
+ ASSERT_EQUALS( BSON( "a" << 5 << "_id" << 17 ) ,
x->hydrate( BSON( "" << 5 << "" << 17 ) ) );
x.reset( m.checkKey( BSON( "a" << 1 << "x" << 1 << "_id" << 1 ) ) );
@@ -1157,15 +1158,15 @@ namespace QueryTests {
class K2 {
public:
- void run(){
-
+ void run() {
+
Projection m;
m.init( BSON( "a" << 1 << "_id" << 0 ) );
- scoped_ptr<Projection::KeyOnly> x( m.checkKey( BSON( "a" << 1 ) ) );
+ scoped_ptr<Projection::KeyOnly> x( m.checkKey( BSON( "a" << 1 ) ) );
ASSERT( x );
- ASSERT_EQUALS( BSON( "a" << 17 ) ,
+ ASSERT_EQUALS( BSON( "a" << 17 ) ,
x->hydrate( BSON( "" << 17 ) ) );
x.reset( m.checkKey( BSON( "x" << 1 << "a" << 1 << "_id" << 1 ) ) );
@@ -1180,13 +1181,13 @@ namespace QueryTests {
class K3 {
public:
- void run(){
-
+ void run() {
+
{
Projection m;
m.init( BSON( "a" << 1 << "_id" << 0 ) );
-
- scoped_ptr<Projection::KeyOnly> x( m.checkKey( BSON( "a" << 1 << "x.a" << 1 ) ) );
+
+ scoped_ptr<Projection::KeyOnly> x( m.checkKey( BSON( "a" << 1 << "x.a" << 1 ) ) );
ASSERT( x );
}
@@ -1195,8 +1196,8 @@ namespace QueryTests {
// TODO: this is temporary SERVER-2104
Projection m;
m.init( BSON( "x.a" << 1 << "_id" << 0 ) );
-
- scoped_ptr<Projection::KeyOnly> x( m.checkKey( BSON( "a" << 1 << "x.a" << 1 ) ) );
+
+ scoped_ptr<Projection::KeyOnly> x( m.checkKey( BSON( "a" << 1 << "x.a" << 1 ) ) );
ASSERT( ! x );
}
@@ -1211,7 +1212,7 @@ namespace QueryTests {
All() : Suite( "query" ) {
}
- void setupTests(){
+ void setupTests() {
add< CountBasic >();
add< CountQuery >();
add< CountFields >();
@@ -1256,9 +1257,9 @@ namespace QueryTests {
add< FindingStart >();
add< FindingStartPartiallyFull >();
add< WhatsMyUri >();
-
+
add< parsedtests::basic1 >();
-
+
add< queryobjecttests::names1 >();
add< OrderingTest >();
@@ -1269,6 +1270,6 @@ namespace QueryTests {
add< proj::K3 >();
}
} myall;
-
+
} // namespace QueryTests
diff --git a/dbtests/repltests.cpp b/dbtests/repltests.cpp
index 33d2118f241..c6ffba28646 100644
--- a/dbtests/repltests.cpp
+++ b/dbtests/repltests.cpp
@@ -34,13 +34,13 @@ namespace ReplTests {
BSONObj f( const char *s ) {
return fromjson( s );
- }
-
+ }
+
class Base {
dblock lk;
Client::Context _context;
public:
- Base() : _context( ns() ){
+ Base() : _context( ns() ) {
replSettings.master = true;
createOplog();
ensureHaveIdIndex( ns() );
@@ -50,7 +50,8 @@ namespace ReplTests {
replSettings.master = false;
deleteAll( ns() );
deleteAll( cllNS() );
- } catch ( ... ) {
+ }
+ catch ( ... ) {
FAIL( "Exception while cleaning up test" );
}
}
@@ -63,7 +64,7 @@ namespace ReplTests {
}
DBDirectClient *client() const { return &client_; }
BSONObj one( const BSONObj &query = BSONObj() ) const {
- return client()->findOne( ns(), query );
+ return client()->findOne( ns(), query );
}
void checkOne( const BSONObj &o ) const {
check( o, one( o ) );
@@ -78,11 +79,11 @@ namespace ReplTests {
void check( const BSONObj &expected, const BSONObj &got ) const {
if ( expected.woCompare( got ) ) {
out() << "expected: " << expected.toString()
- << ", got: " << got.toString() << endl;
+ << ", got: " << got.toString() << endl;
}
ASSERT_EQUALS( expected , got );
}
- BSONObj oneOp() const {
+ BSONObj oneOp() const {
return client()->findOne( cllNS(), BSONObj() );
}
int count() const {
@@ -131,7 +132,7 @@ namespace ReplTests {
out() << "all for " << ns << endl;
for(; c->ok(); c->advance() ) {
out() << c->current().toString() << endl;
- }
+ }
}
// These deletes don't get logged.
static void deleteAll( const char *ns ) {
@@ -143,7 +144,7 @@ namespace ReplTests {
toDelete.push_back( c->currLoc() );
}
for( vector< DiskLoc >::iterator i = toDelete.begin(); i != toDelete.end(); ++i ) {
- theDataFileMgr.deleteRecord( ns, i->rec(), *i, true );
+ theDataFileMgr.deleteRecord( ns, i->rec(), *i, true );
}
}
static void insert( const BSONObj &o, bool god = false ) {
@@ -163,7 +164,7 @@ namespace ReplTests {
static DBDirectClient client_;
};
DBDirectClient Base::client_;
-
+
class LogBasic : public Base {
public:
void run() {
@@ -172,9 +173,9 @@ namespace ReplTests {
ASSERT_EQUALS( 2, opCount() );
}
};
-
+
namespace Idempotence {
-
+
class Base : public ReplTests::Base {
public:
virtual ~Base() {}
@@ -186,7 +187,7 @@ namespace ReplTests {
applyAllOperations();
check();
ASSERT_EQUALS( nOps, opCount() );
-
+
reset();
applyAllOperations();
check();
@@ -200,7 +201,7 @@ namespace ReplTests {
virtual void check() const = 0;
virtual void reset() const = 0;
};
-
+
class InsertTimestamp : public Base {
public:
void doIt() const {
@@ -221,7 +222,7 @@ namespace ReplTests {
private:
mutable Date_t date_;
};
-
+
class InsertAutoId : public Base {
public:
InsertAutoId() : o_( fromjson( "{\"a\":\"b\"}" ) ) {}
@@ -248,12 +249,12 @@ namespace ReplTests {
checkOne( o_ );
}
};
-
+
class InsertTwo : public Base {
public:
- InsertTwo() :
- o_( fromjson( "{'_id':1,a:'b'}" ) ),
- t_( fromjson( "{'_id':2,c:'d'}" ) ) {}
+ InsertTwo() :
+ o_( fromjson( "{'_id':1,a:'b'}" ) ),
+ t_( fromjson( "{'_id':2,c:'d'}" ) ) {}
void doIt() const {
vector< BSONObj > v;
v.push_back( o_ );
@@ -287,7 +288,7 @@ namespace ReplTests {
deleteAll( ns() );
}
private:
- BSONObj o_;
+ BSONObj o_;
};
class UpdateTimestamp : public Base {
@@ -311,14 +312,14 @@ namespace ReplTests {
private:
mutable Date_t date_;
};
-
+
class UpdateSameField : public Base {
public:
UpdateSameField() :
- q_( fromjson( "{a:'b'}" ) ),
- o1_( wid( "{a:'b'}" ) ),
- o2_( wid( "{a:'b'}" ) ),
- u_( fromjson( "{a:'c'}" ) ){}
+ q_( fromjson( "{a:'b'}" ) ),
+ o1_( wid( "{a:'b'}" ) ),
+ o2_( wid( "{a:'b'}" ) ),
+ u_( fromjson( "{a:'c'}" ) ) {}
void doIt() const {
client()->update( ns(), q_, u_ );
}
@@ -334,14 +335,14 @@ namespace ReplTests {
}
private:
BSONObj q_, o1_, o2_, u_;
- };
-
+ };
+
class UpdateSameFieldWithId : public Base {
public:
UpdateSameFieldWithId() :
- o_( fromjson( "{'_id':1,a:'b'}" ) ),
- q_( fromjson( "{a:'b'}" ) ),
- u_( fromjson( "{'_id':1,a:'c'}" ) ){}
+ o_( fromjson( "{'_id':1,a:'b'}" ) ),
+ q_( fromjson( "{a:'b'}" ) ),
+ u_( fromjson( "{'_id':1,a:'c'}" ) ) {}
void doIt() const {
client()->update( ns(), q_, u_ );
}
@@ -356,14 +357,14 @@ namespace ReplTests {
insert( fromjson( "{'_id':2,a:'b'}" ) );
}
private:
- BSONObj o_, q_, u_;
- };
+ BSONObj o_, q_, u_;
+ };
class UpdateSameFieldExplicitId : public Base {
public:
UpdateSameFieldExplicitId() :
- o_( fromjson( "{'_id':1,a:'b'}" ) ),
- u_( fromjson( "{'_id':1,a:'c'}" ) ){}
+ o_( fromjson( "{'_id':1,a:'b'}" ) ),
+ u_( fromjson( "{'_id':1,a:'c'}" ) ) {}
void doIt() const {
client()->update( ns(), o_, u_ );
}
@@ -376,15 +377,15 @@ namespace ReplTests {
insert( o_ );
}
protected:
- BSONObj o_, u_;
+ BSONObj o_, u_;
};
-
+
class UpdateDifferentFieldExplicitId : public Base {
public:
UpdateDifferentFieldExplicitId() :
- o_( fromjson( "{'_id':1,a:'b'}" ) ),
- q_( fromjson( "{'_id':1}" ) ),
- u_( fromjson( "{'_id':1,a:'c'}" ) ){}
+ o_( fromjson( "{'_id':1,a:'b'}" ) ),
+ q_( fromjson( "{'_id':1}" ) ),
+ u_( fromjson( "{'_id':1,a:'c'}" ) ) {}
void doIt() const {
client()->update( ns(), q_, u_ );
}
@@ -397,28 +398,28 @@ namespace ReplTests {
insert( o_ );
}
protected:
- BSONObj o_, q_, u_;
- };
-
+ BSONObj o_, q_, u_;
+ };
+
class UpsertUpdateNoMods : public UpdateDifferentFieldExplicitId {
void doIt() const {
client()->update( ns(), q_, u_, true );
}
};
-
+
class UpsertInsertNoMods : public InsertAutoId {
void doIt() const {
client()->update( ns(), fromjson( "{a:'c'}" ), o_, true );
}
};
-
+
class UpdateSet : public Base {
public:
UpdateSet() :
- o_( fromjson( "{'_id':1,a:5}" ) ),
- q_( fromjson( "{a:5}" ) ),
- u_( fromjson( "{$set:{a:7}}" ) ),
- ou_( fromjson( "{'_id':1,a:7}" ) ) {}
+ o_( fromjson( "{'_id':1,a:5}" ) ),
+ q_( fromjson( "{a:5}" ) ),
+ u_( fromjson( "{$set:{a:7}}" ) ),
+ ou_( fromjson( "{'_id':1,a:7}" ) ) {}
void doIt() const {
client()->update( ns(), q_, u_ );
}
@@ -431,16 +432,16 @@ namespace ReplTests {
insert( o_ );
}
protected:
- BSONObj o_, q_, u_, ou_;
+ BSONObj o_, q_, u_, ou_;
};
-
+
class UpdateInc : public Base {
public:
UpdateInc() :
- o_( fromjson( "{'_id':1,a:5}" ) ),
- q_( fromjson( "{a:5}" ) ),
- u_( fromjson( "{$inc:{a:3}}" ) ),
- ou_( fromjson( "{'_id':1,a:8}" ) ) {}
+ o_( fromjson( "{'_id':1,a:5}" ) ),
+ q_( fromjson( "{a:5}" ) ),
+ u_( fromjson( "{$inc:{a:3}}" ) ),
+ ou_( fromjson( "{'_id':1,a:8}" ) ) {}
void doIt() const {
client()->update( ns(), q_, u_ );
}
@@ -453,16 +454,16 @@ namespace ReplTests {
insert( o_ );
}
protected:
- BSONObj o_, q_, u_, ou_;
+ BSONObj o_, q_, u_, ou_;
};
class UpdateInc2 : public Base {
public:
UpdateInc2() :
- o_( fromjson( "{'_id':1,a:5}" ) ),
- q_( fromjson( "{a:5}" ) ),
- u_( fromjson( "{$inc:{a:3},$set:{x:5}}" ) ),
- ou_( fromjson( "{'_id':1,a:8,x:5}" ) ) {}
+ o_( fromjson( "{'_id':1,a:5}" ) ),
+ q_( fromjson( "{a:5}" ) ),
+ u_( fromjson( "{$inc:{a:3},$set:{x:5}}" ) ),
+ ou_( fromjson( "{'_id':1,a:8,x:5}" ) ) {}
void doIt() const {
client()->update( ns(), q_, u_ );
}
@@ -475,16 +476,16 @@ namespace ReplTests {
insert( o_ );
}
protected:
- BSONObj o_, q_, u_, ou_;
+ BSONObj o_, q_, u_, ou_;
};
-
+
class IncEmbedded : public Base {
public:
IncEmbedded() :
- o_( fromjson( "{'_id':1,a:{b:3},b:{b:1}}" ) ),
- q_( fromjson( "{'_id':1}" ) ),
- u_( fromjson( "{$inc:{'a.b':1,'b.b':1}}" ) ),
- ou_( fromjson( "{'_id':1,a:{b:4},b:{b:2}}" ) )
+ o_( fromjson( "{'_id':1,a:{b:3},b:{b:1}}" ) ),
+ q_( fromjson( "{'_id':1}" ) ),
+ u_( fromjson( "{$inc:{'a.b':1,'b.b':1}}" ) ),
+ ou_( fromjson( "{'_id':1,a:{b:4},b:{b:2}}" ) )
{}
void doIt() const {
client()->update( ns(), q_, u_ );
@@ -498,16 +499,16 @@ namespace ReplTests {
insert( o_ );
}
protected:
- BSONObj o_, q_, u_, ou_;
+ BSONObj o_, q_, u_, ou_;
};
class IncCreates : public Base {
public:
IncCreates() :
- o_( fromjson( "{'_id':1}" ) ),
- q_( fromjson( "{'_id':1}" ) ),
- u_( fromjson( "{$inc:{'a':1}}" ) ),
- ou_( fromjson( "{'_id':1,a:1}") )
+ o_( fromjson( "{'_id':1}" ) ),
+ q_( fromjson( "{'_id':1}" ) ),
+ u_( fromjson( "{$inc:{'a':1}}" ) ),
+ ou_( fromjson( "{'_id':1,a:1}") )
{}
void doIt() const {
client()->update( ns(), q_, u_ );
@@ -521,16 +522,16 @@ namespace ReplTests {
insert( o_ );
}
protected:
- BSONObj o_, q_, u_, ou_;
+ BSONObj o_, q_, u_, ou_;
};
class UpsertInsertIdMod : public Base {
public:
UpsertInsertIdMod() :
- q_( fromjson( "{'_id':5,a:4}" ) ),
- u_( fromjson( "{$inc:{a:3}}" ) ),
- ou_( fromjson( "{'_id':5,a:7}" ) ) {}
+ q_( fromjson( "{'_id':5,a:4}" ) ),
+ u_( fromjson( "{$inc:{a:3}}" ) ),
+ ou_( fromjson( "{'_id':5,a:7}" ) ) {}
void doIt() const {
client()->update( ns(), q_, u_, true );
}
@@ -542,15 +543,15 @@ namespace ReplTests {
deleteAll( ns() );
}
protected:
- BSONObj q_, u_, ou_;
+ BSONObj q_, u_, ou_;
};
-
+
class UpsertInsertSet : public Base {
public:
UpsertInsertSet() :
- q_( fromjson( "{a:5}" ) ),
- u_( fromjson( "{$set:{a:7}}" ) ),
- ou_( fromjson( "{a:7}" ) ) {}
+ q_( fromjson( "{a:5}" ) ),
+ u_( fromjson( "{$set:{a:7}}" ) ),
+ ou_( fromjson( "{a:7}" ) ) {}
void doIt() const {
client()->update( ns(), q_, u_, true );
}
@@ -563,15 +564,15 @@ namespace ReplTests {
insert( fromjson( "{'_id':7,a:7}" ) );
}
protected:
- BSONObj o_, q_, u_, ou_;
+ BSONObj o_, q_, u_, ou_;
};
-
+
class UpsertInsertInc : public Base {
public:
UpsertInsertInc() :
- q_( fromjson( "{a:5}" ) ),
- u_( fromjson( "{$inc:{a:3}}" ) ),
- ou_( fromjson( "{a:8}" ) ) {}
+ q_( fromjson( "{a:5}" ) ),
+ u_( fromjson( "{$inc:{a:3}}" ) ),
+ ou_( fromjson( "{a:8}" ) ) {}
void doIt() const {
client()->update( ns(), q_, u_, true );
}
@@ -583,38 +584,38 @@ namespace ReplTests {
deleteAll( ns() );
}
protected:
- BSONObj o_, q_, u_, ou_;
+ BSONObj o_, q_, u_, ou_;
};
-
+
class MultiInc : public Base {
public:
-
+
string s() const {
stringstream ss;
auto_ptr<DBClientCursor> cc = client()->query( ns() , Query().sort( BSON( "_id" << 1 ) ) );
bool first = true;
- while ( cc->more() ){
+ while ( cc->more() ) {
if ( first ) first = false;
else ss << ",";
-
+
BSONObj o = cc->next();
ss << o["x"].numberInt();
}
return ss.str();
}
-
+
void doIt() const {
client()->insert( ns(), BSON( "_id" << 1 << "x" << 1 ) );
client()->insert( ns(), BSON( "_id" << 2 << "x" << 5 ) );
-
+
ASSERT_EQUALS( "1,5" , s() );
-
+
client()->update( ns() , BSON( "_id" << 1 ) , BSON( "$inc" << BSON( "x" << 1 ) ) );
ASSERT_EQUALS( "2,5" , s() );
-
+
client()->update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) );
ASSERT_EQUALS( "3,5" , s() );
-
+
client()->update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) , false , true );
check();
}
@@ -622,18 +623,18 @@ namespace ReplTests {
void check() const {
ASSERT_EQUALS( "4,6" , s() );
}
-
+
void reset() const {
deleteAll( ns() );
}
};
-
+
class UpdateWithoutPreexistingId : public Base {
public:
UpdateWithoutPreexistingId() :
- o_( fromjson( "{a:5}" ) ),
- u_( fromjson( "{a:5}" ) ),
- ot_( fromjson( "{b:4}" ) ) {}
+ o_( fromjson( "{a:5}" ) ),
+ u_( fromjson( "{a:5}" ) ),
+ ot_( fromjson( "{b:4}" ) ) {}
void doIt() const {
client()->update( ns(), o_, u_ );
}
@@ -648,15 +649,15 @@ namespace ReplTests {
insert( o_, true );
}
protected:
- BSONObj o_, u_, ot_;
- };
-
+ BSONObj o_, u_, ot_;
+ };
+
class Remove : public Base {
public:
Remove() :
- o1_( f( "{\"_id\":\"010101010101010101010101\",\"a\":\"b\"}" ) ),
- o2_( f( "{\"_id\":\"010101010101010101010102\",\"a\":\"b\"}" ) ),
- q_( f( "{\"a\":\"b\"}" ) ) {}
+ o1_( f( "{\"_id\":\"010101010101010101010101\",\"a\":\"b\"}" ) ),
+ o2_( f( "{\"_id\":\"010101010101010101010102\",\"a\":\"b\"}" ) ),
+ q_( f( "{\"a\":\"b\"}" ) ) {}
void doIt() const {
client()->remove( ns(), q_ );
}
@@ -669,23 +670,23 @@ namespace ReplTests {
insert( o2_ );
}
protected:
- BSONObj o1_, o2_, q_;
+ BSONObj o1_, o2_, q_;
};
-
+
class RemoveOne : public Remove {
void doIt() const {
client()->remove( ns(), q_, true );
- }
+ }
void check() const {
ASSERT_EQUALS( 1, count() );
}
};
-
+
class FailingUpdate : public Base {
public:
FailingUpdate() :
- o_( fromjson( "{'_id':1,a:'b'}" ) ),
- u_( fromjson( "{'_id':1,c:'d'}" ) ) {}
+ o_( fromjson( "{'_id':1,a:'b'}" ) ),
+ u_( fromjson( "{'_id':1,c:'d'}" ) ) {}
void doIt() const {
client()->update( ns(), o_, u_ );
client()->insert( ns(), o_ );
@@ -700,7 +701,7 @@ namespace ReplTests {
protected:
BSONObj o_, u_;
};
-
+
class SetNumToStr : public Base {
public:
void doIt() const {
@@ -715,7 +716,7 @@ namespace ReplTests {
insert( BSON( "_id" << 0 << "a" << 4.0 ) );
}
};
-
+
class Push : public Base {
public:
void doIt() const {
@@ -729,9 +730,9 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:[4]}" ) );
- }
+ }
};
-
+
class PushUpsert : public Base {
public:
void doIt() const {
@@ -745,7 +746,7 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:[4]}" ) );
- }
+ }
};
class MultiPush : public Base {
@@ -761,7 +762,7 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:[4]}" ) );
- }
+ }
};
class EmptyPush : public Base {
@@ -777,13 +778,13 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0}" ) );
- }
+ }
};
class PushAll : public Base {
public:
void doIt() const {
- client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$pushAll:{a:[5.0,6.0]}}" ) );
+ client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$pushAll:{a:[5.0,6.0]}}" ) );
}
using ReplTests::Base::check;
void check() const {
@@ -793,13 +794,13 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:[4]}" ) );
- }
+ }
};
-
+
class PushAllUpsert : public Base {
public:
void doIt() const {
- client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$pushAll:{a:[5.0,6.0]}}" ), true );
+ client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$pushAll:{a:[5.0,6.0]}}" ), true );
}
using ReplTests::Base::check;
void check() const {
@@ -809,7 +810,7 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:[4]}" ) );
- }
+ }
};
class EmptyPushAll : public Base {
@@ -825,7 +826,7 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0}" ) );
- }
+ }
};
class Pull : public Base {
@@ -841,9 +842,9 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:[4,5]}" ) );
- }
+ }
};
-
+
class PullNothing : public Base {
public:
void doIt() const {
@@ -857,13 +858,13 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:[4,5]}" ) );
- }
+ }
};
-
+
class PullAll : public Base {
public:
void doIt() const {
- client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$pullAll:{a:[4,5]}}" ) );
+ client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$pullAll:{a:[4,5]}}" ) );
}
using ReplTests::Base::check;
void check() const {
@@ -873,7 +874,7 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:[4,5,6]}" ) );
- }
+ }
};
class Pop : public Base {
@@ -889,7 +890,7 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:[4,5,6]}" ) );
- }
+ }
};
class PopReverse : public Base {
@@ -905,7 +906,7 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:[4,5,6]}" ) );
- }
+ }
};
class BitOp : public Base {
@@ -921,14 +922,14 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:3}" ) );
- }
+ }
};
class Rename : public Base {
public:
void doIt() const {
- client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$rename:{a:'b'}}" ) );
- client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$set:{a:50}}" ) );
+ client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$rename:{a:'b'}}" ) );
+ client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$set:{a:50}}" ) );
}
using ReplTests::Base::check;
void check() const {
@@ -938,14 +939,14 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:3}" ) );
- }
+ }
};
class RenameReplace : public Base {
public:
void doIt() const {
- client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$rename:{a:'b'}}" ) );
- client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$set:{a:50}}" ) );
+ client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$rename:{a:'b'}}" ) );
+ client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$set:{a:50}}" ) );
}
using ReplTests::Base::check;
void check() const {
@@ -955,13 +956,13 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:3,b:100}" ) );
- }
+ }
};
class RenameOverwrite : public Base {
public:
void doIt() const {
- client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$rename:{a:'b'}}" ) );
+ client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$rename:{a:'b'}}" ) );
}
using ReplTests::Base::check;
void check() const {
@@ -971,13 +972,13 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,z:1,a:3}" ) );
- }
+ }
};
-
+
class NoRename : public Base {
public:
void doIt() const {
- client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$rename:{c:'b'},$set:{z:1}}" ) );
+ client()->update( ns(), BSON( "_id" << 0 ), fromjson( "{$rename:{c:'b'},$set:{z:1}}" ) );
}
using ReplTests::Base::check;
void check() const {
@@ -987,12 +988,12 @@ namespace ReplTests {
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:3}" ) );
- }
+ }
};
-
-
+
+
} // namespace Idempotence
-
+
class DeleteOpIsIdBased : public Base {
public:
void run() {
@@ -1002,21 +1003,21 @@ namespace ReplTests {
client()->remove( ns(), BSON( "a" << 10 ) );
ASSERT_EQUALS( 1U, client()->count( ns(), BSONObj() ) );
insert( BSON( "_id" << 0 << "a" << 11 ) );
- insert( BSON( "_id" << 2 << "a" << 10 ) );
+ insert( BSON( "_id" << 2 << "a" << 10 ) );
insert( BSON( "_id" << 3 << "a" << 10 ) );
-
+
applyAllOperations();
ASSERT_EQUALS( 2U, client()->count( ns(), BSONObj() ) );
ASSERT( !one( BSON( "_id" << 1 ) ).isEmpty() );
ASSERT( !one( BSON( "_id" << 2 ) ).isEmpty() );
}
};
-
+
class DbIdsTest {
public:
void run() {
Client::Context ctx( "unittests.repltest.DbIdsTest" );
-
+
s_.reset( new DbIds( "local.temp.DbIdsTest" ) );
s_->reset();
check( false, false, false );
@@ -1025,7 +1026,7 @@ namespace ReplTests {
check( true, false, false );
s_->set( "a", BSON( "_id" << 4 ), false );
check( false, false, false );
-
+
s_->set( "b", BSON( "_id" << 4 ), true );
check( false, true, false );
s_->set( "b", BSON( "_id" << 4 ), false );
@@ -1043,7 +1044,7 @@ namespace ReplTests {
s_->reset();
check( false, false, false );
-
+
s_->set( "a", BSON( "_id" << 4 ), true );
s_->set( "a", BSON( "_id" << 4 ), true );
check( true, false, false );
@@ -1054,17 +1055,17 @@ namespace ReplTests {
void check( bool one, bool two, bool three ) {
ASSERT_EQUALS( one, s_->get( "a", BSON( "_id" << 4 ) ) );
ASSERT_EQUALS( two, s_->get( "b", BSON( "_id" << 4 ) ) );
- ASSERT_EQUALS( three, s_->get( "a", BSON( "_id" << 5 ) ) );
+ ASSERT_EQUALS( three, s_->get( "a", BSON( "_id" << 5 ) ) );
}
dblock lk_;
auto_ptr< DbIds > s_;
};
-
+
class MemIdsTest {
public:
void run() {
int n = sizeof( BSONObj ) + BSON( "_id" << 4 ).objsize();
-
+
s_.reset();
ASSERT_EQUALS( 0, s_.roughSize() );
ASSERT( !s_.get( "a", BSON( "_id" << 4 ) ) );
@@ -1091,7 +1092,7 @@ namespace ReplTests {
public:
void run() {
Client::Context ctx( "unittests.repltests.IdTrackerTest" );
-
+
ASSERT( s_.inMem() );
s_.reset( 4 * sizeof( BSONObj ) - 1 );
s_.haveId( "a", BSON( "_id" << 0 ), true );
@@ -1103,34 +1104,34 @@ namespace ReplTests {
s_.mayUpgradeStorage();
ASSERT( !s_.inMem() );
check();
-
+
s_.haveId( "a", BSON( "_id" << 1 ), false );
ASSERT( !s_.haveId( "a", BSON( "_id" << 1 ) ) );
s_.haveId( "a", BSON( "_id" << 1 ), true );
check();
- ASSERT( !s_.inMem() );
-
+ ASSERT( !s_.inMem() );
+
s_.reset( 4 * sizeof( BSONObj ) - 1 );
s_.mayUpgradeStorage();
- ASSERT( s_.inMem() );
+ ASSERT( s_.inMem() );
}
private:
void check() {
ASSERT( s_.haveId( "a", BSON( "_id" << 0 ) ) );
ASSERT( s_.haveId( "a", BSON( "_id" << 1 ) ) );
ASSERT( s_.haveId( "b", BSON( "_id" << 0 ) ) );
- ASSERT( s_.haveModId( "b", BSON( "_id" << 0 ) ) );
+ ASSERT( s_.haveModId( "b", BSON( "_id" << 0 ) ) );
}
dblock lk_;
IdTracker s_;
};
-
+
class All : public Suite {
public:
- All() : Suite( "repl" ){
+ All() : Suite( "repl" ) {
}
-
- void setupTests(){
+
+ void setupTests() {
add< LogBasic >();
add< Idempotence::InsertTimestamp >();
add< Idempotence::InsertAutoId >();
@@ -1182,6 +1183,6 @@ namespace ReplTests {
add< IdTrackerTest >();
}
} myall;
-
+
} // namespace ReplTests
diff --git a/dbtests/sharding.cpp b/dbtests/sharding.cpp
index 2473366ccda..19edd5537ab 100644
--- a/dbtests/sharding.cpp
+++ b/dbtests/sharding.cpp
@@ -27,17 +27,17 @@ namespace ShardingTests {
namespace serverandquerytests {
class test1 {
public:
- void run(){
+ void run() {
ServerAndQuery a( "foo:1" , BSON( "a" << GT << 0 << LTE << 100 ) );
ServerAndQuery b( "foo:1" , BSON( "a" << GT << 200 << LTE << 1000 ) );
-
+
ASSERT( a < b );
ASSERT( ! ( b < a ) );
set<ServerAndQuery> s;
s.insert( a );
s.insert( b );
-
+
ASSERT_EQUALS( (unsigned int)2 , s.size() );
}
};
@@ -45,12 +45,12 @@ namespace ShardingTests {
class All : public Suite {
public:
- All() : Suite( "sharding" ){
+ All() : Suite( "sharding" ) {
}
- void setupTests(){
+ void setupTests() {
add< serverandquerytests::test1 >();
}
} myall;
-
+
}
diff --git a/dbtests/socktests.cpp b/dbtests/socktests.cpp
index 427e19e7c4b..5cd42f59d45 100644
--- a/dbtests/socktests.cpp
+++ b/dbtests/socktests.cpp
@@ -29,20 +29,20 @@ namespace SockTests {
ASSERT_EQUALS( "127.0.0.1", hostbyname( "localhost" ) );
ASSERT_EQUALS( "127.0.0.1", hostbyname( "127.0.0.1" ) );
// ASSERT_EQUALS( "::1", hostbyname( "::1" ) ); // IPv6 disabled at runtime by default.
-
+
HostAndPort h("asdfasdfasdf_no_such_host");
// this fails uncomment when fixed.
ASSERT( !h.isSelf() );
}
};
-
+
class All : public Suite {
public:
- All() : Suite( "sock" ){}
- void setupTests(){
+ All() : Suite( "sock" ) {}
+ void setupTests() {
add< HostByName >();
}
} myall;
-
+
} // namespace SockTests
diff --git a/dbtests/spin_lock_test.cpp b/dbtests/spin_lock_test.cpp
index d053d61cd5b..01eb7b37121 100644
--- a/dbtests/spin_lock_test.cpp
+++ b/dbtests/spin_lock_test.cpp
@@ -26,26 +26,26 @@ namespace {
using mongo::SpinLock;
- class LockTester{
+ class LockTester {
public:
LockTester( SpinLock* spin, int* counter )
- : _spin(spin), _counter(counter), _requests(0){}
+ : _spin(spin), _counter(counter), _requests(0) {}
- ~LockTester(){
+ ~LockTester() {
delete _t;
}
- void start( int increments ){
- _t = new boost::thread( boost::bind(&LockTester::test, this, increments) );
+ void start( int increments ) {
+ _t = new boost::thread( boost::bind(&LockTester::test, this, increments) );
}
- void join(){
+ void join() {
if ( _t ) _t->join();
}
- int requests() const{
- return _requests;
- }
+ int requests() const {
+ return _requests;
+ }
private:
SpinLock* _spin; // not owned here
@@ -53,7 +53,7 @@ namespace {
int _requests;
boost::thread* _t;
- void test( int increments ){
+ void test( int increments ) {
while ( increments-- > 0 ) {
_spin->lock();
++(*_counter);
@@ -61,14 +61,14 @@ namespace {
_spin->unlock();
}
}
-
+
LockTester( LockTester& );
LockTester& operator=( LockTester& );
};
- class ConcurrentIncs{
+ class ConcurrentIncs {
public:
- void run(){
+ void run() {
#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
@@ -77,37 +77,37 @@ namespace {
const int threads = 64;
const int incs = 10000;
- LockTester* testers[threads];
-
- for ( int i = 0; i < threads; i++ ){
- testers[i] = new LockTester( &spin, &counter );
- }
- for ( int i = 0; i < threads; i++ ){
- testers[i]->start( incs );
- }
- for ( int i = 0; i < threads; i++ ){
- testers[i]->join();
- ASSERT_EQUALS( testers[i]->requests(), incs );
- delete testers[i];
- }
-
- ASSERT_EQUALS( counter, threads*incs );
+ LockTester* testers[threads];
+
+ for ( int i = 0; i < threads; i++ ) {
+ testers[i] = new LockTester( &spin, &counter );
+ }
+ for ( int i = 0; i < threads; i++ ) {
+ testers[i]->start( incs );
+ }
+ for ( int i = 0; i < threads; i++ ) {
+ testers[i]->join();
+ ASSERT_EQUALS( testers[i]->requests(), incs );
+ delete testers[i];
+ }
+
+ ASSERT_EQUALS( counter, threads*incs );
#else
- // WARNING "TODO Missing spin lock in this platform."
- ASSERT( true );
+ // WARNING "TODO Missing spin lock in this platform."
+ ASSERT( true );
+
-
#endif
}
};
- class SpinLockSuite : public Suite{
+ class SpinLockSuite : public Suite {
public:
- SpinLockSuite() : Suite( "spinlock" ){}
+ SpinLockSuite() : Suite( "spinlock" ) {}
- void setupTests(){
+ void setupTests() {
add< ConcurrentIncs >();
}
} spinLockSuite;
diff --git a/dbtests/threadedtests.cpp b/dbtests/threadedtests.cpp
index af413cc2fe4..8891594537c 100644
--- a/dbtests/threadedtests.cpp
+++ b/dbtests/threadedtests.cpp
@@ -29,34 +29,34 @@
namespace ThreadedTests {
template <int nthreads_param=10>
- class ThreadedTest{
- public:
- virtual void setup() {} //optional
- virtual void subthread() = 0;
- virtual void validate() = 0;
+ class ThreadedTest {
+ public:
+ virtual void setup() {} //optional
+ virtual void subthread() = 0;
+ virtual void validate() = 0;
- static const int nthreads = nthreads_param;
+ static const int nthreads = nthreads_param;
- void run(){
- setup();
+ void run() {
+ setup();
- launch_subthreads(nthreads);
+ launch_subthreads(nthreads);
- validate();
- }
+ validate();
+ }
- virtual ~ThreadedTest() {}; // not necessary, but makes compilers happy
+ virtual ~ThreadedTest() {}; // not necessary, but makes compilers happy
- private:
- void launch_subthreads(int remaining){
- if (!remaining) return;
+ private:
+ void launch_subthreads(int remaining) {
+ if (!remaining) return;
- boost::thread athread(boost::bind(&ThreadedTest::subthread, this));
+ boost::thread athread(boost::bind(&ThreadedTest::subthread, this));
- launch_subthreads(remaining - 1);
+ launch_subthreads(remaining - 1);
- athread.join();
- }
+ athread.join();
+ }
};
// Tested with up to 30k threads
@@ -64,13 +64,13 @@ namespace ThreadedTests {
static const int iterations = 1000000;
AtomicUInt target;
- void subthread(){
- for(int i=0; i < iterations; i++){
+ void subthread() {
+ for(int i=0; i < iterations; i++) {
//target.x++; // verified to fail with this version
target++;
}
}
- void validate(){
+ void validate() {
ASSERT_EQUALS(target.x , unsigned(nthreads * iterations));
AtomicUInt u;
@@ -87,10 +87,10 @@ namespace ThreadedTests {
static const int iterations = 10000;
MVar<int> target;
- public:
+ public:
MVarTest() : target(0) {}
- void subthread(){
- for(int i=0; i < iterations; i++){
+ void subthread() {
+ for(int i=0; i < iterations; i++) {
int val = target.take();
#if BOOST_VERSION >= 103500
//increase chances of catching failure
@@ -99,30 +99,30 @@ namespace ThreadedTests {
target.put(val+1);
}
}
- void validate(){
+ void validate() {
ASSERT_EQUALS(target.take() , nthreads * iterations);
}
};
- class ThreadPoolTest{
+ class ThreadPoolTest {
static const int iterations = 10000;
static const int nThreads = 8;
AtomicUInt counter;
- void increment(int n){
- for (int i=0; i<n; i++){
+ void increment(int n) {
+ for (int i=0; i<n; i++) {
counter++;
}
}
- public:
- void run(){
+ public:
+ void run() {
ThreadPool tp(nThreads);
- for (int i=0; i < iterations; i++){
+ for (int i=0; i < iterations; i++) {
tp.schedule(&ThreadPoolTest::increment, this, 2);
}
-
+
tp.join();
ASSERT(counter == (unsigned)(iterations * 2));
@@ -131,7 +131,7 @@ namespace ThreadedTests {
class LockTest {
public:
- void run(){
+ void run() {
// quick atomicint wrap test
// MSGID likely assumes this semantic
AtomicUInt counter = 0xffffffff;
@@ -145,10 +145,10 @@ namespace ThreadedTests {
class All : public Suite {
public:
- All() : Suite( "threading" ){
+ All() : Suite( "threading" ) {
}
- void setupTests(){
+ void setupTests() {
add< IsAtomicUIntAtomic >();
add< MVarTest >();
add< ThreadPoolTest >();
diff --git a/dbtests/updatetests.cpp b/dbtests/updatetests.cpp
index 665bdc481ee..0f95a326faa 100644
--- a/dbtests/updatetests.cpp
+++ b/dbtests/updatetests.cpp
@@ -110,14 +110,14 @@ namespace UpdateTests {
class PushAllNonArray : public Fail {
void doIt() {
- insert( ns(), fromjson( "{a:[1]}" ) );
+ insert( ns(), fromjson( "{a:[1]}" ) );
update( ns(), BSONObj(), fromjson( "{$pushAll:{a:'d'}}" ) );
}
};
class PullAllNonArray : public Fail {
void doIt() {
- insert( ns(), fromjson( "{a:[1]}" ) );
+ insert( ns(), fromjson( "{a:[1]}" ) );
update( ns(), BSONObj(), fromjson( "{$pullAll:{a:'d'}}" ) );
}
};
@@ -241,12 +241,12 @@ namespace UpdateTests {
class MultiInc : public SetBase {
public:
-
- string s(){
+
+ string s() {
stringstream ss;
auto_ptr<DBClientCursor> cc = client().query( ns() , Query().sort( BSON( "_id" << 1 ) ) );
bool first = true;
- while ( cc->more() ){
+ while ( cc->more() ) {
if ( first ) first = false;
else ss << ",";
@@ -255,11 +255,11 @@ namespace UpdateTests {
}
return ss.str();
}
-
- void run(){
+
+ void run() {
client().insert( ns(), BSON( "_id" << 1 << "x" << 1 ) );
client().insert( ns(), BSON( "_id" << 2 << "x" << 5 ) );
-
+
ASSERT_EQUALS( "1,5" , s() );
client().update( ns() , BSON( "_id" << 1 ) , BSON( "$inc" << BSON( "x" << 1 ) ) );
@@ -270,7 +270,7 @@ namespace UpdateTests {
client().update( ns() , BSONObj() , BSON( "$inc" << BSON( "x" << 1 ) ) , false , true );
ASSERT_EQUALS( "4,6" , s() );
-
+
}
};
@@ -498,10 +498,10 @@ namespace UpdateTests {
client().insert( ns(), BSON( "_id" << 55 << "i" << 5 ) );
client().update( ns(), BSON( "i" << 5 ), BSON( "i" << 6 ) );
ASSERT( !client().findOne( ns(), Query( BSON( "_id" << 55 ) ).hint
- ( "{\"_id\":ObjectId(\"000000000000000000000000\")}" ) ).isEmpty() );
+ ( "{\"_id\":ObjectId(\"000000000000000000000000\")}" ) ).isEmpty() );
}
};
-
+
class CheckNoMods : public SetBase {
public:
void run() {
@@ -509,7 +509,7 @@ namespace UpdateTests {
ASSERT( error() );
}
};
-
+
class UpdateMissingToNull : public SetBase {
public:
void run() {
@@ -520,10 +520,10 @@ namespace UpdateTests {
};
namespace ModSetTests {
-
+
class internal1 {
public:
- void run(){
+ void run() {
BSONObj b = BSON( "$inc" << BSON( "x" << 1 << "a.b" << 1 ) );
ModSet m(b);
@@ -532,7 +532,7 @@ namespace UpdateTests {
ASSERT( ! m.haveModForField( "y" ) );
ASSERT( ! m.haveModForField( "a.c" ) );
ASSERT( ! m.haveModForField( "a" ) );
-
+
ASSERT( m.haveConflictingMod( "x" ) );
ASSERT( m.haveConflictingMod( "a" ) );
ASSERT( m.haveConflictingMod( "a.b" ) );
@@ -541,14 +541,14 @@ namespace UpdateTests {
ASSERT( ! m.haveConflictingMod( "a.a" ) );
}
};
-
+
class Base {
public:
- virtual ~Base(){}
+ virtual ~Base() {}
-
- void test( BSONObj morig , BSONObj in , BSONObj wanted ){
+
+ void test( BSONObj morig , BSONObj in , BSONObj wanted ) {
BSONObj m = morig.copy();
ModSet set(m);
@@ -556,20 +556,20 @@ namespace UpdateTests {
ASSERT_EQUALS( wanted , out );
}
};
-
+
class inc1 : public Base {
public:
- void run(){
+ void run() {
BSONObj m = BSON( "$inc" << BSON( "x" << 1 ) );
test( m , BSON( "x" << 5 ) , BSON( "x" << 6 ) );
test( m , BSON( "a" << 5 ) , BSON( "a" << 5 << "x" << 1 ) );
test( m , BSON( "z" << 5 ) , BSON( "x" << 1 << "z" << 5 ) );
}
};
-
+
class inc2 : public Base {
public:
- void run(){
+ void run() {
BSONObj m = BSON( "$inc" << BSON( "a.b" << 1 ) );
test( m , BSONObj() , BSON( "a" << BSON( "b" << 1 ) ) );
test( m , BSON( "a" << BSON( "b" << 2 ) ) , BSON( "a" << BSON( "b" << 3 ) ) );
@@ -577,23 +577,23 @@ namespace UpdateTests {
m = BSON( "$inc" << BSON( "a.b" << 1 << "a.c" << 1 ) );
test( m , BSONObj() , BSON( "a" << BSON( "b" << 1 << "c" << 1 ) ) );
-
+
}
};
class set1 : public Base {
public:
- void run(){
+ void run() {
test( BSON( "$set" << BSON( "x" << 17 ) ) , BSONObj() , BSON( "x" << 17 ) );
test( BSON( "$set" << BSON( "x" << 17 ) ) , BSON( "x" << 5 ) , BSON( "x" << 17 ) );
test( BSON( "$set" << BSON( "x.a" << 17 ) ) , BSON( "z" << 5 ) , BSON( "x" << BSON( "a" << 17 )<< "z" << 5 ) );
}
- };
-
+ };
+
class push1 : public Base {
public:
- void run(){
+ void run() {
test( BSON( "$push" << BSON( "a" << 5 ) ) , fromjson( "{a:[1]}" ) , fromjson( "{a:[1,5]}" ) );
}
};
@@ -603,28 +603,28 @@ namespace UpdateTests {
namespace basic {
class Base : public ClientBase {
protected:
-
+
virtual const char * ns() = 0;
virtual void dotest() = 0;
-
- void insert( const BSONObj& o ){
+
+ void insert( const BSONObj& o ) {
client().insert( ns() , o );
}
-
- void update( const BSONObj& m ){
+
+ void update( const BSONObj& m ) {
client().update( ns() , BSONObj() , m );
}
- BSONObj findOne(){
+ BSONObj findOne() {
return client().findOne( ns() , BSONObj() );
}
- void test( const char* initial , const char* mod , const char* after ){
+ void test( const char* initial , const char* mod , const char* after ) {
test( fromjson( initial ) , fromjson( mod ) , fromjson( after ) );
}
- void test( const BSONObj& initial , const BSONObj& mod , const BSONObj& after ){
+ void test( const BSONObj& initial , const BSONObj& mod , const BSONObj& after ) {
client().dropCollection( ns() );
insert( initial );
update( mod );
@@ -633,14 +633,14 @@ namespace UpdateTests {
}
public:
-
- Base(){}
- virtual ~Base(){
+
+ Base() {}
+ virtual ~Base() {
}
- void run(){
+ void run() {
client().dropCollection( ns() );
-
+
dotest();
client().dropCollection( ns() );
@@ -652,87 +652,87 @@ namespace UpdateTests {
virtual BSONObj mod() = 0;
virtual BSONObj after() = 0;
- void dotest(){
+ void dotest() {
test( initial() , mod() , after() );
}
-
+
};
-
+
class inc1 : public SingleTest {
- virtual BSONObj initial(){
+ virtual BSONObj initial() {
return BSON( "_id" << 1 << "x" << 1 );
}
- virtual BSONObj mod(){
+ virtual BSONObj mod() {
return BSON( "$inc" << BSON( "x" << 2 ) );
}
- virtual BSONObj after(){
+ virtual BSONObj after() {
return BSON( "_id" << 1 << "x" << 3 );
}
- virtual const char * ns(){
+ virtual const char * ns() {
return "unittests.inc1";
}
};
class inc2 : public SingleTest {
- virtual BSONObj initial(){
+ virtual BSONObj initial() {
return BSON( "_id" << 1 << "x" << 1 );
}
- virtual BSONObj mod(){
+ virtual BSONObj mod() {
return BSON( "$inc" << BSON( "x" << 2.5 ) );
}
- virtual BSONObj after(){
+ virtual BSONObj after() {
return BSON( "_id" << 1 << "x" << 3.5 );
}
- virtual const char * ns(){
+ virtual const char * ns() {
return "unittests.inc2";
}
};
-
+
class inc3 : public SingleTest {
- virtual BSONObj initial(){
+ virtual BSONObj initial() {
return BSON( "_id" << 1 << "x" << 537142123123LL );
}
- virtual BSONObj mod(){
+ virtual BSONObj mod() {
return BSON( "$inc" << BSON( "x" << 2 ) );
}
- virtual BSONObj after(){
+ virtual BSONObj after() {
return BSON( "_id" << 1 << "x" << 537142123125LL );
}
- virtual const char * ns(){
+ virtual const char * ns() {
return "unittests.inc3";
}
};
class inc4 : public SingleTest {
- virtual BSONObj initial(){
+ virtual BSONObj initial() {
return BSON( "_id" << 1 << "x" << 537142123123LL );
}
- virtual BSONObj mod(){
+ virtual BSONObj mod() {
return BSON( "$inc" << BSON( "x" << 2LL ) );
}
- virtual BSONObj after(){
+ virtual BSONObj after() {
return BSON( "_id" << 1 << "x" << 537142123125LL );
}
- virtual const char * ns(){
+ virtual const char * ns() {
return "unittests.inc4";
}
};
class inc5 : public SingleTest {
- virtual BSONObj initial(){
+ virtual BSONObj initial() {
return BSON( "_id" << 1 << "x" << 537142123123LL );
}
- virtual BSONObj mod(){
+ virtual BSONObj mod() {
return BSON( "$inc" << BSON( "x" << 2.0 ) );
}
- virtual BSONObj after(){
+ virtual BSONObj after() {
return BSON( "_id" << 1 << "x" << 537142123125LL );
}
- virtual const char * ns(){
+ virtual const char * ns() {
return "unittests.inc5";
}
@@ -740,23 +740,23 @@ namespace UpdateTests {
class inc6 : public Base {
- virtual const char * ns(){
+ virtual const char * ns() {
return "unittests.inc6";
}
- virtual BSONObj initial(){ return BSONObj(); }
- virtual BSONObj mod(){ return BSONObj(); }
- virtual BSONObj after(){ return BSONObj(); }
+ virtual BSONObj initial() { return BSONObj(); }
+ virtual BSONObj mod() { return BSONObj(); }
+ virtual BSONObj after() { return BSONObj(); }
- void dotest(){
+ void dotest() {
client().insert( ns() , BSON( "x" << 5 ) );
ASSERT( findOne()["x"].type() == NumberInt );
long long start = 5;
long long max = numeric_limits<int>::max();
max *= 32;
- while ( start < max ){
+ while ( start < max ) {
update( BSON( "$inc" << BSON( "x" << 500000 ) ) );
start += 500000;
ASSERT_EQUALS( start , findOne()["x"].numberLong() ); // SERVER-2005
@@ -764,12 +764,12 @@ namespace UpdateTests {
}
};
-
+
class bit1 : public Base {
- const char * ns(){
+ const char * ns() {
return "unittests.bit1";
}
- void dotest(){
+ void dotest() {
test( BSON( "_id" << 1 << "x" << 3 ) , BSON( "$bit" << BSON( "x" << BSON( "and" << 2 ) ) ) , BSON( "_id" << 1 << "x" << ( 3 & 2 ) ) );
test( BSON( "_id" << 1 << "x" << 1 ) , BSON( "$bit" << BSON( "x" << BSON( "or" << 4 ) ) ) , BSON( "_id" << 1 << "x" << ( 1 | 4 ) ) );
test( BSON( "_id" << 1 << "x" << 3 ) , BSON( "$bit" << BSON( "x" << BSON( "and" << 2 << "or" << 8 ) ) ) , BSON( "_id" << 1 << "x" << ( ( 3 & 2 ) | 8 ) ) );
@@ -777,21 +777,21 @@ namespace UpdateTests {
}
};
-
+
class unset : public Base {
- const char * ns(){
+ const char * ns() {
return "unittests.unset";
}
- void dotest(){
+ void dotest() {
test( "{_id:1,x:1}" , "{$unset:{x:1}}" , "{_id:1}" );
}
};
class setswitchint : public Base {
- const char * ns(){
+ const char * ns() {
return "unittests.int1";
}
- void dotest(){
+ void dotest() {
test( BSON( "_id" << 1 << "x" << 1 ) , BSON( "$set" << BSON( "x" << 5.6 ) ) , BSON( "_id" << 1 << "x" << 5.6 ) );
test( BSON( "_id" << 1 << "x" << 5.6 ) , BSON( "$set" << BSON( "x" << 1 ) ) , BSON( "_id" << 1 << "x" << 1 ) );
}
@@ -799,12 +799,12 @@ namespace UpdateTests {
};
-
+
class All : public Suite {
public:
All() : Suite( "update" ) {
}
- void setupTests(){
+ void setupTests() {
add< ModId >();
add< ModNonmodMix >();
add< InvalidMod >();
@@ -853,13 +853,13 @@ namespace UpdateTests {
add< PreserveIdWithIndex >();
add< CheckNoMods >();
add< UpdateMissingToNull >();
-
+
add< ModSetTests::internal1 >();
add< ModSetTests::inc1 >();
add< ModSetTests::inc2 >();
add< ModSetTests::set1 >();
add< ModSetTests::push1 >();
-
+
add< basic::inc1 >();
add< basic::inc2 >();
add< basic::inc3 >();