[pypy-commit] cffi default: Extra test.

arigo noreply at buildbot.pypy.org
Mon Jun 25 18:29:16 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r511:dfa132331270
Date: 2012-06-25 18:29 +0200
http://bitbucket.org/cffi/cffi/changeset/dfa132331270/

Log:	Extra test.

diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -198,6 +198,27 @@
         assert int(cast(p, 4.2)) == 4
         py.test.raises(TypeError, newp, new_pointer_type(p), 4.2)
 
+def test_newp_integer_types():
+    for name in ['signed char', 'short', 'int', 'long', 'long long']:
+        p = new_primitive_type(name)
+        pp = new_pointer_type(p)
+        size = sizeof(p)
+        min = -(1 << (8*size-1))
+        max = (1 << (8*size-1)) - 1
+        assert newp(pp, min)[0] == min
+        assert newp(pp, max)[0] == max
+        py.test.raises(OverflowError, newp, pp, min - 1)
+        py.test.raises(OverflowError, newp, pp, max + 1)
+    for name in ['char', 'short', 'int', 'long', 'long long']:
+        p = new_primitive_type('unsigned ' + name)
+        pp = new_pointer_type(p)
+        size = sizeof(p)
+        max = (1 << (8*size)) - 1
+        assert newp(pp, 0)[0] == 0
+        assert newp(pp, max)[0] == max
+        py.test.raises(OverflowError, newp, pp, -1)
+        py.test.raises(OverflowError, newp, pp, max + 1)
+
 def test_reading_pointer_to_char():
     BChar = new_primitive_type("char")
     py.test.raises(TypeError, newp, BChar, None)


More information about the pypy-commit mailing list