From 9444212e9881c0b4951ea554e0b87afd90a1e481 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sun, 21 Feb 2010 02:02:59 -0800 Subject: [PATCH] Simple reference tests. --- tests/wrappers/cpp_references.pyx | 44 ++++++++++++++++++++++++++ tests/wrappers/cpp_references_helper.h | 5 +++ 2 files changed, 49 insertions(+) create mode 100644 tests/wrappers/cpp_references.pyx create mode 100644 tests/wrappers/cpp_references_helper.h 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; } -- 2.26.2