diff options
Diffstat (limited to 'sources/shiboken2/tests')
3 files changed, 27 insertions, 2 deletions
diff --git a/sources/shiboken2/tests/libsample/nontypetemplate.h b/sources/shiboken2/tests/libsample/nontypetemplate.h index 4e2100626..5a9e670c6 100644 --- a/sources/shiboken2/tests/libsample/nontypetemplate.h +++ b/sources/shiboken2/tests/libsample/nontypetemplate.h @@ -37,6 +37,7 @@ template <int Size> class IntArray { public: + explicit IntArray(const int *data) { std::copy(data, data + Size, m_array); } explicit IntArray(int v) { std::fill(m_array, m_array + Size, v); } int sum() const { return std::accumulate(m_array, m_array + Size, int(0)); } diff --git a/sources/shiboken2/tests/samplebinding/nontypetemplate_test.py b/sources/shiboken2/tests/samplebinding/nontypetemplate_test.py index 9adfa2441..a7a4da72b 100644 --- a/sources/shiboken2/tests/samplebinding/nontypetemplate_test.py +++ b/sources/shiboken2/tests/samplebinding/nontypetemplate_test.py @@ -28,6 +28,14 @@ ## ############################################################################# +hasNumPy = False + +try: + import numpy + hasNumPy = True +except ImportError: + pass + import unittest from sample import IntArray2, IntArray3 @@ -40,5 +48,12 @@ class NonTypeTemplateTest(unittest.TestCase): array3 = IntArray3(5) self.assertEqual(array3.sum(), 15) + def testArrayInitializer(self): + if not hasNumPy: + return + array3 = IntArray3(numpy.array([1, 2, 3], dtype = 'int32')) + self.assertEqual(array3.sum(), 6) + + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml index 9b967fc53..78ceaab43 100644 --- a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml @@ -521,8 +521,17 @@ </value-type> <value-type name="IntArray" generate="no"/> - <value-type name="IntArray2"/> - <value-type name="IntArray3"/> + <value-type name="IntArray2"> + <modify-function signature="IntArray2(const int*)"> + <modify-argument index="1"><array/></modify-argument> + </modify-function> + </value-type> + + <value-type name="IntArray3"> + <modify-function signature="IntArray3(const int*)"> + <modify-argument index="1"><array/></modify-argument> + </modify-function> + </value-type> <enum-type name="OverloadedFuncEnum"/> <!-- BUG: |