gapi_compile_args_tests.cpp 2.0 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) 2020 Intel Corporation
  6. #include "test_precomp.hpp"
  7. namespace opencv_test
  8. {
  9. struct CustomArg
  10. {
  11. int number;
  12. };
  13. }
  14. namespace cv
  15. {
  16. namespace detail
  17. {
  18. template<> struct CompileArgTag<opencv_test::CustomArg>
  19. {
  20. static const char* tag() { return "org.opencv.test.custom_arg"; }
  21. };
  22. }
  23. }
  24. namespace opencv_test
  25. {
  26. namespace
  27. {
  28. G_TYPED_KERNEL(GTestOp, <GMat(GMat)>, "org.opencv.test.test_op")
  29. {
  30. static GMatDesc outMeta(GMatDesc in) { return in; }
  31. };
  32. GAPI_OCV_KERNEL(GOCVTestOp, GTestOp)
  33. {
  34. static void run(const cv::Mat &/* in */, cv::Mat &/* out */) { }
  35. };
  36. } // anonymous namespace
  37. TEST(GetCompileArgTest, PredefinedArgs)
  38. {
  39. cv::GKernelPackage pkg = cv::gapi::kernels<GOCVTestOp>();
  40. cv::GCompileArg arg0 { pkg },
  41. arg1 { cv::gapi::use_only { pkg } },
  42. arg2 { cv::graph_dump_path { "fake_path" } };
  43. GCompileArgs compArgs { arg0, arg1, arg2 };
  44. auto kernelPkgOpt = cv::gapi::getCompileArg<cv::GKernelPackage>(compArgs);
  45. GAPI_Assert(kernelPkgOpt.has_value());
  46. EXPECT_NO_THROW(kernelPkgOpt.value().lookup("org.opencv.test.test_op"));
  47. auto hasUseOnlyOpt = cv::gapi::getCompileArg<cv::gapi::use_only>(compArgs);
  48. GAPI_Assert(hasUseOnlyOpt.has_value());
  49. EXPECT_NO_THROW(hasUseOnlyOpt.value().pkg.lookup("org.opencv.test.test_op"));
  50. auto dumpInfoOpt = cv::gapi::getCompileArg<cv::graph_dump_path>(compArgs);
  51. GAPI_Assert(dumpInfoOpt.has_value());
  52. EXPECT_EQ("fake_path", dumpInfoOpt.value().m_dump_path);
  53. }
  54. TEST(GetCompileArg, CustomArgs)
  55. {;
  56. cv::GCompileArgs compArgs{ GCompileArg { CustomArg { 7 } } };
  57. auto customArgOpt = cv::gapi::getCompileArg<CustomArg>(compArgs);
  58. GAPI_Assert(customArgOpt.has_value());
  59. EXPECT_EQ(7, customArgOpt.value().number);
  60. }
  61. } // namespace opencv_test