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


Python _ctypes_test.__file__方法代码示例

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


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

示例1: test_integrate

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def test_integrate(self):
        # Derived from some then non-working code, posted by David Foster
        dll = CDLL(_ctypes_test.__file__)

        # The function prototype called by 'integrate': double func(double);
        CALLBACK = CFUNCTYPE(c_double, c_double)

        # The integrate function itself, exposed from the _ctypes_test dll
        integrate = dll.integrate
        integrate.argtypes = (c_double, c_double, CALLBACK, c_long)
        integrate.restype = c_double

        def func(x):
            return x**2

        result = integrate(0.0, 1.0, CALLBACK(func), 10)
        diff = abs(result - 1./3.)

        self.assertLess(diff, 0.01, "%s not less than 0.01" % diff) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_callbacks.py

示例2: test_callback_register_double

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [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

示例3: test_from_dll_refcount

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def test_from_dll_refcount(self):
        class BadSequence(tuple):
            def __getitem__(self, key):
                if key == 0:
                    return "my_strchr"
                if key == 1:
                    return CDLL(_ctypes_test.__file__)
                raise IndexError

        # _CFuncPtr instances are now callable with a tuple argument
        # which denotes a function name and a dll:
        strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(
                BadSequence(("my_strchr", CDLL(_ctypes_test.__file__))))
        self.assertTrue(strchr(b"abcdef", b"b"), "bcdef")
        self.assertEqual(strchr(b"abcdef", b"x"), None)
        self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0)
        self.assertRaises(TypeError, strchr, b"abcdef") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_returnfuncptrs.py

示例4: test_change_pointers

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def test_change_pointers(self):
        dll = CDLL(_ctypes_test.__file__)
        func = dll._testfunc_p_p

        i = c_int(87654)
        func.restype = POINTER(c_int)
        func.argtypes = (POINTER(c_int),)

        res = func(pointer(i))
        self.assertEqual(res[0], 87654)
        self.assertEqual(res.contents.value, 87654)

        # C code: *res = 54345
        res[0] = 54345
        self.assertEqual(i.value, 54345)

        # C code:
        #   int x = 12321;
        #   res = &x
        x = c_int(12321)
        res.contents = x
        self.assertEqual(i.value, 54345)

        x.value = -99
        self.assertEqual(res.contents.value, -99) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_pointers.py

示例5: test_pass_by_value

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [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

示例6: test_callback_register_double

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [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:dxwu,项目名称:BinderFilter,代码行数:23,代码来源:test_callbacks.py

示例7: test_change_pointers

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def test_change_pointers(self):
        dll = CDLL(_ctypes_test.__file__)
        func = dll._testfunc_p_p

        i = c_int(87654)
        func.restype = POINTER(c_int)
        func.argtypes = (POINTER(c_int),)

        res = func(pointer(i))
        self.assertEqual(res[0], 87654)
        self.assertEqual(res.contents.value, 87654)

        # C code: *res = 54345
        res[0] = 54345
        self.assertEqual(i.value, 54345)

        # C code:
        #   int x = 12321;
        #   res = &x
        res.contents = c_int(12321)
        self.assertEqual(i.value, 54345) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:23,代码来源:test_pointers.py

示例8: test_struct_by_value

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def test_struct_by_value(self):
        class POINT(Structure):
            _fields_ = [("x", c_long),
                        ("y", c_long)]

        class RECT(Structure):
            _fields_ = [("left", c_long),
                        ("top", c_long),
                        ("right", c_long),
                        ("bottom", c_long)]

        dll = CDLL(_ctypes_test.__file__)

        pt = POINT(10, 10)
        rect = RECT(0, 0, 20, 20)
        self.assertEqual(1, dll.PointInRect(byref(rect), pt)) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:18,代码来源:test_win32.py

示例9: test_char_ptr_with_free

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def test_char_ptr_with_free(self):
        dll = CDLL(_ctypes_test.__file__)
        s = "abcdefghijklmnopqrstuvwxyz"

        class allocated_c_char_p(c_char_p):
            pass

        dll.my_free.restype = None
        def errcheck(result, func, args):
            retval = result.value
            dll.my_free(result)
            return retval

        dll.my_strdup.restype = allocated_c_char_p
        dll.my_strdup.errcheck = errcheck
        try:
            res = dll.my_strdup(s)
            self.assertEqual(res, s)
        finally:
            del dll.my_strdup.errcheck 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:22,代码来源:test_slicing.py

示例10: test_pass_pointers

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def test_pass_pointers(self):
        dll = CDLL(_ctypes_test.__file__)
        func = dll._testfunc_p_p
        if sizeof(c_longlong) == sizeof(c_void_p):
            func.restype = c_longlong
        else:
            func.restype = c_long

        i = c_int(12345678)
##        func.argtypes = (POINTER(c_int),)
        address = func(byref(i))
        self.assertEqual(c_int.from_address(address).value, 12345678)

        func.restype = POINTER(c_int)
        res = func(pointer(i))
        self.assertEqual(res.contents.value, 12345678)
        self.assertEqual(res[0], 12345678) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_pointers.py

示例11: test_load_ordinal_functions

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def test_load_ordinal_functions(self):
        import _ctypes_test
        dll = WinDLL(_ctypes_test.__file__)
        # We load the same function both via ordinal and name
        func_ord = dll[2]
        func_name = dll.GetString
        # addressof gets the address where the function pointer is stored
        a_ord = addressof(func_ord)
        a_name = addressof(func_name)
        f_ord_addr = c_void_p.from_address(a_ord).value
        f_name_addr = c_void_p.from_address(a_name).value
        self.assertEqual(hex(f_ord_addr), hex(f_name_addr))

        self.assertRaises(AttributeError, dll.__getitem__, 1234) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_loading.py

示例12: test_callback_register_int

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [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

示例13: setUpClass

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def setUpClass(cls):
        super(StringTestCase, cls).setUpClass()
        cls.func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_unicode.py

示例14: test_with_prototype

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def test_with_prototype(self):
        # The _ctypes_test shared lib/dll exports quite some functions for testing.
        # The get_strchr function returns a *pointer* to the C strchr function.
        dll = CDLL(_ctypes_test.__file__)
        get_strchr = dll.get_strchr
        get_strchr.restype = CFUNCTYPE(c_char_p, c_char_p, c_char)
        strchr = get_strchr()
        self.assertEqual(strchr("abcdef", "b"), "bcdef")
        self.assertEqual(strchr("abcdef", "x"), None)
        self.assertRaises(ArgumentError, strchr, "abcdef", 3)
        self.assertRaises(TypeError, strchr, "abcdef") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_returnfuncptrs.py

示例15: test_without_prototype

# 需要导入模块: import _ctypes_test [as 别名]
# 或者: from _ctypes_test import __file__ [as 别名]
def test_without_prototype(self):
        dll = CDLL(_ctypes_test.__file__)
        get_strchr = dll.get_strchr
        # the default 'c_int' would not work on systems where sizeof(int) != sizeof(void *)
        get_strchr.restype = c_void_p
        addr = get_strchr()
        # _CFuncPtr instances are now callable with an integer argument
        # which denotes a function address:
        strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(addr)
        self.assertTrue(strchr("abcdef", "b"), "bcdef")
        self.assertEqual(strchr("abcdef", "x"), None)
        self.assertRaises(ArgumentError, strchr, "abcdef", 3)
        self.assertRaises(TypeError, strchr, "abcdef") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_returnfuncptrs.py


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