当前位置: 首页>>代码示例>>Python>>正文


Python _ctypes_test.c方法代码示例

本文整理汇总了Python中_ctypes_test.c方法的典型用法代码示例。如果您正苦于以下问题:Python _ctypes_test.c方法的具体用法?Python _ctypes_test.c怎么用?Python _ctypes_test.c使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在_ctypes_test的用法示例。


在下文中一共展示了_ctypes_test.c方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_callback_register_double

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import c [as 别名]
def test_callback_register_double(self):
        # Issue #8275: buggy handling of callback args under Win64
        # NOTE: should be run on release builds as well
        dll = CDLL(_ctypes_test.__file__)
        CALLBACK = CFUNCTYPE(c_double, c_double, c_double, c_double,
                             c_double, c_double)
        # All this function does is call the callback with its args squared
        func = dll._testfunc_cbk_reg_double
        func.argtypes = (c_double, c_double, c_double,
                         c_double, c_double, CALLBACK)
        func.restype = c_double

        def callback(a, b, c, d, e):
            return a + b + c + d + e

        result = func(1.1, 2.2, 3.3, 4.4, 5.5, CALLBACK(callback))
        self.assertEqual(result,
                         callback(1.1*1.1, 2.2*2.2, 3.3*3.3, 4.4*4.4, 5.5*5.5)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_callbacks.py

示例2: test_positional_args

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import c [as 别名]
def test_positional_args(self):
        # see also http://bugs.python.org/issue5042
        class W(Structure):
            _fields_ = [("a", c_int), ("b", c_int)]
        class X(W):
            _fields_ = [("c", c_int)]
        class Y(X):
            pass
        class Z(Y):
            _fields_ = [("d", c_int), ("e", c_int), ("f", c_int)]

        z = Z(1, 2, 3, 4, 5, 6)
        self.assertEqual((z.a, z.b, z.c, z.d, z.e, z.f),
                         (1, 2, 3, 4, 5, 6))
        z = Z(1)
        self.assertEqual((z.a, z.b, z.c, z.d, z.e, z.f),
                         (1, 0, 0, 0, 0, 0))
        self.assertRaises(TypeError, lambda: Z(1, 2, 3, 4, 5, 6, 7)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_structures.py

示例3: test_pass_by_value

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import c [as 别名]
def test_pass_by_value(self):
        # This should mirror the structure in Modules/_ctypes/_ctypes_test.c
        class X(Structure):
            _fields_ = [
                ('first', c_ulong),
                ('second', c_ulong),
                ('third', c_ulong),
            ]

        s = X()
        s.first = 0xdeadbeef
        s.second = 0xcafebabe
        s.third = 0x0bad1dea
        dll = CDLL(_ctypes_test.__file__)
        func = dll._testfunc_large_struct_update_value
        func.argtypes = (X,)
        func.restype = None
        func(s)
        self.assertEqual(s.first, 0xdeadbeef)
        self.assertEqual(s.second, 0xcafebabe)
        self.assertEqual(s.third, 0x0bad1dea) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_structures.py

示例4: test_init_errors

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import c [as 别名]
def test_init_errors(self):
        class Phone(Structure):
            _fields_ = [("areacode", c_char*6),
                        ("number", c_char*12)]

        class Person(Structure):
            _fields_ = [("name", c_char * 12),
                        ("phone", Phone),
                        ("age", c_int)]

        cls, msg = self.get_except(Person, b"Someone", (1, 2))
        self.assertEqual(cls, RuntimeError)
        self.assertEqual(msg,
                             "(Phone) <class 'TypeError'>: "
                             "expected bytes, int found")

        cls, msg = self.get_except(Person, b"Someone", (b"a", b"b", b"c"))
        self.assertEqual(cls, RuntimeError)
        self.assertEqual(msg,
                             "(Phone) <class 'TypeError'>: too many initializers") 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:22,代码来源:test_structures.py

示例5: test_init_errors

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import c [as 别名]
def test_init_errors(self):
        class Phone(Structure):
            _fields_ = [("areacode", c_char*6),
                        ("number", c_char*12)]

        class Person(Structure):
            _fields_ = [("name", c_char * 12),
                        ("phone", Phone),
                        ("age", c_int)]

        cls, msg = self.get_except(Person, b"Someone", (1, 2))
        self.assertEqual(cls, RuntimeError)
        self.assertEqual(msg,
                             "(Phone) <class 'TypeError'>: "
                             "expected bytes, int found")

        cls, msg = self.get_except(Person, b"Someone", (b"a", b"b", b"c"))
        self.assertEqual(cls, RuntimeError)
        if issubclass(Exception, object):
            self.assertEqual(msg,
                                 "(Phone) <class 'TypeError'>: too many initializers")
        else:
            self.assertEqual(msg, "(Phone) TypeError: too many initializers") 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:25,代码来源:test_structures.py

示例6: test_issue_8959_a

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import c [as 别名]
def test_issue_8959_a(self):
        from ctypes.util import find_library
        libc_path = find_library("c")
        if not libc_path:
            self.skipTest('could not find libc')
        libc = CDLL(libc_path)

        @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
        def cmp_func(a, b):
            return a[0] - b[0]

        array = (c_int * 5)(5, 1, 99, 7, 33)

        libc.qsort(array, len(array), sizeof(c_int), cmp_func)
        self.assertEqual(array[:], [1, 5, 7, 33, 99]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_callbacks.py

示例7: test_callback_register_int

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import c [as 别名]
def test_callback_register_int(self):
        # Issue #8275: buggy handling of callback args under Win64
        # NOTE: should be run on release builds as well
        dll = CDLL(_ctypes_test.__file__)
        CALLBACK = CFUNCTYPE(c_int, c_int, c_int, c_int, c_int, c_int)
        # All this function does is call the callback with its args squared
        func = dll._testfunc_cbk_reg_int
        func.argtypes = (c_int, c_int, c_int, c_int, c_int, CALLBACK)
        func.restype = c_int

        def callback(a, b, c, d, e):
            return a + b + c + d + e

        result = func(2, 3, 4, 5, 6, CALLBACK(callback))
        self.assertEqual(result, callback(2*2, 3*3, 4*4, 5*5, 6*6)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_callbacks.py

示例8: test_simple_structs

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import c [as 别名]
def test_simple_structs(self):
        for code, tp in self.formats.items():
            class X(Structure):
                _fields_ = [("x", c_char),
                            ("y", tp)]
            self.assertEqual((sizeof(X), code),
                                 (calcsize("c%c0%c" % (code, code)), code)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_structures.py

示例9: test_init_errors

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import c [as 别名]
def test_init_errors(self):
        class Phone(Structure):
            _fields_ = [("areacode", c_char*6),
                        ("number", c_char*12)]

        class Person(Structure):
            _fields_ = [("name", c_char * 12),
                        ("phone", Phone),
                        ("age", c_int)]

        cls, msg = self.get_except(Person, "Someone", (1, 2))
        self.assertEqual(cls, RuntimeError)
        # In Python 2.5, Exception is a new-style class, and the repr changed
        if issubclass(Exception, object):
            self.assertEqual(msg,
                                 "(Phone) <type 'exceptions.TypeError'>: "
                                 "expected string or Unicode object, int found")
        else:
            # Compatibility no longer strictly required
            self.assertEqual(msg,
                                 "(Phone) exceptions.TypeError: "
                                 "expected string or Unicode object, int found")

        cls, msg = self.get_except(Person, "Someone", ("a", "b", "c"))
        self.assertEqual(cls, RuntimeError)
        if issubclass(Exception, object):
            self.assertEqual(msg,
                                 "(Phone) <type 'exceptions.TypeError'>: too many initializers")
        else:
            self.assertEqual(msg, "(Phone) exceptions.TypeError: too many initializers") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:32,代码来源:test_structures.py


注:本文中的_ctypes_test.c方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。