Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_partial_enum():
ffi = FFI()
ffi.cdef("enum foo { A, B, ... };")
ffi.set_source('test_partial_enum', None)
py.test.raises(VerificationMissing, ffi.emit_python_code,
str(tmpdir.join('test_partial_enum.py')))
def test_ffi_nonfull_struct():
ffi = FFI()
ffi.cdef("""
struct foo_s {
int x;
...;
};
""")
py.test.raises(VerificationMissing, ffi.sizeof, 'struct foo_s')
py.test.raises(VerificationMissing, ffi.offsetof, 'struct foo_s', 'x')
py.test.raises(VerificationMissing, ffi.new, 'struct foo_s *')
ffi.verify("""
struct foo_s {
int a, b, x, c, d, e;
};
""")
assert ffi.sizeof('struct foo_s') == 6 * ffi.sizeof('int')
assert ffi.offsetof('struct foo_s', 'x') == 2 * ffi.sizeof('int')
def test_ffi_nonfull_struct():
ffi = FFI()
ffi.cdef("""
struct foo_s {
int x;
...;
};
""")
py.test.raises(VerificationMissing, ffi.sizeof, 'struct foo_s')
py.test.raises(VerificationMissing, ffi.offsetof, 'struct foo_s', 'x')
py.test.raises(VerificationMissing, ffi.new, 'struct foo_s *')
ffi.verify("""
struct foo_s {
int a, b, x, c, d, e;
};
""")
assert ffi.sizeof('struct foo_s') == 6 * ffi.sizeof('int')
assert ffi.offsetof('struct foo_s', 'x') == 2 * ffi.sizeof('int')
def test_nonfull_enum_syntax2():
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2=\t..., EE3 };")
py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == 'EE2'
assert ffi.string(ffi.cast('enum ee', -10)) == 'EE3'
#
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2=\t... };")
py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == 'EE2'
#
ffi = FFI()
ffi.cdef("enum ee2 { EE4=..., EE5=..., ... };")
ffi.verify("enum ee2 { EE4=-1234-5, EE5 }; ")
assert ffi.string(ffi.cast('enum ee2', -1239)) == 'EE4'
assert ffi.string(ffi.cast('enum ee2', -1238)) == 'EE5'
def test_partial_enum():
ffi = FFI()
ffi.cdef("enum foo { A, B, ... };")
ffi.set_source('test_partial_enum', None)
py.test.raises(VerificationMissing, ffi.emit_python_code,
str(tmpdir.join('test_partial_enum.py')))
def test_ffi_nonfull_struct():
ffi = FFI()
ffi.cdef("""
struct foo_s {
int x;
...;
};
""")
py.test.raises(VerificationMissing, ffi.sizeof, 'struct foo_s')
py.test.raises(VerificationMissing, ffi.offsetof, 'struct foo_s', 'x')
py.test.raises(VerificationMissing, ffi.new, 'struct foo_s *')
ffi.verify("""
struct foo_s {
int a, b, x, c, d, e;
};
""")
assert ffi.sizeof('struct foo_s') == 6 * ffi.sizeof('int')
assert ffi.offsetof('struct foo_s', 'x') == 2 * ffi.sizeof('int')
def test_nonfull_enum_syntax2():
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2=\t..., EE3 };")
py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == 'EE2'
assert ffi.string(ffi.cast('enum ee', -10)) == 'EE3'
#
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2=\t... };")
py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == 'EE2'
#
ffi = FFI()
ffi.cdef("enum ee2 { EE4=..., EE5=..., ... };")
ffi.verify("enum ee2 { EE4=-1234-5, EE5 }; ")
assert ffi.string(ffi.cast('enum ee2', -1239)) == 'EE4'
assert ffi.string(ffi.cast('enum ee2', -1238)) == 'EE5'
def test_nonfull_enum_syntax2():
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2=\t..., EE3 };")
py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == 'EE2'
assert ffi.string(ffi.cast('enum ee', -10)) == 'EE3'
#
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2=\t... };")
py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == 'EE2'
#
ffi = FFI()
ffi.cdef("enum ee2 { EE4=..., EE5=..., ... };")
ffi.verify("enum ee2 { EE4=-1234-5, EE5 }; ")
assert ffi.string(ffi.cast('enum ee2', -1239)) == 'EE4'
assert ffi.string(ffi.cast('enum ee2', -1238)) == 'EE5'
def test_ffi_nonfull_struct():
ffi = FFI()
ffi.cdef("""
struct foo_s {
int x;
...;
};
""")
py.test.raises(VerificationMissing, ffi.sizeof, 'struct foo_s')
py.test.raises(VerificationMissing, ffi.offsetof, 'struct foo_s', 'x')
py.test.raises(VerificationMissing, ffi.new, 'struct foo_s *')
ffi.verify("""
struct foo_s {
int a, b, x, c, d, e;
};
""")
assert ffi.sizeof('struct foo_s') == 6 * ffi.sizeof('int')
assert ffi.offsetof('struct foo_s', 'x') == 2 * ffi.sizeof('int')
def test_nonfull_enum_syntax2():
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2=\t..., EE3 };")
py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == 'EE2'
assert ffi.string(ffi.cast('enum ee', -10)) == 'EE3'
#
ffi = FFI()
ffi.cdef("enum ee { EE1, EE2=\t... };")
py.test.raises(VerificationMissing, ffi.cast, 'enum ee', 'EE1')
ffi.verify("enum ee { EE1=10, EE2, EE3=-10, EE4 };")
assert ffi.string(ffi.cast('enum ee', 11)) == 'EE2'
#
ffi = FFI()
ffi.cdef("enum ee2 { EE4=..., EE5=..., ... };")
ffi.verify("enum ee2 { EE4=-1234-5, EE5 }; ")
assert ffi.string(ffi.cast('enum ee2', -1239)) == 'EE4'
assert ffi.string(ffi.cast('enum ee2', -1238)) == 'EE5'