1/*
2 * Copyright 2017-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/lang/ColdClass.h>
18
19#include <folly/portability/GTest.h>
20#include <type_traits>
21
22using folly::ColdClass;
23
24template <class TestClass>
25static void validateInheritedClass() {
26 // The only verifiable property of ColdClass is that it must not disrupt the
27 // default constructor/destructor, default copy/move constructors and default
28 // copy/move assignment operators when a class derives from it.
29 EXPECT_TRUE(std::is_nothrow_default_constructible<TestClass>::value);
30#if !defined(__GLIBCXX__) || __GNUC__ >= 5
31 EXPECT_TRUE(std::is_trivially_copy_constructible<TestClass>::value);
32 EXPECT_TRUE(std::is_trivially_move_constructible<TestClass>::value);
33 EXPECT_TRUE(std::is_trivially_copy_assignable<TestClass>::value);
34 EXPECT_TRUE(std::is_trivially_move_assignable<TestClass>::value);
35#endif
36 EXPECT_TRUE(std::is_nothrow_copy_constructible<TestClass>::value);
37 EXPECT_TRUE(std::is_nothrow_move_constructible<TestClass>::value);
38 EXPECT_TRUE(std::is_nothrow_copy_assignable<TestClass>::value);
39 EXPECT_TRUE(std::is_nothrow_move_assignable<TestClass>::value);
40 EXPECT_TRUE(std::is_trivially_destructible<TestClass>::value);
41}
42
43TEST(ColdClassTest, publicInheritance) {
44 struct TestPublic : ColdClass {};
45 validateInheritedClass<TestPublic>();
46}
47
48TEST(ColdClassTest, protectedInheritance) {
49 // Same again, but protected inheritance. Should make no difference.
50 class TestProtected : protected ColdClass {};
51 validateInheritedClass<TestProtected>();
52}
53
54TEST(ColdClassTest, privateInheritance) {
55 // Same again, but private inheritance. Should make no difference.
56 class TestPrivate : ColdClass {};
57 validateInheritedClass<TestPrivate>();
58}
59