gapi_util_tests.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2018 Intel Corporation
  6. #include <type_traits>
  7. #include "test_precomp.hpp"
  8. #include <opencv2/gapi/gtype_traits.hpp>
  9. #include <opencv2/gapi/util/util.hpp>
  10. namespace cv
  11. {
  12. struct Own {};
  13. namespace gapi
  14. {
  15. namespace own
  16. {
  17. struct ConvertibleToOwn{};
  18. struct NotConvertibleToOwn{};
  19. } // own
  20. } // gapi
  21. } // cv
  22. struct NoGhape {};
  23. struct HasGShape {
  24. static constexpr cv::GShape shape = cv::GShape::GFRAME;
  25. };
  26. struct MimicGShape {
  27. static constexpr int shape = 0;
  28. };
  29. #define DISALLOWED_LIST cv::gapi::own::NotConvertibleToOwn
  30. namespace opencv_test
  31. {
  32. TEST(GAPIUtil, AllSatisfy)
  33. {
  34. static_assert(true == cv::detail::all_satisfy<std::is_integral, long, int, char>::value,
  35. "[long, int, char] are all integral types");
  36. static_assert(true == cv::detail::all_satisfy<std::is_integral, char>::value,
  37. "char is an integral type");
  38. static_assert(false == cv::detail::all_satisfy<std::is_integral, float, int, char>::value,
  39. "[float, int, char] are NOT all integral types");
  40. static_assert(false == cv::detail::all_satisfy<std::is_integral, int, char, float>::value,
  41. "[int, char, float] are NOT all integral types");
  42. static_assert(false == cv::detail::all_satisfy<std::is_integral, float>::value,
  43. "float is not an integral types");
  44. }
  45. TEST(GAPIUtil, AllButLast)
  46. {
  47. using test1 = cv::detail::all_but_last<long, int, float>::type;
  48. static_assert(true == cv::detail::all_satisfy<std::is_integral, test1>::value,
  49. "[long, int] are all integral types (float skipped)");
  50. using test2 = cv::detail::all_but_last<int, float, char>::type;
  51. static_assert(false == cv::detail::all_satisfy<std::is_integral, test2>::value,
  52. "[int, float] are NOT all integral types");
  53. }
  54. TEST(GAPIUtil, GShaped)
  55. {
  56. static_assert(!cv::detail::has_gshape<NoGhape>::value, "NoGhape hasn't got any shape");
  57. static_assert(cv::detail::has_gshape<HasGShape>::value, "HasGShape has got GShape shape");
  58. static_assert(!cv::detail::has_gshape<MimicGShape>::value, "MimicGShape hasn't got right shape");
  59. }
  60. TEST(GAPIUtil, GTypeList)
  61. {
  62. static_assert(cv::detail::contains<cv::gapi::own::NotConvertibleToOwn, GAPI_OWN_TYPES_LIST, DISALLOWED_LIST>::value, "NotConvertibleToOwn is in denial list");
  63. static_assert(!cv::detail::contains<cv::gapi::own::ConvertibleToOwn>::value, "ConvertibleToOwn is not in empty denial list");
  64. static_assert(!cv::detail::contains<cv::gapi::own::ConvertibleToOwn, GAPI_OWN_TYPES_LIST, DISALLOWED_LIST>::value, "ConvertibleToOwn is not in denial list");
  65. }
  66. } // namespace opencv_test