Build a subobject without recopying the contents

This commit is contained in:
Aaron
2009-03-25 18:24:22 -04:00
parent 2506307e43
commit e5a43008fd
3 changed files with 54 additions and 8 deletions

View File

@@ -25,6 +25,16 @@
#include "dbtests.h"
namespace JsobjTests {
class BufBuilderBasic {
public:
void run() {
BufBuilder b( 0 );
b.append( "foo" );
ASSERT_EQUALS( 4, b.len() );
ASSERT( strcmp( "foo", b.buf() ) == 0 );
}
};
class BSONElementBasic {
public:
void run() {
@@ -571,9 +581,26 @@ namespace JsobjTests {
} // namespace ValueStreamTests
class SubObjectBuilder {
public:
void run() {
BSONObjBuilder b1;
b1.append( "a", "bcd" );
BSONObjBuilder b2( b1.subobjStart( "foo" ) );
b2.append( "ggg", 44.0 );
b2.done();
b1.append( "f", 10.0 );
BSONObj ret = b1.done();
out() << "ret: " << ret << endl;
ASSERT( ret.valid() );
ASSERT( ret.woCompare( fromjson( "{a:'bcd',foo:{ggg:44},f:10}" ) ) == 0 );
}
};
class All : public UnitTest::Suite {
public:
All() {
add< BufBuilderBasic >();
add< BSONElementBasic >();
add< BSONObjTests::Create >();
add< BSONObjTests::WoCompareBasic >();
@@ -626,6 +653,7 @@ namespace JsobjTests {
add< ValueStreamTests::LabelDoubleShares >();
add< ValueStreamTests::LabelMulti >();
add< ValueStreamTests::Unallowed >();
add< SubObjectBuilder >();
}
};