Blame view

3rdparty/opencv-4.5.4/modules/gapi/test/gapi_compile_args_tests.cpp 2.02 KB
f4334277   Hu Chunming   提交3rdparty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  // This file is part of OpenCV project.
  // It is subject to the license terms in the LICENSE file found in the top-level directory
  // of this distribution and at http://opencv.org/license.html.
  //
  // Copyright (C) 2020 Intel Corporation
  
  
  #include "test_precomp.hpp"
  
  namespace opencv_test
  {
      struct CustomArg
      {
          int number;
      };
  }
  
  namespace cv
  {
      namespace detail
      {
          template<> struct CompileArgTag<opencv_test::CustomArg>
          {
              static const char* tag() { return "org.opencv.test.custom_arg"; }
          };
      }
  }
  
  
  namespace opencv_test
  {
  namespace
  {
  G_TYPED_KERNEL(GTestOp, <GMat(GMat)>, "org.opencv.test.test_op")
  {
      static GMatDesc outMeta(GMatDesc in) { return in; }
  };
  
  GAPI_OCV_KERNEL(GOCVTestOp, GTestOp)
  {
      static void run(const cv::Mat &/* in */, cv::Mat &/* out */) { }
  };
  } // anonymous namespace
  
  TEST(GetCompileArgTest, PredefinedArgs)
  {
      cv::gapi::GKernelPackage pkg = cv::gapi::kernels<GOCVTestOp>();
      cv::GCompileArg arg0 { pkg },
                      arg1 { cv::gapi::use_only { pkg } },
                      arg2 { cv::graph_dump_path { "fake_path" } };
  
      GCompileArgs compArgs { arg0, arg1, arg2 };
  
      auto kernelPkgOpt = cv::gapi::getCompileArg<cv::gapi::GKernelPackage>(compArgs);
      GAPI_Assert(kernelPkgOpt.has_value());
      EXPECT_NO_THROW(kernelPkgOpt.value().lookup("org.opencv.test.test_op"));
  
      auto hasUseOnlyOpt = cv::gapi::getCompileArg<cv::gapi::use_only>(compArgs);
      GAPI_Assert(hasUseOnlyOpt.has_value());
      EXPECT_NO_THROW(hasUseOnlyOpt.value().pkg.lookup("org.opencv.test.test_op"));
  
      auto dumpInfoOpt = cv::gapi::getCompileArg<cv::graph_dump_path>(compArgs);
      GAPI_Assert(dumpInfoOpt.has_value());
      EXPECT_EQ("fake_path", dumpInfoOpt.value().m_dump_path);
  }
  
  TEST(GetCompileArg, CustomArgs)
  {;
      cv::GCompileArgs compArgs{ GCompileArg { CustomArg { 7 } } };
  
      auto customArgOpt = cv::gapi::getCompileArg<CustomArg>(compArgs);
      GAPI_Assert(customArgOpt.has_value());
      EXPECT_EQ(7, customArgOpt.value().number);
  }
  } // namespace opencv_test