diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index a8467e3..d19daf5 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -336,6 +336,10 @@ TYPED_TEST(DocumentMove, MoveConstructorParseError) { EXPECT_EQ(c.GetErrorOffset(), error.Offset()); } +// This test does not properly use parsing, just for testing. +// It must call ClearStack() explicitly to prevent memory leak. +// But here we cannot as ClearStack() is private. +#if 0 TYPED_TEST(DocumentMove, MoveConstructorStack) { typedef TypeParam Allocator; typedef UTF8<> Encoding; @@ -360,6 +364,7 @@ TYPED_TEST(DocumentMove, MoveConstructorStack) { EXPECT_EQ(b.GetStackCapacity(), defaultCapacity); EXPECT_EQ(c.GetStackCapacity(), capacity); } +#endif TYPED_TEST(DocumentMove, MoveAssignment) { typedef TypeParam Allocator; @@ -428,6 +433,10 @@ TYPED_TEST(DocumentMove, MoveAssignmentParseError) { EXPECT_EQ(c.GetErrorOffset(), error.Offset()); } +// This test does not properly use parsing, just for testing. +// It must call ClearStack() explicitly to prevent memory leak. +// But here we cannot as ClearStack() is private. +#if 0 TYPED_TEST(DocumentMove, MoveAssignmentStack) { typedef TypeParam Allocator; typedef UTF8<> Encoding; @@ -454,6 +463,7 @@ TYPED_TEST(DocumentMove, MoveAssignmentStack) { EXPECT_EQ(b.GetStackCapacity(), defaultCapacity); EXPECT_EQ(c.GetStackCapacity(), capacity); } +#endif #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS diff --git a/test/unittest/unittest.cpp b/test/unittest/unittest.cpp index e92bc66..4604d9d 100644 --- a/test/unittest/unittest.cpp +++ b/test/unittest/unittest.cpp @@ -21,10 +21,20 @@ #include "unittest.h" int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + #if _MSC_VER - _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); + _CrtMemState memoryState = { 0 }; + _CrtMemCheckpoint(&memoryState); + //_CrtSetBreakAlloc(X); //void *testWhetherMemoryLeakDetectionWorks = malloc(1); #endif - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + + int ret = RUN_ALL_TESTS(); + +#if _MSC_VER + // Current gtest constantly leak 2 blocks at exit + _CrtMemDumpAllObjectsSince(&memoryState); +#endif + return ret; }