// 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) 2018 Intel Corporation #include "test_precomp.hpp" #include "opencv2/gapi/cpu/gcpukernel.hpp" #include "gapi_mock_kernels.hpp" namespace opencv_test { namespace { G_TYPED_KERNEL(GClone, , "org.opencv.test.clone") { static GMatDesc outMeta(GMatDesc in) { return in; } }; GAPI_OCV_KERNEL(GCloneImpl, GClone) { static void run(const cv::Mat& in, cv::Mat &out) { out = in.clone(); } }; } TEST(KernelPackage, Create) { namespace J = Jupiter; auto pkg = cv::gapi::kernels(); EXPECT_EQ(3u, pkg.size()); } TEST(KernelPackage, Includes) { namespace J = Jupiter; auto pkg = cv::gapi::kernels(); EXPECT_TRUE (pkg.includes()); EXPECT_TRUE (pkg.includes()); EXPECT_TRUE (pkg.includes()); EXPECT_FALSE(pkg.includes()); } TEST(KernelPackage, IncludesAPI) { namespace J = Jupiter; namespace S = Saturn; auto pkg = cv::gapi::kernels(); EXPECT_TRUE (pkg.includesAPI()); EXPECT_TRUE (pkg.includesAPI()); EXPECT_FALSE(pkg.includesAPI()); EXPECT_FALSE(pkg.includesAPI()); } TEST(KernelPackage, IncludesAPI_Overlapping) { namespace J = Jupiter; namespace S = Saturn; auto pkg = cv::gapi::kernels(); EXPECT_TRUE (pkg.includesAPI()); EXPECT_TRUE (pkg.includesAPI()); EXPECT_FALSE(pkg.includesAPI()); EXPECT_FALSE(pkg.includesAPI()); } TEST(KernelPackage, Include_Add) { namespace J = Jupiter; auto pkg = cv::gapi::kernels(); EXPECT_FALSE(pkg.includes()); pkg.include(); EXPECT_TRUE(pkg.includes()); } TEST(KernelPackage, Include_KEEP) { namespace J = Jupiter; namespace S = Saturn; auto pkg = cv::gapi::kernels(); EXPECT_FALSE(pkg.includes()); EXPECT_FALSE(pkg.includes()); pkg.include(); // default (KEEP) EXPECT_TRUE(pkg.includes()); EXPECT_TRUE(pkg.includes()); pkg.include(cv::unite_policy::KEEP); // explicit (KEEP) EXPECT_TRUE(pkg.includes()); EXPECT_TRUE(pkg.includes()); } TEST(KernelPackage, Include_REPLACE) { namespace J = Jupiter; namespace S = Saturn; auto pkg = cv::gapi::kernels(); EXPECT_FALSE(pkg.includes()); pkg.include(cv::unite_policy::REPLACE); EXPECT_FALSE(pkg.includes()); EXPECT_TRUE(pkg.includes()); } TEST(KernelPackage, RemoveBackend) { namespace J = Jupiter; namespace S = Saturn; auto pkg = cv::gapi::kernels(); EXPECT_TRUE(pkg.includes()); EXPECT_TRUE(pkg.includes()); EXPECT_TRUE(pkg.includes()); pkg.remove(J::backend()); EXPECT_FALSE(pkg.includes()); EXPECT_FALSE(pkg.includes()); EXPECT_TRUE(pkg.includes()); }; TEST(KernelPackage, RemoveAPI) { namespace J = Jupiter; namespace S = Saturn; auto pkg = cv::gapi::kernels(); EXPECT_TRUE(pkg.includes()); EXPECT_TRUE(pkg.includes()); EXPECT_TRUE(pkg.includes()); pkg.remove(); EXPECT_TRUE(pkg.includes()); EXPECT_TRUE(pkg.includes()); EXPECT_FALSE(pkg.includes()); EXPECT_FALSE(pkg.includes()); }; TEST(KernelPackage, CreateHetero) { namespace J = Jupiter; namespace S = Saturn; auto pkg = cv::gapi::kernels(); EXPECT_EQ(4u, pkg.size()); } TEST(KernelPackage, IncludesHetero) { namespace J = Jupiter; namespace S = Saturn; auto pkg = cv::gapi::kernels(); EXPECT_TRUE (pkg.includes()); EXPECT_TRUE (pkg.includes()); EXPECT_TRUE (pkg.includes()); EXPECT_FALSE(pkg.includes()); EXPECT_TRUE (pkg.includes()); } TEST(KernelPackage, IncludeHetero) { namespace J = Jupiter; namespace S = Saturn; auto pkg = cv::gapi::kernels(); EXPECT_FALSE(pkg.includes()); EXPECT_FALSE(pkg.includes()); pkg.include(); EXPECT_FALSE(pkg.includes()); EXPECT_TRUE (pkg.includes()); } TEST(KernelPackage, Combine_REPLACE_Full) { namespace J = Jupiter; namespace S = Saturn; auto j_pkg = cv::gapi::kernels(); auto s_pkg = cv::gapi::kernels(); auto u_pkg = cv::gapi::combine(j_pkg, s_pkg, cv::unite_policy::REPLACE); EXPECT_EQ(3u, u_pkg.size()); EXPECT_FALSE(u_pkg.includes()); EXPECT_FALSE(u_pkg.includes()); EXPECT_FALSE(u_pkg.includes()); EXPECT_TRUE (u_pkg.includes()); EXPECT_TRUE (u_pkg.includes()); EXPECT_TRUE (u_pkg.includes()); } TEST(KernelPackage, Combine_REPLACE_Partial) { namespace J = Jupiter; namespace S = Saturn; auto j_pkg = cv::gapi::kernels(); auto s_pkg = cv::gapi::kernels(); auto u_pkg = cv::gapi::combine(j_pkg, s_pkg, cv::unite_policy::REPLACE); EXPECT_EQ(2u, u_pkg.size()); EXPECT_TRUE (u_pkg.includes()); EXPECT_FALSE(u_pkg.includes()); EXPECT_TRUE (u_pkg.includes()); } TEST(KernelPackage, Combine_REPLACE_Append) { namespace J = Jupiter; namespace S = Saturn; auto j_pkg = cv::gapi::kernels(); auto s_pkg = cv::gapi::kernels(); auto u_pkg = cv::gapi::combine(j_pkg, s_pkg, cv::unite_policy::REPLACE); EXPECT_EQ(3u, u_pkg.size()); EXPECT_TRUE(u_pkg.includes()); EXPECT_TRUE(u_pkg.includes()); EXPECT_TRUE(u_pkg.includes()); } TEST(KernelPackage, Combine_KEEP_AllDups) { namespace J = Jupiter; namespace S = Saturn; auto j_pkg = cv::gapi::kernels(); auto s_pkg = cv::gapi::kernels(); auto u_pkg = cv::gapi::combine(j_pkg ,s_pkg, cv::unite_policy::KEEP); EXPECT_EQ(6u, u_pkg.size()); EXPECT_TRUE(u_pkg.includes()); EXPECT_TRUE(u_pkg.includes()); EXPECT_TRUE(u_pkg.includes()); EXPECT_TRUE(u_pkg.includes()); EXPECT_TRUE(u_pkg.includes()); EXPECT_TRUE(u_pkg.includes()); } TEST(KernelPackage, Combine_KEEP_Append_NoDups) { namespace J = Jupiter; namespace S = Saturn; auto j_pkg = cv::gapi::kernels(); auto s_pkg = cv::gapi::kernels(); auto u_pkg = cv::gapi::combine(j_pkg, s_pkg, cv::unite_policy::KEEP); EXPECT_EQ(3u, u_pkg.size()); EXPECT_TRUE(u_pkg.includes()); EXPECT_TRUE(u_pkg.includes()); EXPECT_TRUE(u_pkg.includes()); } TEST(KernelPackage, TestWithEmptyLHS) { namespace J = Jupiter; auto lhs = cv::gapi::kernels<>(); auto rhs = cv::gapi::kernels(); auto pkg = cv::gapi::combine(lhs, rhs, cv::unite_policy::KEEP); EXPECT_EQ(1u, pkg.size()); EXPECT_TRUE(pkg.includes()); } TEST(KernelPackage, TestWithEmptyRHS) { namespace J = Jupiter; auto lhs = cv::gapi::kernels(); auto rhs = cv::gapi::kernels<>(); auto pkg = cv::gapi::combine(lhs, rhs, cv::unite_policy::KEEP); EXPECT_EQ(1u, pkg.size()); EXPECT_TRUE(pkg.includes()); } TEST(KernelPackage, Can_Use_Custom_Kernel) { cv::GMat in[2]; auto out = GClone::on(cv::gapi::add(in[0], in[1])); const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::Size(32,32)}); auto pkg = cv::gapi::kernels(); EXPECT_NO_THROW(cv::GComputation(cv::GIn(in[0], in[1]), cv::GOut(out)). compile({in_meta, in_meta}, cv::compile_args(pkg))); } } // namespace opencv_test