summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2014-10-23 15:57:12 -0400
committerAndrew Morrow <acm@mongodb.com>2014-10-27 11:07:37 -0400
commitc1c1116c488351e0cdbd7626dcc8ce1f5dc828af (patch)
tree7ed0e6596b9ea93715f23dd112c251a03bb40c28 /src
parent0fde30ad2f873e7f835aa224e83a97ae6d4a171e (diff)
downloadmongo-c1c1116c488351e0cdbd7626dcc8ce1f5dc828af.tar.gz
SERVER-15707 Fix leaks in C++ unit test framework
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/sorter/sorter_test.cpp4
-rw-r--r--src/mongo/db/storage/mmap_v1/btree/btree_logic_test.cpp7
-rw-r--r--src/mongo/dbtests/accumulatortests.cpp4
-rw-r--r--src/mongo/dbtests/basictests.cpp4
-rw-r--r--src/mongo/dbtests/chunktests.cpp6
-rw-r--r--src/mongo/dbtests/clienttests.cpp4
-rw-r--r--src/mongo/dbtests/commandtests.cpp4
-rw-r--r--src/mongo/dbtests/counttests.cpp4
-rw-r--r--src/mongo/dbtests/directclienttests.cpp4
-rw-r--r--src/mongo/dbtests/documentsourcetests.cpp4
-rw-r--r--src/mongo/dbtests/documenttests.cpp6
-rw-r--r--src/mongo/dbtests/executor_registry.cpp4
-rw-r--r--src/mongo/dbtests/expressiontests.cpp4
-rw-r--r--src/mongo/dbtests/gle_test.cpp4
-rw-r--r--src/mongo/dbtests/gridfstest.cpp4
-rw-r--r--src/mongo/dbtests/indexcatalogtests.cpp4
-rw-r--r--src/mongo/dbtests/jsobjtests.cpp4
-rw-r--r--src/mongo/dbtests/jsontests.cpp4
-rw-r--r--src/mongo/dbtests/jstests.cpp4
-rw-r--r--src/mongo/dbtests/matchertests.cpp4
-rw-r--r--src/mongo/dbtests/mmaptests.cpp4
-rw-r--r--src/mongo/dbtests/namespacetests.cpp5
-rw-r--r--src/mongo/dbtests/oplogstarttests.cpp4
-rw-r--r--src/mongo/dbtests/pdfiletests.cpp4
-rw-r--r--src/mongo/dbtests/perf/perftest.cpp36
-rw-r--r--src/mongo/dbtests/pipelinetests.cpp6
-rw-r--r--src/mongo/dbtests/plan_ranking.cpp4
-rw-r--r--src/mongo/dbtests/query_multi_plan_runner.cpp4
-rw-r--r--src/mongo/dbtests/query_plan_executor.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_and.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_collscan.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_count.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_delete.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_distinct.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_fetch.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_keep.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_limit_skip.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_merge_sort.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_sort.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_subplan.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_tests.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_update.cpp4
-rw-r--r--src/mongo/dbtests/querytests.cpp4
-rw-r--r--src/mongo/dbtests/repltests.cpp4
-rw-r--r--src/mongo/dbtests/sharding.cpp4
-rw-r--r--src/mongo/dbtests/socktests.cpp4
-rw-r--r--src/mongo/dbtests/threadedtests.cpp4
-rw-r--r--src/mongo/dbtests/updatetests.cpp4
-rw-r--r--src/mongo/unittest/unittest.cpp31
-rw-r--r--src/mongo/unittest/unittest.h17
50 files changed, 210 insertions, 72 deletions
diff --git a/src/mongo/db/sorter/sorter_test.cpp b/src/mongo/db/sorter/sorter_test.cpp
index 610075373d6..78a129d2b0e 100644
--- a/src/mongo/db/sorter/sorter_test.cpp
+++ b/src/mongo/db/sorter/sorter_test.cpp
@@ -545,5 +545,7 @@ namespace mongo {
add<SorterTests::LotsOfDataWithLimit<5000,/*random=*/false> >(); // spills
add<SorterTests::LotsOfDataWithLimit<5000,/*random=*/true> >(); // spills
}
- } extSortTests;
+ };
+
+ mongo::unittest::SuiteInstance<SorterSuite> extSortTests;
}
diff --git a/src/mongo/db/storage/mmap_v1/btree/btree_logic_test.cpp b/src/mongo/db/storage/mmap_v1/btree/btree_logic_test.cpp
index d1d6e3d1de3..16d773f9a22 100644
--- a/src/mongo/db/storage/mmap_v1/btree/btree_logic_test.cpp
+++ b/src/mongo/db/storage/mmap_v1/btree/btree_logic_test.cpp
@@ -2258,6 +2258,9 @@ namespace mongo {
};
// Test suite for both V0 and V1
- static BtreeLogicTestSuite<BtreeLayoutV0> SUITE_V0("BTreeLogicTests_V0");
- static BtreeLogicTestSuite<BtreeLayoutV1> SUITE_V1("BTreeLogicTests_V1");
+ static unittest::SuiteInstance< BtreeLogicTestSuite<BtreeLayoutV0> > SUITE_V0(
+ "BTreeLogicTests_V0");
+
+ static unittest::SuiteInstance< BtreeLogicTestSuite<BtreeLayoutV1> > SUITE_V1(
+ "BTreeLogicTests_V1");
}
diff --git a/src/mongo/dbtests/accumulatortests.cpp b/src/mongo/dbtests/accumulatortests.cpp
index da5779f63fa..331a8ccc499 100644
--- a/src/mongo/dbtests/accumulatortests.cpp
+++ b/src/mongo/dbtests/accumulatortests.cpp
@@ -914,6 +914,8 @@ namespace AccumulatorTests {
add<Sum::IntUndefined>();
add<Sum::NoOverflowBeforeDouble>();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace AccumulatorTests
diff --git a/src/mongo/dbtests/basictests.cpp b/src/mongo/dbtests/basictests.cpp
index ba4b0773bab..64fc2876b2e 100644
--- a/src/mongo/dbtests/basictests.cpp
+++ b/src/mongo/dbtests/basictests.cpp
@@ -570,7 +570,9 @@ namespace BasicTests {
add< CompressionTest1 >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace BasicTests
diff --git a/src/mongo/dbtests/chunktests.cpp b/src/mongo/dbtests/chunktests.cpp
index 3faddbc5305..facf2b33ee2 100644
--- a/src/mongo/dbtests/chunktests.cpp
+++ b/src/mongo/dbtests/chunktests.cpp
@@ -274,6 +274,8 @@ namespace ChunkTests {
add<ChunkManagerTests::OrEqualityUnsatisfiableInequality>();
add<ChunkManagerTests::InMultiShard>();
}
- } myall;
-
+ };
+
+ SuiteInstance<All> myAll;
+
} // namespace ChunkTests
diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp
index 0b26a83e208..f3cd6792b1a 100644
--- a/src/mongo/dbtests/clienttests.cpp
+++ b/src/mongo/dbtests/clienttests.cpp
@@ -272,5 +272,7 @@ namespace ClientTests {
add<ConnectionStringTests>();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
}
diff --git a/src/mongo/dbtests/commandtests.cpp b/src/mongo/dbtests/commandtests.cpp
index 124498b4be1..faba4d41b9e 100644
--- a/src/mongo/dbtests/commandtests.cpp
+++ b/src/mongo/dbtests/commandtests.cpp
@@ -109,5 +109,7 @@ namespace CommandTests {
add< FileMD5::Type2 >();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
}
diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp
index 10f823a6c39..2613c3b933c 100644
--- a/src/mongo/dbtests/counttests.cpp
+++ b/src/mongo/dbtests/counttests.cpp
@@ -166,6 +166,8 @@ namespace CountTests {
add<QueryFields>();
add<IndexedRegex>();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace CountTests
diff --git a/src/mongo/dbtests/directclienttests.cpp b/src/mongo/dbtests/directclienttests.cpp
index a0e8a96898f..b1fbcb3d6fe 100644
--- a/src/mongo/dbtests/directclienttests.cpp
+++ b/src/mongo/dbtests/directclienttests.cpp
@@ -194,5 +194,7 @@ namespace DirectClientTests {
add< BadNSUpdate >();
add< BadNSRemove >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
}
diff --git a/src/mongo/dbtests/documentsourcetests.cpp b/src/mongo/dbtests/documentsourcetests.cpp
index 33b94af0ff0..4e5a44742a9 100644
--- a/src/mongo/dbtests/documentsourcetests.cpp
+++ b/src/mongo/dbtests/documentsourcetests.cpp
@@ -1986,6 +1986,8 @@ namespace DocumentSourceTests {
add<DocumentSourceMatch::RedactSafePortion>();
add<DocumentSourceMatch::Coalesce>();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace DocumentSourceTests
diff --git a/src/mongo/dbtests/documenttests.cpp b/src/mongo/dbtests/documenttests.cpp
index fa6156e473b..fe54e29585f 100644
--- a/src/mongo/dbtests/documenttests.cpp
+++ b/src/mongo/dbtests/documenttests.cpp
@@ -1507,6 +1507,8 @@ namespace DocumentTests {
add<Value::SubFields>();
add<Value::SerializationOfMissingForSorter>();
}
- } myall;
-
+ };
+
+ SuiteInstance<All> myall;
+
} // namespace DocumentTests
diff --git a/src/mongo/dbtests/executor_registry.cpp b/src/mongo/dbtests/executor_registry.cpp
index 821e81ac377..5efaf842934 100644
--- a/src/mongo/dbtests/executor_registry.cpp
+++ b/src/mongo/dbtests/executor_registry.cpp
@@ -331,6 +331,8 @@ namespace ExecutorRegistry {
add<ExecutorRegistryDropOneIndex>();
add<ExecutorRegistryDropDatabase>();
}
- } executorRegistryAll;
+ };
+
+ SuiteInstance<All> executorRegistryAll;
} // namespace ExecutorRegistry
diff --git a/src/mongo/dbtests/expressiontests.cpp b/src/mongo/dbtests/expressiontests.cpp
index ab4cf9c4479..449ac2d3597 100644
--- a/src/mongo/dbtests/expressiontests.cpp
+++ b/src/mongo/dbtests/expressiontests.cpp
@@ -3740,6 +3740,8 @@ namespace ExpressionTests {
add<AllAnyElements::FalseViaInt>();
add<AllAnyElements::Null>();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace ExpressionTests
diff --git a/src/mongo/dbtests/gle_test.cpp b/src/mongo/dbtests/gle_test.cpp
index 8c0d410b399..b5f958671a6 100644
--- a/src/mongo/dbtests/gle_test.cpp
+++ b/src/mongo/dbtests/gle_test.cpp
@@ -106,5 +106,7 @@ namespace {
add< GetLastErrorCommandFailure >();
add< GetLastErrorFromDup >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
}
diff --git a/src/mongo/dbtests/gridfstest.cpp b/src/mongo/dbtests/gridfstest.cpp
index ca95149b83d..299867fc941 100644
--- a/src/mongo/dbtests/gridfstest.cpp
+++ b/src/mongo/dbtests/gridfstest.cpp
@@ -65,6 +65,8 @@ namespace {
void setupTests() {
add< SetChunkSizeTest >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
}
diff --git a/src/mongo/dbtests/indexcatalogtests.cpp b/src/mongo/dbtests/indexcatalogtests.cpp
index 5d27c3d9200..2d42e26767c 100644
--- a/src/mongo/dbtests/indexcatalogtests.cpp
+++ b/src/mongo/dbtests/indexcatalogtests.cpp
@@ -98,5 +98,7 @@ namespace IndexCatalogTests {
void setupTests() {
add<IndexIteratorTests>();
}
- } indexCatalogTests;
+ };
+
+ SuiteInstance<IndexCatalogTests> indexCatalogTests;
}
diff --git a/src/mongo/dbtests/jsobjtests.cpp b/src/mongo/dbtests/jsobjtests.cpp
index 7105131f5e4..e0cfe65c13b 100644
--- a/src/mongo/dbtests/jsobjtests.cpp
+++ b/src/mongo/dbtests/jsobjtests.cpp
@@ -2310,7 +2310,9 @@ namespace JsobjTests {
add< HashingTest >();
add< NestedBuilderOversize >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace JsobjTests
diff --git a/src/mongo/dbtests/jsontests.cpp b/src/mongo/dbtests/jsontests.cpp
index 688e0e8f460..9c3b322028a 100644
--- a/src/mongo/dbtests/jsontests.cpp
+++ b/src/mongo/dbtests/jsontests.cpp
@@ -2931,7 +2931,9 @@ namespace JsonTests {
add< FromJsonTests::MinKey >();
add< FromJsonTests::MaxKey >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace JsonTests
diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp
index 03a1479c175..e9d1a345639 100644
--- a/src/mongo/dbtests/jstests.cpp
+++ b/src/mongo/dbtests/jstests.cpp
@@ -2159,7 +2159,9 @@ namespace JSTests {
add< RoundTripTests::MD5 >();
add< RoundTripTests::NullString >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace JavaJSTests
diff --git a/src/mongo/dbtests/matchertests.cpp b/src/mongo/dbtests/matchertests.cpp
index 591afcfd383..534bf5845b2 100644
--- a/src/mongo/dbtests/matchertests.cpp
+++ b/src/mongo/dbtests/matchertests.cpp
@@ -270,7 +270,9 @@ namespace MatcherTests {
ADD_BOTH(WithinCenter);
ADD_BOTH(WithinPolygon);
}
- } dball;
+ };
+
+ SuiteInstance<All> dball;
} // namespace MatcherTests
diff --git a/src/mongo/dbtests/mmaptests.cpp b/src/mongo/dbtests/mmaptests.cpp
index 5508e01482c..160e5f80b99 100644
--- a/src/mongo/dbtests/mmaptests.cpp
+++ b/src/mongo/dbtests/mmaptests.cpp
@@ -179,7 +179,9 @@ namespace MMapTests {
add< LeakTest >();
add< ExtentSizing >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
#if 0
diff --git a/src/mongo/dbtests/namespacetests.cpp b/src/mongo/dbtests/namespacetests.cpp
index a42dfdc7629..b12c9631397 100644
--- a/src/mongo/dbtests/namespacetests.cpp
+++ b/src/mongo/dbtests/namespacetests.cpp
@@ -635,6 +635,9 @@ namespace NamespaceTests {
add< DatabaseTests::RollbackDropCollection >();
#endif
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
+
} // namespace NamespaceTests
diff --git a/src/mongo/dbtests/oplogstarttests.cpp b/src/mongo/dbtests/oplogstarttests.cpp
index 485ba802bc2..c2129065b0c 100644
--- a/src/mongo/dbtests/oplogstarttests.cpp
+++ b/src/mongo/dbtests/oplogstarttests.cpp
@@ -368,6 +368,8 @@ namespace OplogStartTests {
add< OplogStartEOF >();
}
}
- } oplogStart;
+ };
+
+ SuiteInstance<All> oplogStart;
} // namespace OplogStartTests
diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp
index 9e8836cb45f..828530905c6 100644
--- a/src/mongo/dbtests/pdfiletests.cpp
+++ b/src/mongo/dbtests/pdfiletests.cpp
@@ -161,7 +161,9 @@ namespace PdfileTests {
add< Insert::UpdateDate2 >();
add< Insert::ValidId >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace PdfileTests
diff --git a/src/mongo/dbtests/perf/perftest.cpp b/src/mongo/dbtests/perf/perftest.cpp
index b891dd92e94..1d2c38aa185 100644
--- a/src/mongo/dbtests/perf/perftest.cpp
+++ b/src/mongo/dbtests/perf/perftest.cpp
@@ -195,7 +195,10 @@ namespace Insert {
add< OneIndexReverse >();
add< OneIndexHighLow >();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
+
} // namespace Insert
namespace Update {
@@ -277,7 +280,10 @@ namespace Update {
add< Set >();
add< SetGrow >();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
+
} // namespace Update
namespace BSON {
@@ -391,7 +397,9 @@ namespace BSON {
add< Copy<1000> >();
add< Copy<10*1000> >();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
} // namespace BSON
@@ -461,7 +469,9 @@ namespace Index {
add< String >();
add< Object >();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
} // namespace Index
@@ -604,7 +614,9 @@ namespace QueryTests {
add< GetMoreIndex >();
add< GetMoreKeyMatchHelps >();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
} // namespace QueryTests
@@ -660,7 +672,9 @@ namespace Count {
add< CountIndex >();
add< CountSimpleIndex >();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
} // namespace Count
@@ -743,7 +757,10 @@ namespace Plan {
add< Sort >();
add< Query >();
}
- } all;
+ };
+
+ SuiteInstance<all> all;
+
#endif
} // namespace Plan
@@ -775,7 +792,10 @@ namespace Misc {
add< TimeMicros64 >();
add< JSTime >();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
+
}
int main( int argc, char **argv, char** envp ) {
diff --git a/src/mongo/dbtests/pipelinetests.cpp b/src/mongo/dbtests/pipelinetests.cpp
index 4d68d40611d..3dd0862057a 100644
--- a/src/mongo/dbtests/pipelinetests.cpp
+++ b/src/mongo/dbtests/pipelinetests.cpp
@@ -433,6 +433,8 @@ namespace PipelineTests {
add<Optimizations::Sharded::limitFieldsSentFromShardsToMerger::JustNeedsMetadata>();
add<Optimizations::Sharded::limitFieldsSentFromShardsToMerger::ShardAlreadyExhaustive>();
}
- } myall;
-
+ };
+
+ SuiteInstance<All> myall;
+
} // namespace PipelineTests
diff --git a/src/mongo/dbtests/plan_ranking.cpp b/src/mongo/dbtests/plan_ranking.cpp
index 41ec196a6fe..e8b39d6f63b 100644
--- a/src/mongo/dbtests/plan_ranking.cpp
+++ b/src/mongo/dbtests/plan_ranking.cpp
@@ -842,6 +842,8 @@ namespace PlanRankingTests {
add<PlanRankingWorkPlansLongEnough>();
add<PlanRankingAccountForKeySkips>();
}
- } planRankingAll;
+ };
+
+ SuiteInstance<All> planRankingAll;
} // namespace PlanRankingTest
diff --git a/src/mongo/dbtests/query_multi_plan_runner.cpp b/src/mongo/dbtests/query_multi_plan_runner.cpp
index 7da7cb7c28c..32f3dbf0f7d 100644
--- a/src/mongo/dbtests/query_multi_plan_runner.cpp
+++ b/src/mongo/dbtests/query_multi_plan_runner.cpp
@@ -286,6 +286,8 @@ namespace QueryMultiPlanRunner {
add<MPRCollectionScanVsHighlySelectiveIXScan>();
add<MPRBackupPlan>();
}
- } queryMultiPlanRunnerAll;
+ };
+
+ SuiteInstance<All> queryMultiPlanRunnerAll;
} // namespace QueryMultiPlanRunner
diff --git a/src/mongo/dbtests/query_plan_executor.cpp b/src/mongo/dbtests/query_plan_executor.cpp
index 1fa7212831d..edb5653d33b 100644
--- a/src/mongo/dbtests/query_plan_executor.cpp
+++ b/src/mongo/dbtests/query_plan_executor.cpp
@@ -508,6 +508,8 @@ namespace QueryPlanExecutor {
add<ClientCursor::InvalidatePinned>();
add<ClientCursor::Timeout>();
}
- } queryPlanExecutorAll;
+ };
+
+ SuiteInstance<All> queryPlanExecutorAll;
} // namespace QueryPlanExecutor
diff --git a/src/mongo/dbtests/query_stage_and.cpp b/src/mongo/dbtests/query_stage_and.cpp
index 645aba10cd2..d6398ee0869 100644
--- a/src/mongo/dbtests/query_stage_and.cpp
+++ b/src/mongo/dbtests/query_stage_and.cpp
@@ -1411,6 +1411,8 @@ namespace QueryStageAnd {
add<QueryStageAndSortedFirstChildFetched>();
add<QueryStageAndSortedSecondChildFetched>();
}
- } queryStageAndAll;
+ };
+
+ SuiteInstance<All> queryStageAndAll;
} // namespace QueryStageAnd
diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp
index db759de784f..0d2b5bec74c 100644
--- a/src/mongo/dbtests/query_stage_collscan.cpp
+++ b/src/mongo/dbtests/query_stage_collscan.cpp
@@ -387,6 +387,8 @@ namespace QueryStageCollectionScan {
add<QueryStageCollscanInvalidateUpcomingObject>();
add<QueryStageCollscanInvalidateUpcomingObjectBackward>();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
}
diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp
index f0d64edaa1c..2d1b2520ab5 100644
--- a/src/mongo/dbtests/query_stage_count.cpp
+++ b/src/mongo/dbtests/query_stage_count.cpp
@@ -639,7 +639,9 @@ namespace QueryStageCount {
add<QueryStageCountBecomesMultiKeyDuringYield>();
add<QueryStageCountUnusedKeys>();
}
- } queryStageCountAll;
+ };
+
+ SuiteInstance<All> queryStageCountAll;
} // namespace QueryStageCount
diff --git a/src/mongo/dbtests/query_stage_delete.cpp b/src/mongo/dbtests/query_stage_delete.cpp
index 2c905e184cb..56849e38f70 100644
--- a/src/mongo/dbtests/query_stage_delete.cpp
+++ b/src/mongo/dbtests/query_stage_delete.cpp
@@ -167,6 +167,8 @@ namespace QueryStageDelete {
// Stage-specific tests below.
add<QueryStageDeleteInvalidateUpcomingObject>();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
}
diff --git a/src/mongo/dbtests/query_stage_distinct.cpp b/src/mongo/dbtests/query_stage_distinct.cpp
index 31f543e4170..2d66731f15b 100644
--- a/src/mongo/dbtests/query_stage_distinct.cpp
+++ b/src/mongo/dbtests/query_stage_distinct.cpp
@@ -235,6 +235,8 @@ namespace QueryStageDistinct {
add<QueryStageDistinctBasic>();
add<QueryStageDistinctMultiKey>();
}
- } queryStageDistinctAll;
+ };
+
+ SuiteInstance<All> queryStageDistinctAll;
} // namespace QueryStageDistinct
diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp
index 713103d74f1..4fd2a04ad3f 100644
--- a/src/mongo/dbtests/query_stage_fetch.cpp
+++ b/src/mongo/dbtests/query_stage_fetch.cpp
@@ -211,6 +211,8 @@ namespace QueryStageFetch {
add<FetchStageAlreadyFetched>();
add<FetchStageFilter>();
}
- } queryStageFetchAll;
+ };
+
+ SuiteInstance<All> queryStageFetchAll;
} // namespace QueryStageFetch
diff --git a/src/mongo/dbtests/query_stage_keep.cpp b/src/mongo/dbtests/query_stage_keep.cpp
index 91c8fb639ba..3006d0e1e79 100644
--- a/src/mongo/dbtests/query_stage_keep.cpp
+++ b/src/mongo/dbtests/query_stage_keep.cpp
@@ -167,6 +167,8 @@ namespace QueryStageKeep {
void setupTests() {
add<KeepStageBasic>();
}
- } queryStageKeepAll;
+ };
+
+ SuiteInstance<All> queryStageKeepAll;
} // namespace QueryStageKeep
diff --git a/src/mongo/dbtests/query_stage_limit_skip.cpp b/src/mongo/dbtests/query_stage_limit_skip.cpp
index af10638cede..994faa3323f 100644
--- a/src/mongo/dbtests/query_stage_limit_skip.cpp
+++ b/src/mongo/dbtests/query_stage_limit_skip.cpp
@@ -98,6 +98,8 @@ namespace {
void setupTests() {
add<QueryStageLimitSkipBasicTest>();
}
- } queryStageLimitSkipAll;
+ };
+
+ SuiteInstance<All> queryStageLimitSkipAll;
} // namespace
diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp
index a318da31114..5038ea91c8b 100644
--- a/src/mongo/dbtests/query_stage_merge_sort.cpp
+++ b/src/mongo/dbtests/query_stage_merge_sort.cpp
@@ -634,7 +634,9 @@ namespace QueryStageMergeSortTests {
add<QueryStageMergeSortManyShort>();
add<QueryStageMergeSortInvalidation>();
}
- } queryStageMergeSortTest;
+ };
+
+ SuiteInstance<All> queryStageMergeSortTest;
} // namespace
diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp
index 0092f6ccec6..f4d81acea2d 100644
--- a/src/mongo/dbtests/query_stage_sort.cpp
+++ b/src/mongo/dbtests/query_stage_sort.cpp
@@ -410,7 +410,9 @@ namespace QueryStageSortTests {
add<QueryStageSortInvalidationWithLimit<1> >();
add<QueryStageSortParallelArrays>();
}
- } queryStageSortTest;
+ };
+
+ SuiteInstance<All> queryStageSortTest;
} // namespace
diff --git a/src/mongo/dbtests/query_stage_subplan.cpp b/src/mongo/dbtests/query_stage_subplan.cpp
index e431fcb68db..184b1010a0c 100644
--- a/src/mongo/dbtests/query_stage_subplan.cpp
+++ b/src/mongo/dbtests/query_stage_subplan.cpp
@@ -109,6 +109,8 @@ namespace QueryStageSubplan {
void setupTests() {
add<QueryStageSubplanGeo2dOr>();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
} // namespace QueryStageSubplan
diff --git a/src/mongo/dbtests/query_stage_tests.cpp b/src/mongo/dbtests/query_stage_tests.cpp
index c0b203ef0b9..4b1ef66dd50 100644
--- a/src/mongo/dbtests/query_stage_tests.cpp
+++ b/src/mongo/dbtests/query_stage_tests.cpp
@@ -227,6 +227,8 @@ namespace QueryStageTests {
add<QueryStageIXScanLowerUpperInclFilter>();
add<QueryStageIXScanCantMatch>();
}
- } queryStageTestsAll;
+ };
+
+ SuiteInstance<All> queryStageTestsAll;
} // namespace
diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp
index 7be23ea50d5..b0e18879361 100644
--- a/src/mongo/dbtests/query_stage_update.cpp
+++ b/src/mongo/dbtests/query_stage_update.cpp
@@ -356,6 +356,8 @@ namespace QueryStageUpdate {
add<QueryStageUpdateUpsertEmptyColl>();
add<QueryStageUpdateSkipInvalidatedDoc>();
}
- } all;
+ };
+
+ SuiteInstance<All> all;
} // namespace QueryStageUpdate
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index 57b9632e94e..221095c054c 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -1642,7 +1642,9 @@ namespace QueryTests {
add< OrderingTest >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace QueryTests
diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp
index 7d036168084..654adaba00f 100644
--- a/src/mongo/dbtests/repltests.cpp
+++ b/src/mongo/dbtests/repltests.cpp
@@ -1519,7 +1519,9 @@ namespace ReplTests {
add< ReplSetMemberCfgEquality >();
add< ShouldRetry >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace ReplTests
diff --git a/src/mongo/dbtests/sharding.cpp b/src/mongo/dbtests/sharding.cpp
index b2c5b1a4831..b1c6c8ec7b7 100644
--- a/src/mongo/dbtests/sharding.cpp
+++ b/src/mongo/dbtests/sharding.cpp
@@ -671,6 +671,8 @@ namespace ShardingTests {
add< ChunkDiffUnitTestNormal >();
add< ChunkDiffUnitTestInverse >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
}
diff --git a/src/mongo/dbtests/socktests.cpp b/src/mongo/dbtests/socktests.cpp
index f27020bc069..65aa215794a 100644
--- a/src/mongo/dbtests/socktests.cpp
+++ b/src/mongo/dbtests/socktests.cpp
@@ -56,7 +56,9 @@ namespace SockTests {
void setupTests() {
add< HostByName >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace SockTests
diff --git a/src/mongo/dbtests/threadedtests.cpp b/src/mongo/dbtests/threadedtests.cpp
index 021e208a4cd..1c1f81d74e8 100644
--- a/src/mongo/dbtests/threadedtests.cpp
+++ b/src/mongo/dbtests/threadedtests.cpp
@@ -893,5 +893,7 @@ namespace ThreadedTests {
add< MongoMutexTest >();
add< TicketHolderWaits >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
}
diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp
index 7794238aeb5..cbdde5d2976 100644
--- a/src/mongo/dbtests/updatetests.cpp
+++ b/src/mongo/dbtests/updatetests.cpp
@@ -2030,7 +2030,9 @@ namespace UpdateTests {
add< basic::unset >();
add< basic::setswitchint >();
}
- } myall;
+ };
+
+ SuiteInstance<All> myall;
} // namespace UpdateTests
diff --git a/src/mongo/unittest/unittest.cpp b/src/mongo/unittest/unittest.cpp
index 030014094b3..be34f4207b0 100644
--- a/src/mongo/unittest/unittest.cpp
+++ b/src/mongo/unittest/unittest.cpp
@@ -52,7 +52,8 @@ namespace mongo {
namespace {
logger::MessageLogDomain* unittestOutput =
logger::globalLogManager()->getNamedDomain("unittest");
- typedef std::map<std::string, Suite*> SuiteMap;
+
+ typedef std::map<std::string, boost::shared_ptr<Suite> > SuiteMap;
inline SuiteMap& _allSuites() {
static SuiteMap allSuites;
@@ -188,7 +189,7 @@ namespace {
Suite::~Suite() {}
void Suite::add(const std::string& name, const TestFunction& testFn) {
- _tests.push_back(new TestHolder(name, testFn));
+ _tests.push_back(boost::shared_ptr<TestHolder>(new TestHolder(name, testFn)));
}
Result * Suite::run( const std::string& filter, int runsPerTest ) {
@@ -201,8 +202,8 @@ namespace {
Result * r = new Result( _name );
Result::cur = r;
- for ( std::vector<TestHolder*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ) {
- TestHolder* tc = *i;
+ for ( std::vector<boost::shared_ptr<TestHolder>>::iterator i=_tests.begin(); i!=_tests.end(); i++ ) {
+ boost::shared_ptr<TestHolder>& tc = *i;
if ( filter.size() && tc->getName().find( filter ) == std::string::npos ) {
LOG(1) << "\t skipping test: " << tc->getName() << " because doesn't match filter" << std::endl;
continue;
@@ -282,7 +283,7 @@ namespace {
for ( std::vector<std::string>::iterator i=torun.begin(); i!=torun.end(); i++ ) {
std::string name = *i;
- Suite* s = _allSuites()[name];
+ boost::shared_ptr<Suite>& s = _allSuites()[name];
fassert( 16145, s );
log() << "going to run suite: " << name << std::endl;
@@ -300,6 +301,7 @@ namespace {
Result totals ("TOTALS");
std::vector<std::string> failedSuites;
+ Result::cur = NULL;
for ( std::vector<Result*>::iterator i=results.begin(); i!=results.end(); i++ ) {
Result* r = *i;
log() << r->toString();
@@ -317,6 +319,8 @@ namespace {
}
asserts += r->_asserts;
millis += r->_millis;
+
+ delete r;
}
totals._tests = tests;
@@ -344,16 +348,19 @@ namespace {
}
void Suite::registerSuite( const std::string& name , Suite* s ) {
- Suite*& m = _allSuites()[name];
- fassert( 10162, ! m );
- m = s;
+ boost::shared_ptr<Suite>& m = _allSuites()[name];
+ fassert( 10162, !m );
+ m.reset(s);
}
Suite* Suite::getSuite(const std::string& name) {
- Suite* result = _allSuites()[name];
- if (!result)
- result = new Suite(name); // Suites are self-registering.
- return result;
+ boost::shared_ptr<Suite>& result = _allSuites()[name];
+ if (!result) {
+ // Suites are self-registering.
+ new Suite(name);
+ }
+ invariant(result);
+ return result.get();
}
void Suite::setupTests() {}
diff --git a/src/mongo/unittest/unittest.h b/src/mongo/unittest/unittest.h
index 374b6674e90..bee0d6514e0 100644
--- a/src/mongo/unittest/unittest.h
+++ b/src/mongo/unittest/unittest.h
@@ -359,7 +359,8 @@ namespace mongo {
virtual void setupTests();
private:
- typedef std::vector<TestHolder *> TestHolderList;
+ // TODO(C++11): Make this hold unique_ptrs.
+ typedef std::vector< boost::shared_ptr<TestHolder> > TestHolderList;
template <typename T>
static void runTestObject() {
@@ -380,6 +381,20 @@ namespace mongo {
void registerSuite( const std::string& name , Suite* s );
};
+ // A type that makes it easy to declare a self registering suite for old style test
+ // declarations. Suites are self registering so this is *not* a memory leak.
+ template<typename T>
+ struct SuiteInstance {
+ SuiteInstance() {
+ new T;
+ }
+
+ template<typename U>
+ SuiteInstance(const U& u) {
+ new T(u);
+ }
+ };
+
/**
* Exception thrown when a test assertion fails.
*