summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/counttests.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/counttests.cpp
parent01965cf52bce6976637ecb8f4a622aeb05ab256a (diff)
downloadmongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/dbtests/counttests.cpp')
-rw-r--r--src/mongo/dbtests/counttests.cpp252
1 files changed, 123 insertions, 129 deletions
diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp
index 9d192edb7b9..855113d66ec 100644
--- a/src/mongo/dbtests/counttests.cpp
+++ b/src/mongo/dbtests/counttests.cpp
@@ -41,139 +41,133 @@
namespace CountTests {
- class Base {
- public:
- Base() : _txn(),
- _scopedXact(&_txn, MODE_IX),
- _lk(_txn.lockState(),
- nsToDatabaseSubstring(ns()), MODE_X),
- _context(&_txn, ns()),
- _client(&_txn) {
-
- _database = _context.db();
-
- {
- WriteUnitOfWork wunit(&_txn);
- _collection = _database->getCollection( ns() );
- if ( _collection ) {
- _database->dropCollection( &_txn, ns() );
- }
- _collection = _database->createCollection( &_txn, ns() );
- wunit.commit();
- }
-
- addIndex( fromjson( "{\"a\":1}" ) );
- }
- ~Base() {
- try {
- WriteUnitOfWork wunit(&_txn);
- uassertStatusOK( _database->dropCollection( &_txn, ns() ) );
- wunit.commit();
- }
- catch ( ... ) {
- FAIL( "Exception while cleaning up collection" );
- }
- }
-
- protected:
-
- static const char *ns() {
- return "unittests.counttests";
- }
-
- void addIndex( const BSONObj &key ) {
- Helpers::ensureIndex(&_txn,
- _collection,
- key,
- /*unique=*/ false,
- /*name=*/ key.firstElementFieldName());
- }
-
- void insert( const char *s ) {
+class Base {
+public:
+ Base()
+ : _txn(),
+ _scopedXact(&_txn, MODE_IX),
+ _lk(_txn.lockState(), nsToDatabaseSubstring(ns()), MODE_X),
+ _context(&_txn, ns()),
+ _client(&_txn) {
+ _database = _context.db();
+
+ {
WriteUnitOfWork wunit(&_txn);
- const BSONObj o = fromjson(s);
-
- if ( o["_id"].eoo() ) {
- BSONObjBuilder b;
- OID oid;
- oid.init();
- b.appendOID( "_id", &oid );
- b.appendElements( o );
- _collection->insertDocument( &_txn, b.obj(), false );
- }
- else {
- _collection->insertDocument( &_txn, o, false );
+ _collection = _database->getCollection(ns());
+ if (_collection) {
+ _database->dropCollection(&_txn, ns());
}
+ _collection = _database->createCollection(&_txn, ns());
wunit.commit();
}
-
- OperationContextImpl _txn;
- ScopedTransaction _scopedXact;
- Lock::DBLock _lk;
-
- OldClientContext _context;
-
- Database* _database;
- Collection* _collection;
-
- DBDirectClient _client;
- };
-
- class Basic : public Base {
- public:
- void run() {
- insert("{\"a\":\"b\"}");
- insert("{\"c\":\"d\"}");
- ASSERT_EQUALS(2ULL, _client.count(ns(), fromjson("{}")));
- }
- };
-
- class Query : public Base {
- public:
- void run() {
- insert( "{\"a\":\"b\"}" );
- insert( "{\"a\":\"b\",\"x\":\"y\"}" );
- insert( "{\"a\":\"c\"}" );
- ASSERT_EQUALS(2ULL, _client.count(ns(), fromjson("{\"a\":\"b\"}")));
- }
- };
-
- class QueryFields : public Base {
- public:
- void run() {
- insert( "{\"a\":\"b\"}" );
- insert( "{\"a\":\"c\"}" );
- insert( "{\"d\":\"e\"}" );
- ASSERT_EQUALS(1ULL, _client.count(ns(), fromjson("{\"a\":\"b\"}")));
- }
- };
-
- class IndexedRegex : public Base {
- public:
- void run() {
- insert( "{\"a\":\"c\"}" );
- insert( "{\"a\":\"b\"}" );
- insert( "{\"a\":\"d\"}" );
- ASSERT_EQUALS(1ULL, _client.count(ns(), fromjson("{\"a\":/^b/}")));
- }
- };
-
-
- class All : public Suite {
- public:
- All() : Suite( "count" ) {
-
+ addIndex(fromjson("{\"a\":1}"));
+ }
+ ~Base() {
+ try {
+ WriteUnitOfWork wunit(&_txn);
+ uassertStatusOK(_database->dropCollection(&_txn, ns()));
+ wunit.commit();
+ } catch (...) {
+ FAIL("Exception while cleaning up collection");
}
-
- void setupTests() {
- add<Basic>();
- add<Query>();
- add<QueryFields>();
- add<IndexedRegex>();
+ }
+
+protected:
+ static const char* ns() {
+ return "unittests.counttests";
+ }
+
+ void addIndex(const BSONObj& key) {
+ Helpers::ensureIndex(&_txn,
+ _collection,
+ key,
+ /*unique=*/false,
+ /*name=*/key.firstElementFieldName());
+ }
+
+ void insert(const char* s) {
+ WriteUnitOfWork wunit(&_txn);
+ const BSONObj o = fromjson(s);
+
+ if (o["_id"].eoo()) {
+ BSONObjBuilder b;
+ OID oid;
+ oid.init();
+ b.appendOID("_id", &oid);
+ b.appendElements(o);
+ _collection->insertDocument(&_txn, b.obj(), false);
+ } else {
+ _collection->insertDocument(&_txn, o, false);
}
- };
-
- SuiteInstance<All> myall;
-
-} // namespace CountTests
+ wunit.commit();
+ }
+
+
+ OperationContextImpl _txn;
+ ScopedTransaction _scopedXact;
+ Lock::DBLock _lk;
+
+ OldClientContext _context;
+
+ Database* _database;
+ Collection* _collection;
+
+ DBDirectClient _client;
+};
+
+class Basic : public Base {
+public:
+ void run() {
+ insert("{\"a\":\"b\"}");
+ insert("{\"c\":\"d\"}");
+ ASSERT_EQUALS(2ULL, _client.count(ns(), fromjson("{}")));
+ }
+};
+
+class Query : public Base {
+public:
+ void run() {
+ insert("{\"a\":\"b\"}");
+ insert("{\"a\":\"b\",\"x\":\"y\"}");
+ insert("{\"a\":\"c\"}");
+ ASSERT_EQUALS(2ULL, _client.count(ns(), fromjson("{\"a\":\"b\"}")));
+ }
+};
+
+class QueryFields : public Base {
+public:
+ void run() {
+ insert("{\"a\":\"b\"}");
+ insert("{\"a\":\"c\"}");
+ insert("{\"d\":\"e\"}");
+ ASSERT_EQUALS(1ULL, _client.count(ns(), fromjson("{\"a\":\"b\"}")));
+ }
+};
+
+class IndexedRegex : public Base {
+public:
+ void run() {
+ insert("{\"a\":\"c\"}");
+ insert("{\"a\":\"b\"}");
+ insert("{\"a\":\"d\"}");
+ ASSERT_EQUALS(1ULL, _client.count(ns(), fromjson("{\"a\":/^b/}")));
+ }
+};
+
+
+class All : public Suite {
+public:
+ All() : Suite("count") {}
+
+ void setupTests() {
+ add<Basic>();
+ add<Query>();
+ add<QueryFields>();
+ add<IndexedRegex>();
+ }
+};
+
+SuiteInstance<All> myall;
+
+} // namespace CountTests