Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r206:98742ee6ef39
Date: 2014-12-19 15:31 +0100
http://bitbucket.org/cffi/creflect/changeset/98742ee6ef39/

Log:    more tests

diff --git a/zeffir/test/test_c.py b/zeffir/test/test_c.py
--- a/zeffir/test/test_c.py
+++ b/zeffir/test/test_c.py
@@ -191,3 +191,34 @@
     assert repr(q).startswith("<cdata 'int *' 0x")
     assert p == q
     assert hash(p) == hash(q)
+
+def test_pointer_bool():
+    ffi = support.new_ffi()
+    p = ffi.cast("int*", 0)
+    assert bool(p) is False
+    p = ffi.cast("int*", 42)
+    assert bool(p) is True
+
+def test_pointer_to_pointer():
+    ffi = support.new_ffi()
+    p = ffi.new("int**", None)
+    assert repr(p) == "<cdata 'int * *' owning %d bytes>" % size_of_ptr()
+
+def test_reading_pointer_to_int():
+    ffi = support.new_ffi()
+    p = ffi.new("int *")
+    assert p[0] == 0
+    p = ffi.new("int *", 5000)
+    assert p[0] == 5000
+    py.test.raises(IndexError, "p[1]")
+    py.test.raises(IndexError, "p[-1]")
+
+def test_reading_pointer_to_float():
+    ffi = support.new_ffi()
+    py.test.raises(TypeError, ffi.new, "float")
+    p = ffi.new("float *", None)
+    assert p[0] == 0.0 and type(p[0]) is float
+    p = ffi.new("float *", 1.25)
+    assert p[0] == 1.25 and type(p[0]) is float
+    p = ffi.new("float *", 1.1)
+    assert p[0] != 1.1 and abs(p[0] - 1.1) < 1E-5   # rounding errors
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to