0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

option to appendOID to gen _id

This commit is contained in:
Eliot Horowitz 2009-09-15 14:50:17 -04:00
parent 46e9226668
commit 0c0a3893e4
2 changed files with 22 additions and 2 deletions

View File

@ -1152,14 +1152,17 @@ namespace mongo {
}
/** Append a BSON Object ID (OID type). */
void appendOID(const char *fieldName, OID *oid = 0) {
void appendOID(const char *fieldName, OID *oid = 0 , bool gen = false ) {
b.append((char) jstOID);
b.append(fieldName);
if ( oid )
b.append( (void *) oid, 12 );
else {
OID tmp;
memset( &tmp, 0, 12 );
if ( gen )
tmp.init();
else
memset( &tmp, 0, 12 );
b.append( (void *) &tmp, 12 );
}
}

View File

@ -579,6 +579,22 @@ namespace JsobjTests {
ASSERT( a == b );
}
};
class append {
public:
void run(){
BSONObjBuilder b;
b.appendOID( "a" , 0 );
b.appendOID( "b" , 0 , false );
b.appendOID( "c" , 0 , true );
BSONObj o = b.obj();
ASSERT( o["a"].__oid().str() == "000000000000000000000000" );
ASSERT( o["b"].__oid().str() == "000000000000000000000000" );
ASSERT( o["c"].__oid().str() != "000000000000000000000000" );
}
};
} // namespace OIDTests
namespace ValueStreamTests {
@ -834,6 +850,7 @@ namespace JsobjTests {
add< BSONObjTests::Validation::Fuzz >( .001 );
add< OIDTests::init1 >();
add< OIDTests::initParse1 >();
add< OIDTests::append >();
add< ValueStreamTests::LabelBasic >();
add< ValueStreamTests::LabelShares >();
add< ValueStreamTests::LabelDouble >();