Author: Armin Rigo <[email protected]>
Branch:
Changeset: r208:7489cad8641a
Date: 2014-12-19 16:34 +0100
http://bitbucket.org/cffi/creflect/changeset/7489cad8641a/
Log: next 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
@@ -264,3 +264,34 @@
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
+
+def test_cast_float_to_int():
+ ffi = support.new_ffi()
+ for type in ["int", "unsigned int", "long", "unsigned long",
+ "long long", "unsigned long long"]:
+ p = ffi.typeof(type)
+ assert ffi.cast(p, 4.2) == 4
+ py.test.raises(TypeError, ffi.new, type, 4.2)
+ py.test.raises(TypeError, ffi.new, type + "*", 4.2)
+
+def test_newp_integer_types():
+ ffi = support.new_ffi()
+ for name in ['signed char', 'short', 'int', 'long', 'long long']:
+ p = ffi.typeof(name)
+ pp = ffi.typeof(name + "*")
+ size = ffi.sizeof(p)
+ min = -(1 << (8*size-1))
+ max = (1 << (8*size-1)) - 1
+ assert ffi.new(pp, min)[0] == min
+ assert ffi.new(pp, max)[0] == max
+ py.test.raises(OverflowError, ffi.new, pp, min - 1)
+ py.test.raises(OverflowError, ffi.new, pp, max + 1)
+ for name in ['char', 'short', 'int', 'long', 'long long']:
+ p = ffi.typeof('unsigned ' + name)
+ pp = ffi.typeof('unsigned ' + name + "*")
+ size = ffi.sizeof(p)
+ max = (1 << (8*size)) - 1
+ assert ffi.new(pp, 0)[0] == 0
+ assert ffi.new(pp, max)[0] == max
+ py.test.raises(OverflowError, ffi.new, pp, -1)
+ py.test.raises(OverflowError, ffi.new, pp, max + 1)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit