From: Robert Bradshaw Date: Sun, 21 Feb 2010 10:02:59 +0000 (-0800) Subject: Simple reference tests. X-Git-Tag: 0.13.beta0~329 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9444212e9881c0b4951ea554e0b87afd90a1e481;p=cython.git Simple reference tests. --- diff --git a/tests/wrappers/cpp_references.pyx b/tests/wrappers/cpp_references.pyx new file mode 100644 index 00000000..bf53a2e2 --- /dev/null +++ b/tests/wrappers/cpp_references.pyx @@ -0,0 +1,44 @@ +cdef extern from "cpp_references_helper.h": + cdef int& ref_func(int&) + + cdef int ref_var_value + cdef int& ref_var + +def test_ref_func(int x): + """ + >>> test_ref_func(2) + 2 + >>> test_ref_func(3) + 3 + """ + return ref_func(x) + +def test_ref_func_address(int x): + """ + >>> test_ref_func_address(5) + 5 + >>> test_ref_func_address(7) + 7 + """ + cdef int* i_ptr = &ref_func(x) + return i_ptr[0] + +def test_ref_var(int x): + """ + >>> test_ref_func(11) + 11 + >>> test_ref_func(13) + 13 + """ + ref_var = x + return ref_var_value + +def test_ref_assign(int x): + """ + >>> test_ref_assign(17) + 17.0 + >>> test_ref_assign(19) + 19.0 + """ + cdef double d = ref_func(x) + return d diff --git a/tests/wrappers/cpp_references_helper.h b/tests/wrappers/cpp_references_helper.h new file mode 100644 index 00000000..95de116e --- /dev/null +++ b/tests/wrappers/cpp_references_helper.h @@ -0,0 +1,5 @@ + +int ref_var_value = 10; +int& ref_var = ref_var_value; + +int& ref_func(int& x) { return x; }