Index: base/lazy_instance_unittest.cc |
diff --git a/base/lazy_instance_unittest.cc b/base/lazy_instance_unittest.cc |
index d55f66489389a30f99c67ef90e15397633c8db62..17313818ebb064f89d92b26eee3d949a0851aa76 100644 |
--- a/base/lazy_instance_unittest.cc |
+++ b/base/lazy_instance_unittest.cc |
@@ -95,3 +95,46 @@ TEST(LazyInstanceTest, ConstructorThreadSafety) { |
EXPECT_EQ(1, SlowConstructor::constructed); |
} |
} |
+ |
+namespace { |
+ |
+// DeleteLogger is an object which sets a flag when it's destroyed. |
+// It accepts a bool* and sets the bool to true when the dtor runs. |
+class DeleteLogger { |
+ public: |
+ DeleteLogger() : deleted_(NULL) {} |
+ ~DeleteLogger() { *deleted_ = true; } |
+ |
+ void SetDeletedPtr(bool* deleted) { |
+ deleted_ = deleted; |
+ } |
+ |
+ private: |
+ bool* deleted_; |
+}; |
+ |
+} // anonymous namespace |
willchan no longer on Chromium
2010/10/21 20:26:50
I actually don't understand why this whole file is
|
+ |
+TEST(LazyInstanceTest, LeakyLazyInstance) { |
+ // Check that using a plain LazyInstance causes the dtor to run |
+ // when the AtExitManager finishes. |
+ bool deleted1 = false; |
+ { |
+ base::ShadowingAtExitManager shadow; |
+ static base::LazyInstance<DeleteLogger> test(base::LINKER_INITIALIZED); |
+ test.Get().SetDeletedPtr(&deleted1); |
+ } |
+ EXPECT_TRUE(deleted1); |
+ |
+ // Check that using a *leaky* LazyInstance makes the dtor not run |
+ // when the AtExitManager finishes. |
+ bool deleted2 = false; |
+ { |
+ base::ShadowingAtExitManager shadow; |
+ static base::LazyInstance<DeleteLogger, |
+ base::LeakyLazyInstanceTraits<DeleteLogger> > |
+ test(base::LINKER_INITIALIZED); |
+ test.Get().SetDeletedPtr(&deleted2); |
+ } |
+ EXPECT_FALSE(deleted2); |
+} |