parameter_pack_unittest.cc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include "base/parameter_pack.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. namespace base {
  7. TEST(ParameterPack, AnyOf) {
  8. static_assert(any_of({true, true, true}), "");
  9. static_assert(any_of({false, false, true, false}), "");
  10. static_assert(!any_of({false}), "");
  11. static_assert(!any_of({false, false, false}), "");
  12. }
  13. TEST(ParameterPack, AllOf) {
  14. static_assert(all_of({true, true, true}), "");
  15. static_assert(!all_of({true, true, true, false}), "");
  16. static_assert(!all_of({false}), "");
  17. static_assert(!all_of({false, false}), "");
  18. }
  19. TEST(ParameterPack, Count) {
  20. static_assert(count({1, 2, 2, 2, 2, 2, 3}, 2) == 5u, "");
  21. }
  22. TEST(ParameterPack, HasType) {
  23. static_assert(ParameterPack<int, float, bool>::HasType<int>(), "");
  24. static_assert(ParameterPack<int, float, bool>::HasType<bool>(), "");
  25. static_assert(ParameterPack<int, float, bool>::HasType<bool>(), "");
  26. static_assert(!ParameterPack<int, float, bool>::HasType<void*>(), "");
  27. }
  28. TEST(ParameterPack, OnlyHasType) {
  29. static_assert(ParameterPack<int, int>::OnlyHasType<int>(), "");
  30. static_assert(ParameterPack<int, int, int, int>::OnlyHasType<int>(), "");
  31. static_assert(!ParameterPack<int, bool>::OnlyHasType<int>(), "");
  32. static_assert(!ParameterPack<int, int, bool, int>::OnlyHasType<int>(), "");
  33. static_assert(!ParameterPack<int, int, int>::OnlyHasType<bool>(), "");
  34. }
  35. TEST(ParameterPack, IsUniqueInPack) {
  36. static_assert(ParameterPack<int, float, bool>::IsUniqueInPack<int>(), "");
  37. static_assert(!ParameterPack<int, int, bool>::IsUniqueInPack<int>(), "");
  38. }
  39. TEST(ParameterPack, IndexInPack) {
  40. static_assert(ParameterPack<int, float, bool>::IndexInPack<int>() == 0u, "");
  41. static_assert(ParameterPack<int, float, bool>::IndexInPack<float>() == 1u,
  42. "");
  43. static_assert(ParameterPack<int, float, bool>::IndexInPack<bool>() == 2u, "");
  44. static_assert(
  45. ParameterPack<int, float, bool>::IndexInPack<void*>() == pack_npos, "");
  46. }
  47. TEST(ParameterPack, NthType) {
  48. static_assert(
  49. std::is_same<int, ParameterPack<int, float, bool>::NthType<0>>::value,
  50. "");
  51. static_assert(
  52. std::is_same<float, ParameterPack<int, float, bool>::NthType<1>>::value,
  53. "");
  54. static_assert(
  55. std::is_same<bool, ParameterPack<int, float, bool>::NthType<2>>::value,
  56. "");
  57. }
  58. TEST(ParameterPack, IsAllSameType) {
  59. static_assert(ParameterPack<int>::IsAllSameType(), "");
  60. static_assert(ParameterPack<int, int, int>::IsAllSameType(), "");
  61. static_assert(!ParameterPack<int, int, int, int, bool>::IsAllSameType(), "");
  62. }
  63. } // namespace base