Skip to content

Commit 4c1c4f9

Browse files
committed
fix: test for return argument
1 parent beb628d commit 4c1c4f9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

tests/cpp/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ cv::Mat cloneimg(cv::Mat image) {
145145
class ClassForReturn {
146146
public:
147147
ClassForReturn() {
148-
m_image = cv::Mat(2, 2, CV_8UC3, cv::Scalar(1,2,3));
148+
m_image = generateMatrix();
149149
}
150150

151151
cv::Mat& returnByRef() { return m_image; };
@@ -160,7 +160,7 @@ class ClassForReturn {
160160
void returnInArgumentByPointer(cv::Mat* image) {};
161161

162162
void changeInternal() {
163-
m_image.at<cv::Vec3b>(0, 0) = cv::Vec3b(4,5,6);
163+
m_image.at<cv::Vec3w>(0, 0) = cv::Vec3w(4,5,6);
164164
}
165165

166166
private:

tests/test_return.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,43 @@
22
from tests import test_module as tm
33
from tests.utils import generate_matrix, check_matrix_content
44

5+
56
def test_return_by_value():
67
a = tm.ClassForReturn()
7-
assert(id(a.returnByValue()) != id(a.returnByValue()))
88
mat = a.returnByValue()
99
a.changeInternal()
10-
assert(np.any(mat != a.returnByValue()))
10+
assert(check_matrix_content(mat))
11+
changed_mat = a.returnByValue()
12+
assert(not check_matrix_content(changed_mat))
1113

1214

1315
def test_return_by_ref_but_copy():
1416
a = tm.ClassForReturn()
15-
assert(id(a.returnByRef()) != id(a.returnByRef()))
1617
mat = a.returnByRef()
1718
a.changeInternal()
18-
assert(np.any(mat != a.returnByValue()))
19+
assert(check_matrix_content(mat))
20+
changed_mat = a.returnByValue()
21+
assert(not check_matrix_content(changed_mat))
1922

2023

2124
def test_return_by_ref():
2225
a = tm.ClassForReturn()
23-
assert(id(a.returnByRef()) != id(a.returnByRef()))
2426
mat = a.viewMatrix()
2527
a.changeInternal()
26-
assert(np.all(mat == a.returnByValue()))
28+
# Currently return parameter perform a copy of the data, so the change is not repercuted to mat
29+
assert(check_matrix_content(mat))
30+
changed_mat = a.returnByValue()
31+
assert(not check_matrix_content(changed_mat))
2732

2833

2934
def test_return_by_pointer():
3035
a = tm.ClassForReturn()
31-
assert(id(a.returnByPointer()) != id(a.returnByPointer()))
3236
mat = a.returnByPointer()
3337
a.changeInternal()
34-
assert(np.all(mat == a.returnByValue()))
35-
38+
# Currently return parameter perform a copy of the data, so the change is not repercuted to mat
39+
assert(check_matrix_content(mat))
40+
changed_mat = a.returnByValue()
41+
assert(not check_matrix_content(changed_mat))
3642

3743

3844
def test_return_by_argument_by_value():

0 commit comments

Comments
 (0)