1 // Copyright 2019 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef PHMAP_PRIV_UNORDERED_SET_MEMBERS_TEST_H_
16 #define PHMAP_PRIV_UNORDERED_SET_MEMBERS_TEST_H_
17
18 #include <type_traits>
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21
22 namespace phmap {
23 namespace priv {
24
25 template <class UnordSet>
26 class MembersTest : public ::testing::Test {};
27
28 TYPED_TEST_SUITE_P(MembersTest);
29
30 template <typename T>
UseType()31 void UseType() {}
32
TYPED_TEST_P(MembersTest,Typedefs)33 TYPED_TEST_P(MembersTest, Typedefs) {
34 EXPECT_TRUE((std::is_same<typename TypeParam::key_type,
35 typename TypeParam::value_type>()));
36 EXPECT_TRUE((phmap::conjunction<
37 phmap::negation<std::is_signed<typename TypeParam::size_type>>,
38 std::is_integral<typename TypeParam::size_type>>()));
39 EXPECT_TRUE((phmap::conjunction<
40 std::is_signed<typename TypeParam::difference_type>,
41 std::is_integral<typename TypeParam::difference_type>>()));
42 EXPECT_TRUE((std::is_convertible<
43 decltype(std::declval<const typename TypeParam::hasher&>()(
44 std::declval<const typename TypeParam::key_type&>())),
45 size_t>()));
46 EXPECT_TRUE((std::is_convertible<
47 decltype(std::declval<const typename TypeParam::key_equal&>()(
48 std::declval<const typename TypeParam::key_type&>(),
49 std::declval<const typename TypeParam::key_type&>())),
50 bool>()));
51 EXPECT_TRUE((std::is_same<typename TypeParam::allocator_type::value_type,
52 typename TypeParam::value_type>()));
53 EXPECT_TRUE((std::is_same<typename TypeParam::value_type&,
54 typename TypeParam::reference>()));
55 EXPECT_TRUE((std::is_same<const typename TypeParam::value_type&,
56 typename TypeParam::const_reference>()));
57 EXPECT_TRUE((std::is_same<typename std::allocator_traits<
58 typename TypeParam::allocator_type>::pointer,
59 typename TypeParam::pointer>()));
60 EXPECT_TRUE(
61 (std::is_same<typename std::allocator_traits<
62 typename TypeParam::allocator_type>::const_pointer,
63 typename TypeParam::const_pointer>()));
64 }
65
TYPED_TEST_P(MembersTest,SimpleFunctions)66 TYPED_TEST_P(MembersTest, SimpleFunctions) {
67 EXPECT_GT(TypeParam().max_size(), 0);
68 }
69
TYPED_TEST_P(MembersTest,BeginEnd)70 TYPED_TEST_P(MembersTest, BeginEnd) {
71 TypeParam t = {typename TypeParam::value_type{}};
72 EXPECT_EQ(t.begin(), t.cbegin());
73 EXPECT_EQ(t.end(), t.cend());
74 EXPECT_NE(t.begin(), t.end());
75 EXPECT_NE(t.cbegin(), t.cend());
76 }
77
78 REGISTER_TYPED_TEST_SUITE_P(MembersTest, Typedefs, SimpleFunctions, BeginEnd);
79
80 } // namespace priv
81 } // namespace phmap
82
83 #endif // PHMAP_PRIV_UNORDERED_SET_MEMBERS_TEST_H_
84