summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/counttests.cpp
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2015-07-28 18:16:39 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2015-07-28 18:27:27 -0400
commitb66e993f1c742518d9b5e93b0d8a5f8255a4127c (patch)
tree55e6fed05333d2d37f34586726a342ed7f7dbc29 /src/mongo/dbtests/counttests.cpp
parent314a22e93f283ab80e650618cbd3ed8babb8510f (diff)
downloadmongo-b66e993f1c742518d9b5e93b0d8a5f8255a4127c.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 918b87ed3d7..006f0b0faaf 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;
-
- Client::Context _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;
+
+ Client::Context _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