summaryrefslogtreecommitdiff
path: root/testing/test_cdata.py
diff options
context:
space:
mode:
authorRonny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>2012-05-17 10:07:32 +0200
committerRonny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>2012-05-17 10:07:32 +0200
commite8f2e3fe8c9a1e0986d7d53e4aa626ded9b40205 (patch)
tree896199daab752588fd97c18890620890ebcfc189 /testing/test_cdata.py
parent88f80f3812f120feef431d77b004fb4aefa83253 (diff)
downloadcffi-e8f2e3fe8c9a1e0986d7d53e4aa626ded9b40205.tar.gz
change file layout
* ffi as package * test -> testing * kill src dir
Diffstat (limited to 'testing/test_cdata.py')
-rw-r--r--testing/test_cdata.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/testing/test_cdata.py b/testing/test_cdata.py
new file mode 100644
index 0000000..dbc9ff6
--- /dev/null
+++ b/testing/test_cdata.py
@@ -0,0 +1,41 @@
+import py
+from ffi import FFI
+
+class FakeBackend(object):
+
+ def load_library(self):
+ return None
+
+ def new_primitive_type(self, name):
+ return FakePrimitiveType(name)
+
+class FakePrimitiveType(object):
+
+ def __init__(self, cdecl):
+ self.cdecl = cdecl
+
+
+def test_typeof():
+ ffi = FFI(backend=FakeBackend())
+ clong = ffi.typeof("long")
+ assert isinstance(clong, FakePrimitiveType)
+ assert clong.cdecl == 'long'
+
+def test_new_array_no_arg():
+ ffi = FFI(backend=FakeBackend())
+ p = ffi.new("int[10]")
+ # the object was zero-initialized:
+ for i in range(10):
+ assert p[i] == 0
+
+def test_array_indexing():
+ ffi = FFI(backend=FakeBackend())
+ p = ffi.new("int[10]")
+ p[0] = 42
+ p[9] = 43
+ assert p[0] == 42
+ assert p[9] == 43
+ py.test.raises(IndexError, "p[10]")
+ py.test.raises(IndexError, "p[10] = 44")
+ py.test.raises(IndexError, "p[-1]")
+ py.test.raises(IndexError, "p[-1] = 44")