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.
5 // Copyright (C) 2018 Intel Corporation
8 #include "test_precomp.hpp"
15 static cv::GMat DemoCC(cv::GMat in, cv::GScalar scale)
17 return cv::gapi::medianBlur(in + in*scale, 3);
20 struct GCompiledValidateMetaTyped: public ::testing::Test
22 cv::GComputationT<cv::GMat(cv::GMat,cv::GScalar)> m_cc;
24 GCompiledValidateMetaTyped() : m_cc(DemoCC)
29 struct GCompiledValidateMetaUntyped: public ::testing::Test
33 cv::GComputation m_ucc;
35 GCompiledValidateMetaUntyped() : m_ucc(cv::GIn(in, scale),
36 cv::GOut(DemoCC(in, scale)))
40 } // anonymous namespace
42 TEST_F(GCompiledValidateMetaTyped, ValidMeta)
44 cv::Mat in = cv::Mat::eye(cv::Size(128, 32), CV_8UC1);
47 auto f = m_cc.compile(cv::descr_of(in),
50 // Correct operation when meta is exactly the same
52 EXPECT_NO_THROW(f(in, sc, out));
54 // Correct operation on next invocation with same meta
55 // taken from different input objects
56 cv::Mat in2 = cv::Mat::zeros(cv::Size(128, 32), CV_8UC1);
59 EXPECT_NO_THROW(f(in2, sc2, out2));
62 TEST_F(GCompiledValidateMetaTyped, InvalidMeta)
64 auto f = m_cc.compile(cv::GMatDesc{CV_8U,1,cv::Size(64,32)},
65 cv::empty_scalar_desc());
70 // 3 channels instead 1
71 cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC3);
72 EXPECT_THROW(f(in1, sc, out), std::logic_error);
75 cv::Mat in2 = cv::Mat::eye(cv::Size(64,32), CV_32F);
76 EXPECT_THROW(f(in2, sc, out), std::logic_error);
78 // 32x32 instead of 64x32
79 cv::Mat in3 = cv::Mat::eye(cv::Size(32,32), CV_8UC1);
80 EXPECT_THROW(f(in3, sc, out), std::logic_error);
83 cv::Mat in4 = cv::Mat::eye(cv::Size(128,64), CV_32FC3);
84 EXPECT_THROW(f(in4, sc, out), std::logic_error);
87 TEST_F(GCompiledValidateMetaUntyped, ValidMeta)
89 cv::Mat in1 = cv::Mat::eye(cv::Size(128, 32), CV_8UC1);
92 auto f = m_ucc.compile(cv::descr_of(in1),
95 // Correct operation when meta is exactly the same
97 EXPECT_NO_THROW(f(cv::gin(in1, sc), cv::gout(out1)));
99 // Correct operation on next invocation with same meta
100 // taken from different input objects
101 cv::Mat in2 = cv::Mat::zeros(cv::Size(128, 32), CV_8UC1);
104 EXPECT_NO_THROW(f(cv::gin(in2, sc2), cv::gout(out2)));
107 TEST_F(GCompiledValidateMetaUntyped, InvalidMetaValues)
109 auto f = m_ucc.compile(cv::GMatDesc{CV_8U,1,cv::Size(64,32)},
110 cv::empty_scalar_desc());
115 // 3 channels instead 1
116 cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC3);
117 EXPECT_THROW(f(cv::gin(in1, sc), cv::gout(out)), std::logic_error);
120 cv::Mat in2 = cv::Mat::eye(cv::Size(64,32), CV_32F);
121 EXPECT_THROW(f(cv::gin(in2, sc), cv::gout(out)), std::logic_error);
123 // 32x32 instead of 64x32
124 cv::Mat in3 = cv::Mat::eye(cv::Size(32,32), CV_8UC1);
125 EXPECT_THROW(f(cv::gin(in3, sc), cv::gout(out)), std::logic_error);
128 cv::Mat in4 = cv::Mat::eye(cv::Size(128,64), CV_32FC3);
129 EXPECT_THROW(f(cv::gin(in4, sc), cv::gout(out)), std::logic_error);
132 TEST_F(GCompiledValidateMetaUntyped, InvalidMetaShape)
134 auto f = m_ucc.compile(cv::GMatDesc{CV_8U,1,cv::Size(64,32)},
135 cv::empty_scalar_desc());
137 cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC1);
141 // call as f(Mat,Mat) while f(Mat,Scalar) is expected
142 EXPECT_THROW(f(cv::gin(in1, in1), cv::gout(out1)), std::logic_error);
144 // call as f(Scalar,Mat) while f(Mat,Scalar) is expected
145 EXPECT_THROW(f(cv::gin(sc, in1), cv::gout(out1)), std::logic_error);
147 // call as f(Scalar,Scalar) while f(Mat,Scalar) is expected
148 EXPECT_THROW(f(cv::gin(sc, sc), cv::gout(out1)), std::logic_error);
151 TEST_F(GCompiledValidateMetaUntyped, InvalidMetaNumber)
153 auto f = m_ucc.compile(cv::GMatDesc{CV_8U,1,cv::Size(64,32)},
154 cv::empty_scalar_desc());
156 cv::Mat in1 = cv::Mat::eye(cv::Size(64,32), CV_8UC1);
160 // call as f(Mat,Scalar,Scalar) while f(Mat,Scalar) is expected
161 EXPECT_THROW(f(cv::gin(in1, sc, sc), cv::gout(out1)), std::logic_error);
163 // call as f(Scalar,Mat,Scalar) while f(Mat,Scalar) is expected
164 EXPECT_THROW(f(cv::gin(sc, in1, sc), cv::gout(out1)), std::logic_error);
166 // call as f(Scalar) while f(Mat,Scalar) is expected
167 EXPECT_THROW(f(cv::gin(sc), cv::gout(out1)), std::logic_error);
169 // call as f(Mat,Scalar,[out1],[out2]) while f(Mat,Scalar,[out]) is expected
170 EXPECT_THROW(f(cv::gin(in1, sc), cv::gout(out1, out2)), std::logic_error);
173 } // namespace opencv_test