Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/gapi/test/internal/gapi_int_garg_test.cpp
16344 views
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 Intel Corporation
6
7
8
#include "test_precomp.hpp"
9
10
namespace opencv_test {
11
// Tests on T/Kind matching ////////////////////////////////////////////////////
12
// {{
13
14
template<class T, cv::detail::ArgKind Exp>
15
struct Expected
16
{
17
using type = T;
18
static const constexpr cv::detail::ArgKind kind = Exp;
19
};
20
21
template<typename T>
22
struct GArgKind: public ::testing::Test
23
{
24
using Type = typename T::type;
25
const cv::detail::ArgKind Kind = T::kind;
26
};
27
28
// The reason here is to _manually_ list types and their kinds
29
// (and NOT reuse cv::detail::ArgKind::Traits<>, since it is a subject of testing)
30
using GArg_Test_Types = ::testing::Types
31
<
32
// G-API types
33
Expected<cv::GMat, cv::detail::ArgKind::GMAT>
34
, Expected<cv::GScalar, cv::detail::ArgKind::GSCALAR>
35
, Expected<cv::GArray<int>, cv::detail::ArgKind::GARRAY>
36
, Expected<cv::GArray<float>, cv::detail::ArgKind::GARRAY>
37
, Expected<cv::GArray<cv::Point>, cv::detail::ArgKind::GARRAY>
38
, Expected<cv::GArray<cv::Rect>, cv::detail::ArgKind::GARRAY>
39
40
// Built-in types
41
, Expected<int, cv::detail::ArgKind::OPAQUE>
42
, Expected<float, cv::detail::ArgKind::OPAQUE>
43
, Expected<int*, cv::detail::ArgKind::OPAQUE>
44
, Expected<cv::Point, cv::detail::ArgKind::OPAQUE>
45
, Expected<std::string, cv::detail::ArgKind::OPAQUE>
46
, Expected<cv::Mat, cv::detail::ArgKind::OPAQUE>
47
, Expected<std::vector<int>, cv::detail::ArgKind::OPAQUE>
48
, Expected<std::vector<cv::Point>, cv::detail::ArgKind::OPAQUE>
49
>;
50
51
TYPED_TEST_CASE(GArgKind, GArg_Test_Types);
52
53
TYPED_TEST(GArgKind, LocalVar)
54
{
55
typename TestFixture::Type val{};
56
cv::GArg arg(val);
57
EXPECT_EQ(TestFixture::Kind, arg.kind);
58
}
59
60
TYPED_TEST(GArgKind, ConstLocalVar)
61
{
62
const typename TestFixture::Type val{};
63
cv::GArg arg(val);
64
EXPECT_EQ(TestFixture::Kind, arg.kind);
65
}
66
67
TYPED_TEST(GArgKind, RValue)
68
{
69
cv::GArg arg = cv::GArg(typename TestFixture::Type());
70
EXPECT_EQ(TestFixture::Kind, arg.kind);
71
}
72
73
// }}
74
////////////////////////////////////////////////////////////////////////////////
75
76
TEST(GArg, HasWrap)
77
{
78
static_assert(!cv::detail::has_custom_wrap<cv::GMat>::value,
79
"GMat has no custom marshalling logic");
80
static_assert(!cv::detail::has_custom_wrap<cv::GScalar>::value,
81
"GScalar has no custom marshalling logic");
82
83
static_assert(cv::detail::has_custom_wrap<cv::GArray<int> >::value,
84
"GArray<int> has custom marshalling logic");
85
static_assert(cv::detail::has_custom_wrap<cv::GArray<std::string> >::value,
86
"GArray<int> has custom marshalling logic");
87
}
88
89
TEST(GArg, GArrayU)
90
{
91
// Placing a GArray<T> into GArg automatically strips it to GArrayU
92
cv::GArg arg1 = cv::GArg(cv::GArray<int>());
93
EXPECT_NO_THROW(arg1.get<cv::detail::GArrayU>());
94
95
cv::GArg arg2 = cv::GArg(cv::GArray<cv::Point>());
96
EXPECT_NO_THROW(arg2.get<cv::detail::GArrayU>());
97
}
98
99
100
} // namespace opencv_test
101
102