summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/pdfiletests.cpp
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 00:22:50 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 10:56:02 -0400
commit9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch)
tree3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/dbtests/pdfiletests.cpp
parent01965cf52bce6976637ecb8f4a622aeb05ab256a (diff)
downloadmongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/dbtests/pdfiletests.cpp')
-rw-r--r--src/mongo/dbtests/pdfiletests.cpp251
1 files changed, 123 insertions, 128 deletions
diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp
index 97eccd6cb25..4ff601c127a 100644
--- a/src/mongo/dbtests/pdfiletests.cpp
+++ b/src/mongo/dbtests/pdfiletests.cpp
@@ -41,133 +41,128 @@
namespace PdfileTests {
- namespace Insert {
- class Base {
- public:
- Base() : _scopedXact(&_txn, MODE_X),
- _lk(_txn.lockState()),
- _context(&_txn, ns()) {
-
- }
-
- virtual ~Base() {
- if ( !collection() )
- return;
- WriteUnitOfWork wunit(&_txn);
- _context.db()->dropCollection( &_txn, ns() );
- wunit.commit();
- }
-
- protected:
- const char *ns() {
- return "unittests.pdfiletests.Insert";
- }
- Collection* collection() {
- return _context.db()->getCollection( ns() );
- }
-
- OperationContextImpl _txn;
- ScopedTransaction _scopedXact;
- Lock::GlobalWrite _lk;
- OldClientContext _context;
- };
-
- class InsertNoId : public Base {
- public:
- void run() {
- WriteUnitOfWork wunit(&_txn);
- BSONObj x = BSON( "x" << 1 );
- ASSERT( x["_id"].type() == 0 );
- Collection* collection = _context.db()->getOrCreateCollection( &_txn, ns() );
- StatusWith<RecordId> dl = collection->insertDocument( &_txn, x, true );
- ASSERT( !dl.isOK() );
-
- StatusWith<BSONObj> fixed = fixDocumentForInsert( x );
- ASSERT( fixed.isOK() );
- x = fixed.getValue();
- ASSERT( x["_id"].type() == jstOID );
- dl = collection->insertDocument( &_txn, x, true );
- ASSERT( dl.isOK() );
- wunit.commit();
- }
- };
-
- class UpdateDate : public Base {
- public:
- void run() {
- BSONObjBuilder b;
- b.appendTimestamp( "a" );
- b.append( "_id", 1 );
- BSONObj o = b.done();
-
- BSONObj fixed = fixDocumentForInsert( o ).getValue();
- ASSERT_EQUALS( 2, fixed.nFields() );
- ASSERT( fixed.firstElement().fieldNameStringData() == "_id" );
- ASSERT( fixed.firstElement().number() == 1 );
-
- BSONElement a = fixed["a"];
- ASSERT( o["a"].type() == bsonTimestamp );
- ASSERT( o["a"].timestampValue() == 0 );
- ASSERT( a.type() == bsonTimestamp );
- ASSERT( a.timestampValue() > 0 );
- }
- };
-
- class UpdateDate2 : public Base {
- public:
- void run() {
- BSONObj o;
- {
- BSONObjBuilder b;
- b.appendTimestamp( "a" );
- b.appendTimestamp( "b" );
- b.append( "_id", 1 );
- o = b.obj();
- }
-
- BSONObj fixed = fixDocumentForInsert( o ).getValue();
- ASSERT_EQUALS( 3, fixed.nFields() );
- ASSERT( fixed.firstElement().fieldNameStringData() == "_id" );
- ASSERT( fixed.firstElement().number() == 1 );
-
- BSONElement a = fixed["a"];
- ASSERT( o["a"].type() == bsonTimestamp );
- ASSERT( o["a"].timestampValue() == 0 );
- ASSERT( a.type() == bsonTimestamp );
- ASSERT( a.timestampValue() > 0 );
-
- BSONElement b = fixed["b"];
- ASSERT( o["b"].type() == bsonTimestamp );
- ASSERT( o["b"].timestampValue() == 0 );
- ASSERT( b.type() == bsonTimestamp );
- ASSERT( b.timestampValue() > 0 );
- }
- };
-
- class ValidId : public Base {
- public:
- void run() {
- ASSERT( fixDocumentForInsert( BSON( "_id" << 5 ) ).isOK() );
- ASSERT( fixDocumentForInsert( BSON( "_id" << BSON( "x" << 5 ) ) ).isOK() );
- ASSERT( !fixDocumentForInsert( BSON( "_id" << BSON( "$x" << 5 ) ) ).isOK() );
- ASSERT( !fixDocumentForInsert( BSON( "_id" << BSON( "$oid" << 5 ) ) ).isOK() );
- }
- };
- } // namespace Insert
-
- class All : public Suite {
- public:
- All() : Suite( "pdfile" ) {}
-
- void setupTests() {
- add< Insert::InsertNoId >();
- add< Insert::UpdateDate >();
- add< Insert::UpdateDate2 >();
- add< Insert::ValidId >();
+namespace Insert {
+class Base {
+public:
+ Base() : _scopedXact(&_txn, MODE_X), _lk(_txn.lockState()), _context(&_txn, ns()) {}
+
+ virtual ~Base() {
+ if (!collection())
+ return;
+ WriteUnitOfWork wunit(&_txn);
+ _context.db()->dropCollection(&_txn, ns());
+ wunit.commit();
+ }
+
+protected:
+ const char* ns() {
+ return "unittests.pdfiletests.Insert";
+ }
+ Collection* collection() {
+ return _context.db()->getCollection(ns());
+ }
+
+ OperationContextImpl _txn;
+ ScopedTransaction _scopedXact;
+ Lock::GlobalWrite _lk;
+ OldClientContext _context;
+};
+
+class InsertNoId : public Base {
+public:
+ void run() {
+ WriteUnitOfWork wunit(&_txn);
+ BSONObj x = BSON("x" << 1);
+ ASSERT(x["_id"].type() == 0);
+ Collection* collection = _context.db()->getOrCreateCollection(&_txn, ns());
+ StatusWith<RecordId> dl = collection->insertDocument(&_txn, x, true);
+ ASSERT(!dl.isOK());
+
+ StatusWith<BSONObj> fixed = fixDocumentForInsert(x);
+ ASSERT(fixed.isOK());
+ x = fixed.getValue();
+ ASSERT(x["_id"].type() == jstOID);
+ dl = collection->insertDocument(&_txn, x, true);
+ ASSERT(dl.isOK());
+ wunit.commit();
+ }
+};
+
+class UpdateDate : public Base {
+public:
+ void run() {
+ BSONObjBuilder b;
+ b.appendTimestamp("a");
+ b.append("_id", 1);
+ BSONObj o = b.done();
+
+ BSONObj fixed = fixDocumentForInsert(o).getValue();
+ ASSERT_EQUALS(2, fixed.nFields());
+ ASSERT(fixed.firstElement().fieldNameStringData() == "_id");
+ ASSERT(fixed.firstElement().number() == 1);
+
+ BSONElement a = fixed["a"];
+ ASSERT(o["a"].type() == bsonTimestamp);
+ ASSERT(o["a"].timestampValue() == 0);
+ ASSERT(a.type() == bsonTimestamp);
+ ASSERT(a.timestampValue() > 0);
+ }
+};
+
+class UpdateDate2 : public Base {
+public:
+ void run() {
+ BSONObj o;
+ {
+ BSONObjBuilder b;
+ b.appendTimestamp("a");
+ b.appendTimestamp("b");
+ b.append("_id", 1);
+ o = b.obj();
}
- };
-
- SuiteInstance<All> myall;
-
-} // namespace PdfileTests
+ BSONObj fixed = fixDocumentForInsert(o).getValue();
+ ASSERT_EQUALS(3, fixed.nFields());
+ ASSERT(fixed.firstElement().fieldNameStringData() == "_id");
+ ASSERT(fixed.firstElement().number() == 1);
+
+ BSONElement a = fixed["a"];
+ ASSERT(o["a"].type() == bsonTimestamp);
+ ASSERT(o["a"].timestampValue() == 0);
+ ASSERT(a.type() == bsonTimestamp);
+ ASSERT(a.timestampValue() > 0);
+
+ BSONElement b = fixed["b"];
+ ASSERT(o["b"].type() == bsonTimestamp);
+ ASSERT(o["b"].timestampValue() == 0);
+ ASSERT(b.type() == bsonTimestamp);
+ ASSERT(b.timestampValue() > 0);
+ }
+};
+
+class ValidId : public Base {
+public:
+ void run() {
+ ASSERT(fixDocumentForInsert(BSON("_id" << 5)).isOK());
+ ASSERT(fixDocumentForInsert(BSON("_id" << BSON("x" << 5))).isOK());
+ ASSERT(!fixDocumentForInsert(BSON("_id" << BSON("$x" << 5))).isOK());
+ ASSERT(!fixDocumentForInsert(BSON("_id" << BSON("$oid" << 5))).isOK());
+ }
+};
+} // namespace Insert
+
+class All : public Suite {
+public:
+ All() : Suite("pdfile") {}
+
+ void setupTests() {
+ add<Insert::InsertNoId>();
+ add<Insert::UpdateDate>();
+ add<Insert::UpdateDate2>();
+ add<Insert::ValidId>();
+ }
+};
+
+SuiteInstance<All> myall;
+
+} // namespace PdfileTests