OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 SingletonNoLeak(&CallbackNoLeak); | 216 SingletonNoLeak(&CallbackNoLeak); |
217 SingletonLeak(&CallbackLeak); | 217 SingletonLeak(&CallbackLeak); |
218 SingletonStatic(&CallbackStatic); | 218 SingletonStatic(&CallbackStatic); |
219 static_singleton = GetStaticSingleton(); | 219 static_singleton = GetStaticSingleton(); |
220 leaky_singleton = GetLeakySingleton(); | 220 leaky_singleton = GetLeakySingleton(); |
221 EXPECT_TRUE(leaky_singleton); | 221 EXPECT_TRUE(leaky_singleton); |
222 } | 222 } |
223 | 223 |
224 // Verify that only the expected callback has been called. | 224 // Verify that only the expected callback has been called. |
225 VerifiesCallbacks(); | 225 VerifiesCallbacks(); |
226 // Delete the leaky singleton. It is interesting to note that Purify does | 226 // Delete the leaky singleton. |
227 // *not* detect the leak when this call is commented out. :( | |
228 DeleteLeakySingleton(); | 227 DeleteLeakySingleton(); |
229 | 228 |
230 // The static singleton can't be acquired post-atexit. | 229 // The static singleton can't be acquired post-atexit. |
231 EXPECT_EQ(NULL, GetStaticSingleton()); | 230 EXPECT_EQ(NULL, GetStaticSingleton()); |
232 | 231 |
233 { | 232 { |
234 base::ShadowingAtExitManager sem; | 233 base::ShadowingAtExitManager sem; |
235 // Verifiy that the variables were reset. | 234 // Verifiy that the variables were reset. |
236 { | 235 { |
237 singleton_int = SingletonInt(); | 236 singleton_int = SingletonInt(); |
238 EXPECT_EQ(*singleton_int, 0); | 237 EXPECT_EQ(*singleton_int, 0); |
239 } | 238 } |
240 { | 239 { |
241 singleton_int_5 = SingletonInt5(); | 240 singleton_int_5 = SingletonInt5(); |
242 EXPECT_EQ(*singleton_int_5, 5); | 241 EXPECT_EQ(*singleton_int_5, 5); |
243 } | 242 } |
244 { | 243 { |
245 // Resurrect the static singleton, and assert that it | 244 // Resurrect the static singleton, and assert that it |
246 // still points to the same (static) memory. | 245 // still points to the same (static) memory. |
247 CallbackSingletonWithStaticTrait::Trait::Resurrect(); | 246 CallbackSingletonWithStaticTrait::Trait::Resurrect(); |
248 EXPECT_EQ(GetStaticSingleton(), static_singleton); | 247 EXPECT_EQ(GetStaticSingleton(), static_singleton); |
249 } | 248 } |
250 } | 249 } |
251 // The leaky singleton shouldn't leak since SingletonLeak has not been called. | 250 // The leaky singleton shouldn't leak since SingletonLeak has not been called. |
252 VerifiesCallbacksNotCalled(); | 251 VerifiesCallbacksNotCalled(); |
253 } | 252 } |
OLD | NEW |