mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Make object comparison recursive, with tests
This commit is contained in:
parent
e85055ec41
commit
ac39edd52c
@ -242,6 +242,7 @@ int compareElementValues(const BSONElement& l, const BSONElement& r) {
|
||||
return strcmp(l.valuestr(), r.valuestr());
|
||||
case Object:
|
||||
case Array:
|
||||
return l.embeddedObject().woCompare( r.embeddedObject() );
|
||||
case DBRef:
|
||||
{
|
||||
int lsz = l.valuesize();
|
||||
|
32
db/jsobj.h
32
db/jsobj.h
@ -480,17 +480,18 @@ public:
|
||||
template < class T >
|
||||
void append( const char *fieldName, const vector< T >& vals ) {
|
||||
BSONObjBuilder arrBuilder;
|
||||
for( int i = 0; i < vals.size(); ++i ) {
|
||||
stringstream o;
|
||||
o << i;
|
||||
arrBuilder.append( o.str().c_str(), vals[ i ] );
|
||||
}
|
||||
BSONObj arr = arrBuilder.done();
|
||||
b.append( (char) Array );
|
||||
b.append( fieldName );
|
||||
b.append( (void *) arr.objdata(), arr.objsize() );
|
||||
for( int i = 0; i < vals.size(); ++i )
|
||||
arrBuilder.append( numStr( i ).c_str(), vals[ i ] );
|
||||
marshalArray( fieldName, arrBuilder.done() );
|
||||
}
|
||||
|
||||
void appendIntArray( const char *fieldName, const vector< int >& vals ) {
|
||||
BSONObjBuilder arrBuilder;
|
||||
for( int i = 0; i < vals.size(); ++i )
|
||||
arrBuilder.appendInt( numStr( i ).c_str(), vals[ i ] );
|
||||
marshalArray( fieldName, arrBuilder.done() );
|
||||
}
|
||||
|
||||
/* BSONObj will free the buffer when it is finished. */
|
||||
BSONObj doneAndDecouple() {
|
||||
int l;
|
||||
@ -516,6 +517,19 @@ public:
|
||||
void decouple() { b.decouple(); } // post done() call version. be sure jsobj frees...
|
||||
|
||||
private:
|
||||
// Append the provided arr object as an array.
|
||||
void marshalArray( const char *fieldName, const BSONObj &arr ) {
|
||||
b.append( (char) Array );
|
||||
b.append( fieldName );
|
||||
b.append( (void *) arr.objdata(), arr.objsize() );
|
||||
}
|
||||
|
||||
string numStr( int i ) const {
|
||||
stringstream o;
|
||||
o << i;
|
||||
return o.str();
|
||||
}
|
||||
|
||||
char* _done() {
|
||||
b.append((char) EOO);
|
||||
char *data = b.buf();
|
||||
|
@ -16,7 +16,7 @@ OBJS=../stdafx.o ../util/sock.o ../grid/message.o ../util/mmap.o pdfile.o query.
|
||||
|
||||
DBGRID_OBJS=../stdafx.o json.o ../util/sock.o ../grid/message.o ../util/util.o jsobj.o ../client/dbclient.o ../dbgrid/dbgrid.o ../dbgrid/request.o ../client/connpool.o ../dbgrid/gridconfig.o commands.o ../dbgrid/dbgrid_commands.o ../dbgrid/griddatabase.o ../client/model.o ../util/background.o ../dbgrid/shard.o
|
||||
|
||||
DBTEST_OBJS= $(OBJS) ../dbtests/dbtests.o ../dbtests/btreetests.o ../dbtests/indexdetailstests.o ../dbtests/pairingtests.o
|
||||
DBTEST_OBJS= $(OBJS) ../dbtests/dbtests.o ../dbtests/btreetests.o ../dbtests/jsobjtests.o ../dbtests/namespacetests.o ../dbtests/pairingtests.o
|
||||
|
||||
GPP = g++
|
||||
|
||||
|
@ -67,6 +67,7 @@ int main( int argc, char** argv ) {
|
||||
UnitTest::Registry tests;
|
||||
|
||||
tests.add( btreeTests(), "btree" );
|
||||
tests.add( jsobjTests(), "jsobj" );
|
||||
tests.add( namespaceTests(), "namespace" );
|
||||
tests.add( pairingTests(), "pairing" );
|
||||
|
||||
|
@ -20,5 +20,6 @@
|
||||
#include <unittest/UnitTest.hpp>
|
||||
|
||||
UnitTest::TestPtr btreeTests();
|
||||
UnitTest::TestPtr jsobjTests();
|
||||
UnitTest::TestPtr namespaceTests();
|
||||
UnitTest::TestPtr pairingTests();
|
||||
|
@ -117,9 +117,6 @@ namespace NamespaceTests {
|
||||
set< BSONObj > keys;
|
||||
id().getKeysFromObject( a.done(), keys );
|
||||
ASSERT_EQUALS( 1, keys.size() );
|
||||
// FIXME Why doesn't woCompare expand sub elements?
|
||||
// ASSERT( !keys.begin()->woCompare( e.done() ) );
|
||||
cout << "first key: " << keys.begin()->toString() << endl;
|
||||
ASSERT_EQUALS( string( "b" ), keys.begin()->firstElement().fieldName() );
|
||||
ASSERT_EQUALS( 4, keys.begin()->firstElement().number() );
|
||||
}
|
||||
@ -204,7 +201,6 @@ namespace NamespaceTests {
|
||||
|
||||
set< BSONObj > keys;
|
||||
id().getKeysFromObject( a.done(), keys );
|
||||
cout << "key: " << keys.begin()->toString() << endl;
|
||||
ASSERT_EQUALS( 3, keys.size() );
|
||||
int j = 1;
|
||||
for( set< BSONObj >::iterator i = keys.begin(); i != keys.end(); ++i, ++j ) {
|
||||
|
@ -16,7 +16,6 @@
|
||||
934223860EF16D7000608550 /* btreetests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = btreetests.cpp; sourceTree = "<group>"; };
|
||||
934223880EF16D7000608550 /* dbtests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dbtests.cpp; sourceTree = "<group>"; };
|
||||
934223890EF16D7000608550 /* dbtests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dbtests.h; sourceTree = "<group>"; };
|
||||
9342238B0EF16D7000608550 /* indexdetailstests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = indexdetailstests.cpp; sourceTree = "<group>"; };
|
||||
9342238C0EF16D7000608550 /* mockdbclient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mockdbclient.h; sourceTree = "<group>"; };
|
||||
9342238D0EF16D7000608550 /* pairingtests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = pairingtests.cpp; sourceTree = "<group>"; };
|
||||
934223900EF16DB400608550 /* btree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = btree.cpp; sourceTree = "<group>"; };
|
||||
@ -69,6 +68,8 @@
|
||||
934223C70EF16DB400608550 /* scanandorder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scanandorder.h; sourceTree = "<group>"; };
|
||||
934223C80EF16DB400608550 /* storage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = storage.h; sourceTree = "<group>"; };
|
||||
934223C90EF16DB400608550 /* tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tests.cpp; sourceTree = "<group>"; };
|
||||
93D0C1520EF1D377005253B7 /* jsobjtests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsobjtests.cpp; sourceTree = "<group>"; };
|
||||
93D0C1FB0EF1E267005253B7 /* namespacetests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = namespacetests.cpp; sourceTree = "<group>"; };
|
||||
C6859E8B029090EE04C91782 /* mongo.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = mongo.1; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@ -116,10 +117,11 @@
|
||||
934223850EF16D7000608550 /* dbtests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
93D0C1FB0EF1E267005253B7 /* namespacetests.cpp */,
|
||||
93D0C1520EF1D377005253B7 /* jsobjtests.cpp */,
|
||||
934223860EF16D7000608550 /* btreetests.cpp */,
|
||||
934223880EF16D7000608550 /* dbtests.cpp */,
|
||||
934223890EF16D7000608550 /* dbtests.h */,
|
||||
9342238B0EF16D7000608550 /* indexdetailstests.cpp */,
|
||||
9342238C0EF16D7000608550 /* mockdbclient.h */,
|
||||
9342238D0EF16D7000608550 /* pairingtests.cpp */,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user