Author: David Schneider <david.schnei...@picle.org> Branch: Changeset: r64939:0e209e181c89 Date: 2013-06-19 13:01 -0500 http://bitbucket.org/pypy/pypy/changeset/0e209e181c89/
Log: more tests for _rawffi structures using bitfields diff --git a/pypy/module/_rawffi/test/test__rawffi.py b/pypy/module/_rawffi/test/test__rawffi.py --- a/pypy/module/_rawffi/test/test__rawffi.py +++ b/pypy/module/_rawffi/test/test__rawffi.py @@ -48,12 +48,12 @@ free(x1->next); free(x1); } - + const char *static_str = "xxxxxx"; long static_int = 42; double static_double = 42.42; long double static_longdouble = 42.42; - + unsigned short add_shorts(short one, short two) { return one + two; @@ -175,7 +175,7 @@ inp.y = inp.x * 100; return inp; } - + ''')) symbols = """get_char char_check get_raw_pointer add_shorts @@ -194,7 +194,7 @@ eci = ExternalCompilationInfo(export_symbols=symbols) return str(platform.compile([c_file], eci, 'x', standalone=False)) prepare_c_example = staticmethod(prepare_c_example) - + def setup_class(cls): space = cls.space from rpython.rlib.clibffi import get_libc_name @@ -438,7 +438,7 @@ arg.free() assert t.tm_year == 70 assert t.tm_sec == 1 - assert t.tm_min == 2 + assert t.tm_min == 2 x.free() def test_nested_structures(self): @@ -464,6 +464,20 @@ free_double_struct = lib.ptr("free_double_struct", ['P'], None) free_double_struct(res) + def test_structure_bitfields_char(self): + import _rawffi + X = _rawffi.Structure([('A', 'B', 1), + ('B', 'B', 6), + ('C', 'B', 1)]) + x = X() + x.A = 0xf + x.B = 0xff + x.C = 0xf + assert x.A == 1 + assert x.B == 63 + assert x.C == 1 + x.free() + def test_structure_bitfields(self): import _rawffi X = _rawffi.Structure([('A', 'I', 1), @@ -486,6 +500,60 @@ assert (y.a, y.b, y.c) == (-1, -7, 0) y.free() + def test_structure_bitfields_longlong(self): + import _rawffi + Z = _rawffi.Structure([('a', 'Q', 1), + ('b', 'Q', 62), + ('c', 'Q', 1)]) + z = Z() + z.a, z.b, z.c = 7, 0x1000000000000001, 7 + assert (z.a, z.b, z.c) == (1, 0x1000000000000001, 1) + z.free() + + def test_structure_ulonglong_bitfields(self): + import _rawffi + X = _rawffi.Structure([('A', 'Q', 1), + ('B', 'Q', 62), + ('C', 'Q', 1)]) + x = X() + x.A, x.B, x.C = 7, 0x1000000000000001, 7 + assert x.A == 1 + assert x.B == 0x1000000000000001 + assert x.C == 1 + x.free() + + def test_structure_longlong_bitfields(self): + import _rawffi + Y = _rawffi.Structure([('a', 'q', 1), + ('b', 'q', 61), + ('c', 'q', 1)]) + y = Y() + y.a, y.b, y.c = 0, -7, 0 + assert (y.a, y.b, y.c) == (0, -7, 0) + y.free() + + def test_structure_ulonglong_bitfields(self): + import _rawffi + X = _rawffi.Structure([('A', 'Q', 1), + ('B', 'Q', 62), + ('C', 'Q', 1)]) + x = X() + x.A, x.B, x.C = 7, 0x1000000000000001, 7 + assert x.A == 1 + assert x.B == 0x1000000000000001 + assert x.C == 1 + x.free() + + def test_structure_longlong_bitfields(self): + import _rawffi + Y = _rawffi.Structure([('a', 'q', 1), + ('b', 'q', 61), + ('c', 'q', 1)]) + y = Y() + y.a, y.b, y.c = 0, -7, 0 + assert (y.a, y.b, y.c) == (0, -7, 0) + y.free() + def test_invalid_bitfields(self): import _rawffi raises(TypeError, _rawffi.Structure, [('A', 'c', 1)]) @@ -571,7 +639,7 @@ res = pass_ll(arg1) assert res[0] == 1<<42 arg1.free() - + def test_callback(self): import _rawffi import struct @@ -970,7 +1038,7 @@ assert res.y == 33 assert s2h.x == 7 assert s2h.y == 11 - + s2h.free() def test_ret_struct_containing_array(self): @@ -1029,7 +1097,7 @@ class AppTestAutoFree: spaceconfig = dict(usemodules=['_rawffi', 'struct']) - + def setup_class(cls): cls.w_sizes_and_alignments = cls.space.wrap(dict( [(k, (v.c_size, v.c_alignment)) for k,v in TYPEMAP.iteritems()])) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit