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 ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MEMBERS_TEST_H_
16 #define ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MEMBERS_TEST_H_
17
18 #include <type_traits>
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 #include "absl/meta/type_traits.h"
22
23 namespace absl {
24 ABSL_NAMESPACE_BEGIN
25 namespace container_internal {
26
27 template <class UnordMap>
28 class MembersTest : public ::testing::Test {};
29
30 TYPED_TEST_SUITE_P(MembersTest);
31
32 template <typename T>
UseType()33 void UseType() {}
34
TYPED_TEST_P(MembersTest,Typedefs)35 TYPED_TEST_P(MembersTest, Typedefs) {
36 EXPECT_TRUE((std::is_same<std::pair<const typename TypeParam::key_type,
37 typename TypeParam::mapped_type>,
38 typename TypeParam::value_type>()));
39 EXPECT_TRUE((absl::conjunction<
40 absl::negation<std::is_signed<typename TypeParam::size_type>>,
41 std::is_integral<typename TypeParam::size_type>>()));
42 EXPECT_TRUE((absl::conjunction<
43 std::is_signed<typename TypeParam::difference_type>,
44 std::is_integral<typename TypeParam::difference_type>>()));
45 EXPECT_TRUE((std::is_convertible<
46 decltype(std::declval<const typename TypeParam::hasher&>()(
47 std::declval<const typename TypeParam::key_type&>())),
48 size_t>()));
49 EXPECT_TRUE((std::is_convertible<
50 decltype(std::declval<const typename TypeParam::key_equal&>()(
51 std::declval<const typename TypeParam::key_type&>(),
52 std::declval<const typename TypeParam::key_type&>())),
53 bool>()));
54 EXPECT_TRUE((std::is_same<typename TypeParam::allocator_type::value_type,
55 typename TypeParam::value_type>()));
56 EXPECT_TRUE((std::is_same<typename TypeParam::value_type&,
57 typename TypeParam::reference>()));
58 EXPECT_TRUE((std::is_same<const typename TypeParam::value_type&,
59 typename TypeParam::const_reference>()));
60 EXPECT_TRUE((std::is_same<typename std::allocator_traits<
61 typename TypeParam::allocator_type>::pointer,
62 typename TypeParam::pointer>()));
63 EXPECT_TRUE(
64 (std::is_same<typename std::allocator_traits<
65 typename TypeParam::allocator_type>::const_pointer,
66 typename TypeParam::const_pointer>()));
67 }
68
TYPED_TEST_P(MembersTest,SimpleFunctions)69 TYPED_TEST_P(MembersTest, SimpleFunctions) {
70 EXPECT_GT(TypeParam().max_size(), 0);
71 }
72
TYPED_TEST_P(MembersTest,BeginEnd)73 TYPED_TEST_P(MembersTest, BeginEnd) {
74 TypeParam t = {typename TypeParam::value_type{}};
75 EXPECT_EQ(t.begin(), t.cbegin());
76 EXPECT_EQ(t.end(), t.cend());
77 EXPECT_NE(t.begin(), t.end());
78 EXPECT_NE(t.cbegin(), t.cend());
79 }
80
81 REGISTER_TYPED_TEST_SUITE_P(MembersTest, Typedefs, SimpleFunctions, BeginEnd);
82
83 } // namespace container_internal
84 ABSL_NAMESPACE_END
85 } // namespace absl
86
87 #endif // ABSL_CONTAINER_INTERNAL_UNORDERED_MAP_MEMBERS_TEST_H_
88