gapi_int_gmetaarg_test.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 "../test_precomp.hpp"
  7. #include "api/gcomputation_priv.hpp"
  8. namespace opencv_test
  9. {
  10. TEST(GMetaArg, Traits_Is_Positive)
  11. {
  12. using namespace cv::detail;
  13. static_assert(is_meta_descr<cv::GScalarDesc>::value,
  14. "GScalarDesc is a meta description type");
  15. static_assert(is_meta_descr<cv::GMatDesc>::value,
  16. "GMatDesc is a meta description type");
  17. }
  18. TEST(GMetaArg, Traits_Is_Negative)
  19. {
  20. using namespace cv::detail;
  21. static_assert(!is_meta_descr<cv::GCompileArgs>::value,
  22. "GCompileArgs is NOT a meta description type");
  23. static_assert(!is_meta_descr<int>::value,
  24. "int is NOT a meta description type");
  25. static_assert(!is_meta_descr<std::string>::value,
  26. "str::string is NOT a meta description type");
  27. }
  28. TEST(GMetaArg, Traits_Are_EntireList_Positive)
  29. {
  30. using namespace cv::detail;
  31. static_assert(are_meta_descrs<cv::GScalarDesc>::value,
  32. "GScalarDesc is a meta description type");
  33. static_assert(are_meta_descrs<cv::GMatDesc>::value,
  34. "GMatDesc is a meta description type");
  35. static_assert(are_meta_descrs<cv::GMatDesc, cv::GScalarDesc>::value,
  36. "Both GMatDesc and GScalarDesc are meta types");
  37. }
  38. TEST(GMetaArg, Traits_Are_EntireList_Negative)
  39. {
  40. using namespace cv::detail;
  41. static_assert(!are_meta_descrs<cv::GCompileArgs>::value,
  42. "GCompileArgs is NOT among meta types");
  43. static_assert(!are_meta_descrs<int, std::string>::value,
  44. "Both int and std::string is NOT among meta types");
  45. static_assert(!are_meta_descrs<cv::GMatDesc, cv::GScalarDesc, int>::value,
  46. "List of type is not valid for meta as there\'s int");
  47. static_assert(!are_meta_descrs<cv::GMatDesc, cv::GScalarDesc, cv::GCompileArgs>::value,
  48. "List of type is not valid for meta as there\'s GCompileArgs");
  49. }
  50. TEST(GMetaArg, Traits_Are_ButLast_Positive)
  51. {
  52. using namespace cv::detail;
  53. static_assert(are_meta_descrs_but_last<cv::GScalarDesc, int>::value,
  54. "List is valid (int is omitted)");
  55. static_assert(are_meta_descrs_but_last<cv::GMatDesc, cv::GScalarDesc, cv::GCompileArgs>::value,
  56. "List is valid (GCompileArgs are omitted)");
  57. }
  58. TEST(GMetaArg, Traits_Are_ButLast_Negative)
  59. {
  60. using namespace cv::detail;
  61. static_assert(!are_meta_descrs_but_last<int, std::string>::value,
  62. "Both int is NOT among meta types (std::string is omitted)");
  63. static_assert(!are_meta_descrs_but_last<cv::GMatDesc, cv::GScalarDesc, int, int>::value,
  64. "List of type is not valid for meta as there\'s two ints");
  65. static_assert(!are_meta_descrs_but_last<cv::GMatDesc, cv::GScalarDesc, cv::GCompileArgs, float>::value,
  66. "List of type is not valid for meta as there\'s GCompileArgs");
  67. }
  68. TEST(GMetaArg, Can_Get_Metas_From_Input_Run_Args)
  69. {
  70. cv::Mat m(3, 3, CV_8UC3);
  71. cv::Scalar s;
  72. std::vector<int> v;
  73. GMatDesc m_desc;
  74. GMetaArgs meta_args = descr_of(cv::gin(m, s, v));
  75. EXPECT_EQ(3u, meta_args.size());
  76. EXPECT_NO_THROW(m_desc = util::get<cv::GMatDesc>(meta_args[0]));
  77. EXPECT_NO_THROW(util::get<cv::GScalarDesc>(meta_args[1]));
  78. EXPECT_NO_THROW(util::get<cv::GArrayDesc>(meta_args[2]));
  79. EXPECT_EQ(CV_8U, m_desc.depth);
  80. EXPECT_EQ(3, m_desc.chan);
  81. EXPECT_EQ(cv::gapi::own::Size(3, 3), m_desc.size);
  82. }
  83. TEST(GMetaArg, Can_Get_Metas_From_Output_Run_Args)
  84. {
  85. cv::Mat m(3, 3, CV_8UC3);
  86. cv::Scalar s;
  87. std::vector<int> v;
  88. GMatDesc m_desc;
  89. GRunArgsP out_run_args = cv::gout(m, s, v);
  90. GMetaArg m_meta = descr_of(out_run_args[0]);
  91. GMetaArg s_meta = descr_of(out_run_args[1]);
  92. GMetaArg v_meta = descr_of(out_run_args[2]);
  93. EXPECT_NO_THROW(m_desc = util::get<cv::GMatDesc>(m_meta));
  94. EXPECT_NO_THROW(util::get<cv::GScalarDesc>(s_meta));
  95. EXPECT_NO_THROW(util::get<cv::GArrayDesc>(v_meta));
  96. EXPECT_EQ(CV_8U, m_desc.depth);
  97. EXPECT_EQ(3, m_desc.chan);
  98. EXPECT_EQ(cv::Size(3, 3), m_desc.size);
  99. }
  100. TEST(GMetaArg, Can_Describe_RunArg)
  101. {
  102. cv::Mat m(3, 3, CV_8UC3);
  103. cv::UMat um(3, 3, CV_8UC3);
  104. cv::Scalar s;
  105. cv::Scalar os;
  106. std::vector<int> v;
  107. GMetaArgs metas = {GMetaArg(descr_of(m)),
  108. GMetaArg(descr_of(um)),
  109. GMetaArg(descr_of(s)),
  110. GMetaArg(descr_of(os)),
  111. GMetaArg(descr_of(v))};
  112. auto in_run_args = cv::gin(m, um, s, os, v);
  113. for (size_t i = 0; i < metas.size(); i++) {
  114. EXPECT_TRUE(can_describe(metas[i], in_run_args[i]));
  115. }
  116. }
  117. TEST(GMetaArg, Can_Describe_RunArgs)
  118. {
  119. cv::Mat m(3, 3, CV_8UC3);
  120. cv::Scalar s;
  121. std::vector<int> v;
  122. GMetaArgs metas0 = {GMetaArg(descr_of(m)), GMetaArg(descr_of(s)), GMetaArg(descr_of(v))};
  123. auto in_run_args0 = cv::gin(m, s, v);
  124. EXPECT_TRUE(can_describe(metas0, in_run_args0));
  125. auto in_run_args01 = cv::gin(m, s);
  126. EXPECT_FALSE(can_describe(metas0, in_run_args01));
  127. }
  128. TEST(GMetaArg, Can_Describe_RunArgP)
  129. {
  130. cv::Mat m(3, 3, CV_8UC3);
  131. cv::UMat um(3, 3, CV_8UC3);
  132. cv::Scalar s;
  133. cv::Scalar os;
  134. std::vector<int> v;
  135. GMetaArgs metas = {GMetaArg(descr_of(m)),
  136. GMetaArg(descr_of(um)),
  137. GMetaArg(descr_of(s)),
  138. GMetaArg(descr_of(os)),
  139. GMetaArg(descr_of(v))};
  140. auto out_run_args = cv::gout(m, um, s, os, v);
  141. for (size_t i = 0; i < metas.size(); i++) {
  142. EXPECT_TRUE(can_describe(metas[i], out_run_args[i]));
  143. }
  144. }
  145. } // namespace opencv_test