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