File: gapi_compile_args_tests.cpp

package info (click to toggle)
opencv 4.10.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 282,092 kB
  • sloc: cpp: 1,178,079; xml: 682,621; python: 49,092; lisp: 31,150; java: 25,469; ansic: 11,039; javascript: 6,085; sh: 1,214; cs: 601; perl: 494; objc: 210; makefile: 173
file content (75 lines) | stat: -rw-r--r-- 2,058 bytes parent folder | download | duplicates (2)
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::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::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