Skip to content

Commit 225589d

Browse files
committed
feat: add test for return by argument with an allocation
1 parent 1d2a116 commit 225589d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/cpp/test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ void returnByArgumentPointer(cv::Mat *mat) {
179179
mat->at<cv::Vec3w>(0, 0) = cv::Vec3w(4,5,6);
180180
}
181181

182+
void returnByArgumentValueWithAllocation(cv::Mat mat) {
183+
mat = cv::Mat::ones(cv::Size(3, 3), CV_8UC1);
184+
}
185+
186+
void returnByArgumentRefWithAllocation(cv::Mat & mat) {
187+
mat = cv::Mat::ones(cv::Size(3, 3), CV_8UC1);
188+
}
189+
182190
PYBIND11_MODULE(test_module, m) {
183191

184192
NDArrayConverter::init_numpy();
@@ -228,4 +236,8 @@ PYBIND11_MODULE(test_module, m) {
228236

229237
m.def("returnByArgumentPointer", &returnByArgumentPointer);
230238

239+
m.def("returnByArgumentValueWithAllocation", &returnByArgumentValueWithAllocation);
240+
241+
m.def("returnByArgumentRefWithAllocation", &returnByArgumentRefWithAllocation);
242+
231243
}

tests/test_return.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,24 @@ def test_return_by_argument_by_value():
5353
def test_return_by_argument_by_ref():
5454
mat = generate_matrix()
5555
tm.returnByArgumentRef(mat)
56-
assert(np.any(mat != generate_matrix()))
5756
assert(not check_matrix_content(mat))
5857

5958

6059
def test_return_by_argument_by_pointer():
6160
mat = generate_matrix()
6261
tm.returnByArgumentPointer(mat)
6362
assert(not check_matrix_content(mat))
63+
64+
65+
def test_return_by_argument_by_value():
66+
mat = generate_matrix()
67+
# During allocation we create a new buffer the data are not linked anymore
68+
tm.returnByArgumentValueWithAllocation(mat)
69+
assert(check_matrix_content(mat))
70+
71+
72+
def test_return_by_argument_by_ref():
73+
mat = generate_matrix()
74+
# During allocation we create a new buffer the data are not linked anymore
75+
tm.returnByArgumentRefWithAllocation(mat)
76+
assert(check_matrix_content(mat))

0 commit comments

Comments
 (0)