traits_bag_unittest.nc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2018 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. // This is a "No Compile Test" suite.
  5. // http://dev.chromium.org/developers/testing/no-compile-tests
  6. #include "base/traits_bag.h"
  7. namespace base {
  8. enum class RequiredTrait {
  9. A,
  10. B,
  11. C
  12. };
  13. struct BooleanTrait {};
  14. struct NotAValidTrait {};
  15. struct TestTraits {
  16. // List of traits that are valid inputs for the constructor below.
  17. struct ValidTrait {
  18. ValidTrait(RequiredTrait);
  19. ValidTrait(BooleanTrait);
  20. };
  21. template <class... ArgTypes,
  22. class CheckArgumentsAreValid = std::enable_if_t<
  23. trait_helpers::AreValidTraits<ValidTrait, ArgTypes...>::value>>
  24. constexpr TestTraits(ArgTypes... args)
  25. : required_trait(trait_helpers::GetEnum<RequiredTrait>(args...)),
  26. boolean_trait(trait_helpers::HasTrait<BooleanTrait, ArgTypes...>()) {}
  27. const RequiredTrait required_trait;
  28. const bool boolean_trait;
  29. };
  30. #if defined(NCTEST_TRAITS_BAG_REQUIRED_TRAIT_NOT_SET) // [r"The traits bag is missing a required trait."]
  31. constexpr TestTraits traits = {};
  32. #elif defined(NCTEST_TRAITS_BAG_INVALID_TRAIT) // [r"no matching constructor for initialization of 'const TestTraits'"]
  33. constexpr TestTraits traits = {RequiredTrait::A, NotAValidTrait{}};
  34. #elif defined(NCTEST_TASK_TRAITS_MULTIPLE_REQUIRED_TRAIT) // [r"The traits bag contains multiple traits of the same type."]
  35. constexpr TestTraits traits = {RequiredTrait::A, RequiredTrait::B};
  36. #elif defined(NCTEST_TASK_TRAITS_REDUNDANT_BOOLEAN_TRAIT) // [r"The traits bag contains multiple traits of the same type."]
  37. constexpr TestTraits traits = {RequiredTrait::A, BooleanTrait(),
  38. BooleanTrait()};
  39. #endif
  40. } // namespace base