diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-05-30 17:37:31 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-05-30 17:37:31 +0000 |
commit | ee2f195dd3e40f49698ca4dc2666ec09c770e80d (patch) | |
tree | 66fa9a69e5789356dfe844991e64bac9222f3a35 /unittests/Support/ManagedStatic.cpp | |
parent | ab44ce3d598882e51a25eb82eb7ae6308de85ae6 (diff) |
Diffstat (limited to 'unittests/Support/ManagedStatic.cpp')
-rw-r--r-- | unittests/Support/ManagedStatic.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/unittests/Support/ManagedStatic.cpp b/unittests/Support/ManagedStatic.cpp index 153884ba4298..4e2e93036a83 100644 --- a/unittests/Support/ManagedStatic.cpp +++ b/unittests/Support/ManagedStatic.cpp @@ -57,4 +57,45 @@ TEST(Initialize, MultipleThreads) { } #endif +namespace NestedStatics { +static ManagedStatic<int> Ms1; +struct Nest { + Nest() { + ++(*Ms1); + } + + ~Nest() { + assert(Ms1.isConstructed()); + ++(*Ms1); + } +}; +static ManagedStatic<Nest> Ms2; + +TEST(ManagedStaticTest, NestedStatics) { + EXPECT_FALSE(Ms1.isConstructed()); + EXPECT_FALSE(Ms2.isConstructed()); + + *Ms2; + EXPECT_TRUE(Ms1.isConstructed()); + EXPECT_TRUE(Ms2.isConstructed()); +} +} // namespace NestedStatics + +namespace CustomCreatorDeletor { +struct CustomCreate { + static void *call() { + void *Mem = std::malloc(sizeof(int)); + *((int *)Mem) = 42; + return Mem; + } +}; +struct CustomDelete { + static void call(void *P) { std::free(P); } +}; +static ManagedStatic<int, CustomCreate, CustomDelete> Custom; +TEST(ManagedStaticTest, CustomCreatorDeletor) { + EXPECT_EQ(42, *Custom); +} +} // namespace CustomCreatorDeletor + } // anonymous namespace |