Update providedCiphersStr_ in one place.
[folly.git] / folly / io / async / test / DestructorCheckTest.cpp
1 /*
2  * Copyright 2017 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/Memory.h>
18 #include <folly/io/async/DestructorCheck.h>
19 #include <folly/portability/GTest.h>
20
21 using namespace folly;
22 using namespace testing;
23
24 class Derived : public DestructorCheck { };
25
26 TEST(DestructorCheckTest, WithoutGuard) {
27   Derived d;
28 }
29
30 TEST(DestructorCheckTest, SingleGuard) {
31   Derived d;
32   Derived::Safety s(d);
33   ASSERT_FALSE(s.destroyed());
34 }
35
36 TEST(DestructorCheckTest, SingleGuardDestroyed) {
37   auto d = std::make_unique<Derived>();
38   Derived::Safety s(*d);
39   ASSERT_FALSE(s.destroyed());
40   d.reset();
41   ASSERT_TRUE(s.destroyed());
42 }
43
44 TEST(DestructorCheckTest, MultipleGuards) {
45   Derived d;
46   auto s1 = std::make_unique<Derived::Safety>(d);
47   auto s2 = std::make_unique<Derived::Safety>(d);
48   auto s3 = std::make_unique<Derived::Safety>(d);
49
50   // Remove the middle of the list.
51   ASSERT_FALSE(s2->destroyed());
52   s2.reset();
53
54   // Add in a link after a removal has occurred.
55   auto s4 = std::make_unique<Derived::Safety>(d);
56
57   // Remove the beginning of the list.
58   ASSERT_FALSE(s1->destroyed());
59   s1.reset();
60   // Remove the end of the list.
61   ASSERT_FALSE(s4->destroyed());
62   s4.reset();
63   // Remove the last remaining of the list.
64   ASSERT_FALSE(s3->destroyed());
65   s3.reset();
66 }
67
68 TEST(DestructorCheckTest, MultipleGuardsDestroyed) {
69   auto d = std::make_unique<Derived>();
70   auto s1 = std::make_unique<Derived::Safety>(*d);
71   auto s2 = std::make_unique<Derived::Safety>(*d);
72   auto s3 = std::make_unique<Derived::Safety>(*d);
73   auto s4 = std::make_unique<Derived::Safety>(*d);
74
75   // Remove something from the list.
76   ASSERT_FALSE(s2->destroyed());
77   s2.reset();
78
79   ASSERT_FALSE(s1->destroyed());
80   ASSERT_FALSE(s3->destroyed());
81   ASSERT_FALSE(s4->destroyed());
82
83   d.reset();
84
85   ASSERT_TRUE(s1->destroyed());
86   ASSERT_TRUE(s3->destroyed());
87   ASSERT_TRUE(s4->destroyed());
88 }