當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。