Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r205:43aafe465a8b
Date: 2014-12-19 15:26 +0100
http://bitbucket.org/cffi/creflect/changeset/43aafe465a8b/

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
@@ -153,3 +153,41 @@
     assert repr(ffi.cast(p, 'A')) == "<cdata 'char' %s'A'>" % 
mandatory_b_prefix
     assert repr(ffi.cast(p, 255)) == r"<cdata 'char' %s'\xff'>" % 
mandatory_b_prefix
     assert repr(ffi.cast(p, 0)) == r"<cdata 'char' %s'\x00'>" % 
mandatory_b_prefix
+
+def test_pointer_type():
+    ffi = support.new_ffi()
+    p = ffi.typeof("int")
+    assert repr(p) == "<ctype 'int'>"
+    p = ffi.typeof("int*")
+    assert repr(p) == "<ctype 'int *'>"
+    p = ffi.typeof("int**")
+    assert repr(p) == "<ctype 'int * *'>"
+    p = ffi.typeof("int***")
+    assert repr(p) == "<ctype 'int * * *'>"
+
+def test_inspect_pointer_type():
+    ffi = support.new_ffi()
+    p1 = ffi.typeof("int")
+    p2 = ffi.typeof("int*")
+    assert p2.kind == "pointer"
+    assert p2.cname == "int *"
+    assert p2.item is p1
+    check_dir(p2, ['cname', 'kind', 'item'])
+    p3 = ffi.typeof("int**")
+    assert p3.item is p2
+
+def test_pointer_to_int():
+    ffi = support.new_ffi()
+    py.test.raises(TypeError, ffi.new, "int")
+    py.test.raises(TypeError, ffi.new, "int", None)
+    py.test.raises(TypeError, ffi.new, "int", 42)
+    p = ffi.new("int*")
+    assert repr(p) == "<cdata 'int *' owning %d bytes>" % size_of_int()
+    p = ffi.new("int*", None)
+    assert repr(p) == "<cdata 'int *' owning %d bytes>" % size_of_int()
+    p = ffi.new("int*", 5000)
+    assert repr(p) == "<cdata 'int *' owning %d bytes>" % size_of_int()
+    q = ffi.cast("int *", p)
+    assert repr(q).startswith("<cdata 'int *' 0x")
+    assert p == q
+    assert hash(p) == hash(q)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to