Simple reference tests.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sun, 21 Feb 2010 10:02:59 +0000 (02:02 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sun, 21 Feb 2010 10:02:59 +0000 (02:02 -0800)
tests/wrappers/cpp_references.pyx [new file with mode: 0644]
tests/wrappers/cpp_references_helper.h [new file with mode: 0644]

diff --git a/tests/wrappers/cpp_references.pyx b/tests/wrappers/cpp_references.pyx
new file mode 100644 (file)
index 0000000..bf53a2e
--- /dev/null
@@ -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 (file)
index 0000000..95de116
--- /dev/null
@@ -0,0 +1,5 @@
+
+int ref_var_value = 10;
+int& ref_var = ref_var_value;
+
+int& ref_func(int& x) { return x; }