1 | /* |
2 | * Copyright 2018-present Facebook, Inc. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | |
17 | #include <folly/detail/StaticSingletonManager.h> |
18 | |
19 | #include <folly/portability/GTest.h> |
20 | |
21 | namespace folly { |
22 | namespace detail { |
23 | |
24 | extern "C" int* check() { |
25 | return &createGlobal<int, void>(); |
26 | } |
27 | |
28 | struct StaticSingletonManagerTest : public testing::Test {}; |
29 | |
30 | template <typename T> |
31 | struct Tag {}; |
32 | |
33 | template <int I> |
34 | using Int = std::integral_constant<int, I>; |
35 | |
36 | TEST_F(StaticSingletonManagerTest, example) { |
37 | using T = std::integral_constant<int, 3>; |
38 | |
39 | auto& i = createGlobal<T, Tag<char>>(); |
40 | EXPECT_EQ(T::value, i); |
41 | |
42 | auto& j = createGlobal<T, Tag<char>>(); |
43 | EXPECT_EQ(&i, &j); |
44 | EXPECT_EQ(T::value, j); |
45 | |
46 | auto& k = createGlobal<T, Tag<char*>>(); |
47 | EXPECT_NE(&i, &k); |
48 | EXPECT_EQ(T::value, k); |
49 | } |
50 | |
51 | } // namespace detail |
52 | } // namespace folly |
53 | |