Alex Clarke | 8906d05 | 2019-03-13 14:58:04 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/parameter_pack.h" |
| 6 | |
| 7 | #include "testing/gtest/include/gtest/gtest.h" |
| 8 | |
| 9 | namespace base { |
| 10 | |
| 11 | TEST(ParameterPack, AnyOf) { |
| 12 | static_assert(any_of({true, true, true}), ""); |
| 13 | static_assert(any_of({false, false, true, false}), ""); |
| 14 | static_assert(!any_of({false}), ""); |
| 15 | static_assert(!any_of({false, false, false}), ""); |
| 16 | } |
| 17 | |
| 18 | TEST(ParameterPack, AllOf) { |
| 19 | static_assert(all_of({true, true, true}), ""); |
| 20 | static_assert(!all_of({true, true, true, false}), ""); |
| 21 | static_assert(!all_of({false}), ""); |
| 22 | static_assert(!all_of({false, false}), ""); |
| 23 | } |
| 24 | |
| 25 | TEST(ParameterPack, Count) { |
| 26 | static_assert(count({1, 2, 2, 2, 2, 2, 3}, 2) == 5u, ""); |
| 27 | } |
| 28 | |
| 29 | TEST(ParameterPack, HasType) { |
| 30 | static_assert(ParameterPack<int, float, bool>::HasType<int>(), ""); |
| 31 | static_assert(ParameterPack<int, float, bool>::HasType<bool>(), ""); |
| 32 | static_assert(ParameterPack<int, float, bool>::HasType<bool>(), ""); |
| 33 | static_assert(!ParameterPack<int, float, bool>::HasType<void*>(), ""); |
| 34 | } |
| 35 | |
| 36 | TEST(ParameterPack, OnlyHasType) { |
| 37 | static_assert(ParameterPack<int, int>::OnlyHasType<int>(), ""); |
| 38 | static_assert(ParameterPack<int, int, int, int>::OnlyHasType<int>(), ""); |
| 39 | static_assert(!ParameterPack<int, bool>::OnlyHasType<int>(), ""); |
| 40 | static_assert(!ParameterPack<int, int, bool, int>::OnlyHasType<int>(), ""); |
| 41 | static_assert(!ParameterPack<int, int, int>::OnlyHasType<bool>(), ""); |
| 42 | } |
| 43 | |
| 44 | TEST(ParameterPack, IsUniqueInPack) { |
| 45 | static_assert(ParameterPack<int, float, bool>::IsUniqueInPack<int>(), ""); |
| 46 | static_assert(!ParameterPack<int, int, bool>::IsUniqueInPack<int>(), ""); |
| 47 | } |
| 48 | |
| 49 | TEST(ParameterPack, IndexInPack) { |
| 50 | static_assert(ParameterPack<int, float, bool>::IndexInPack<int>() == 0u, ""); |
| 51 | static_assert(ParameterPack<int, float, bool>::IndexInPack<float>() == 1u, |
| 52 | ""); |
| 53 | static_assert(ParameterPack<int, float, bool>::IndexInPack<bool>() == 2u, ""); |
| 54 | static_assert( |
| 55 | ParameterPack<int, float, bool>::IndexInPack<void*>() == pack_npos, ""); |
| 56 | } |
| 57 | |
| 58 | TEST(ParameterPack, NthType) { |
| 59 | static_assert( |
| 60 | std::is_same<int, ParameterPack<int, float, bool>::NthType<0>>::value, |
| 61 | ""); |
| 62 | static_assert( |
| 63 | std::is_same<float, ParameterPack<int, float, bool>::NthType<1>>::value, |
| 64 | ""); |
| 65 | static_assert( |
| 66 | std::is_same<bool, ParameterPack<int, float, bool>::NthType<2>>::value, |
| 67 | ""); |
| 68 | } |
| 69 | |
| 70 | TEST(ParameterPack, IsAllSameType) { |
| 71 | static_assert(ParameterPack<int>::IsAllSameType(), ""); |
| 72 | static_assert(ParameterPack<int, int, int>::IsAllSameType(), ""); |
| 73 | static_assert(!ParameterPack<int, int, int, int, bool>::IsAllSameType(), ""); |
| 74 | } |
| 75 | |
| 76 | } // namespace base |