From 2bd0a604c13e003713a21f7fea423902bc64426a Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 17 Oct 2009 00:35:18 +0200 Subject: [PATCH] simple test for testing truth of C values --- tests/run/ctruthtests.pyx | 88 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/run/ctruthtests.pyx diff --git a/tests/run/ctruthtests.pyx b/tests/run/ctruthtests.pyx new file mode 100644 index 00000000..3a66bd17 --- /dev/null +++ b/tests/run/ctruthtests.pyx @@ -0,0 +1,88 @@ +__doc__ = u""" +>>> test_int(0) +False +>>> test_int(1) +True + +>>> test_short(0) +False +>>> test_short(1) +True + +>>> test_Py_ssize_t(0) +False +>>> test_Py_ssize_t(1) +True + +>>> test_ptr() +False +>>> test_ptr2() +2 + +>>> test_attr_int(TestExtInt(0)) +False +>>> test_attr_int(TestExtInt(1)) +True + +>>> test_attr_ptr(TestExtPtr(0)) +False +>>> test_attr_ptr(TestExtPtr(1)) +True +""" + +def test_ptr(): + cdef void* p = NULL + if p: + return True + else: + return False + +def test_ptr2(): + cdef void* p1 = NULL + cdef void* p2 = NULL + p1 += 1 + + if p1 and p2: + return 1 + elif p1 or p2: + return 2 + else: + return 3 + +def test_int(int i): + if i: + return True + else: + return False + +def test_short(short i): + if i: + return True + else: + return False + +def test_Py_ssize_t(Py_ssize_t i): + if i: + return True + else: + return False + +cdef class TestExtInt: + cdef int i + def __init__(self, i): self.i = i + +def test_attr_int(TestExtInt e): + if e.i: + return True + else: + return False + +cdef class TestExtPtr: + cdef void* p + def __init__(self, int i): self.p = i + +def test_attr_ptr(TestExtPtr e): + if e.p: + return True + else: + return False -- 2.26.2