✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ beluga.o2switch.net ​🇻​♯➤ 4.18.0-553.123.2.lve.el8.x86_64 #1 SMP 🇾​♯➤ 2026

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 185.154.139.77 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.216.84
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗙𝗙 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ 𝗔𝗟𝗟 𝗪𝗢𝗥𝗞𝗜𝗡𝗚....

𝗛𝗢𝗠𝗘
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /opt/alt/python33/lib64/python3.3/ctypes/test//test_as_parameter.py
import unittest
from ctypes import *
import _ctypes_test

dll = CDLL(_ctypes_test.__file__)

try:
    CALLBACK_FUNCTYPE = WINFUNCTYPE
except NameError:
    # fake to enable this test on Linux
    CALLBACK_FUNCTYPE = CFUNCTYPE

class POINT(Structure):
    _fields_ = [("x", c_int), ("y", c_int)]

class BasicWrapTestCase(unittest.TestCase):
    def wrap(self, param):
        return param

    def test_wchar_parm(self):
        try:
            c_wchar
        except NameError:
            return
        f = dll._testfunc_i_bhilfd
        f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double]
        result = f(self.wrap(1), self.wrap("x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0))
        self.assertEqual(result, 139)
        self.assertTrue(type(result), int)

    def test_pointers(self):
        f = dll._testfunc_p_p
        f.restype = POINTER(c_int)
        f.argtypes = [POINTER(c_int)]

        # This only works if the value c_int(42) passed to the
        # function is still alive while the pointer (the result) is
        # used.

        v = c_int(42)

        self.assertEqual(pointer(v).contents.value, 42)
        result = f(self.wrap(pointer(v)))
        self.assertEqual(type(result), POINTER(c_int))
        self.assertEqual(result.contents.value, 42)

        # This on works...
        result = f(self.wrap(pointer(v)))
        self.assertEqual(result.contents.value, v.value)

        p = pointer(c_int(99))
        result = f(self.wrap(p))
        self.assertEqual(result.contents.value, 99)

    def test_shorts(self):
        f = dll._testfunc_callback_i_if

        args = []
        expected = [262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048,
                    1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1]

        def callback(v):
            args.append(v)
            return v

        CallBack = CFUNCTYPE(c_int, c_int)

        cb = CallBack(callback)
        f(self.wrap(2**18), self.wrap(cb))
        self.assertEqual(args, expected)

    ################################################################

    def test_callbacks(self):
        f = dll._testfunc_callback_i_if
        f.restype = c_int
        f.argtypes = None

        MyCallback = CFUNCTYPE(c_int, c_int)

        def callback(value):
            #print "called back with", value
            return value

        cb = MyCallback(callback)

        result = f(self.wrap(-10), self.wrap(cb))
        self.assertEqual(result, -18)

        # test with prototype
        f.argtypes = [c_int, MyCallback]
        cb = MyCallback(callback)

        result = f(self.wrap(-10), self.wrap(cb))
        self.assertEqual(result, -18)

        result = f(self.wrap(-10), self.wrap(cb))
        self.assertEqual(result, -18)

        AnotherCallback = CALLBACK_FUNCTYPE(c_int, c_int, c_int, c_int, c_int)

        # check that the prototype works: we call f with wrong
        # argument types
        cb = AnotherCallback(callback)
        self.assertRaises(ArgumentError, f, self.wrap(-10), self.wrap(cb))

    def test_callbacks_2(self):
        # Can also use simple datatypes as argument type specifiers
        # for the callback function.
        # In this case the call receives an instance of that type
        f = dll._testfunc_callback_i_if
        f.restype = c_int

        MyCallback = CFUNCTYPE(c_int, c_int)

        f.argtypes = [c_int, MyCallback]

        def callback(value):
            #print "called back with", value
            self.assertEqual(type(value), int)
            return value

        cb = MyCallback(callback)
        result = f(self.wrap(-10), self.wrap(cb))
        self.assertEqual(result, -18)

    def test_longlong_callbacks(self):

        f = dll._testfunc_callback_q_qf
        f.restype = c_longlong

        MyCallback = CFUNCTYPE(c_longlong, c_longlong)

        f.argtypes = [c_longlong, MyCallback]

        def callback(value):
            self.assertIsInstance(value, int)
            return value & 0x7FFFFFFF

        cb = MyCallback(callback)

        self.assertEqual(13577625587, int(f(self.wrap(1000000000000), self.wrap(cb))))

    def test_byval(self):
        # without prototype
        ptin = POINT(1, 2)
        ptout = POINT()
        # EXPORT int _testfunc_byval(point in, point *pout)
        result = dll._testfunc_byval(ptin, byref(ptout))
        got = result, ptout.x, ptout.y
        expected = 3, 1, 2
        self.assertEqual(got, expected)

        # with prototype
        ptin = POINT(101, 102)
        ptout = POINT()
        dll._testfunc_byval.argtypes = (POINT, POINTER(POINT))
        dll._testfunc_byval.restype = c_int
        result = dll._testfunc_byval(self.wrap(ptin), byref(ptout))
        got = result, ptout.x, ptout.y
        expected = 203, 101, 102
        self.assertEqual(got, expected)

    def test_struct_return_2H(self):
        class S2H(Structure):
            _fields_ = [("x", c_short),
                        ("y", c_short)]
        dll.ret_2h_func.restype = S2H
        dll.ret_2h_func.argtypes = [S2H]
        inp = S2H(99, 88)
        s2h = dll.ret_2h_func(self.wrap(inp))
        self.assertEqual((s2h.x, s2h.y), (99*2, 88*3))

    def test_struct_return_8H(self):
        class S8I(Structure):
            _fields_ = [("a", c_int),
                        ("b", c_int),
                        ("c", c_int),
                        ("d", c_int),
                        ("e", c_int),
                        ("f", c_int),
                        ("g", c_int),
                        ("h", c_int)]
        dll.ret_8i_func.restype = S8I
        dll.ret_8i_func.argtypes = [S8I]
        inp = S8I(9, 8, 7, 6, 5, 4, 3, 2)
        s8i = dll.ret_8i_func(self.wrap(inp))
        self.assertEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h),
                             (9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9))

    def test_recursive_as_param(self):
        from ctypes import c_int

        class A(object):
            pass

        a = A()
        a._as_parameter_ = a
        with self.assertRaises(RuntimeError):
            c_int.from_param(a)


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class AsParamWrapper(object):
    def __init__(self, param):
        self._as_parameter_ = param

class AsParamWrapperTestCase(BasicWrapTestCase):
    wrap = AsParamWrapper

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class AsParamPropertyWrapper(object):
    def __init__(self, param):
        self._param = param

    def getParameter(self):
        return self._param
    _as_parameter_ = property(getParameter)

class AsParamPropertyWrapperTestCase(BasicWrapTestCase):
    wrap = AsParamPropertyWrapper

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if __name__ == '__main__':
    unittest.main()


Current_dir [ 𝗡𝗢𝗧 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
25 Jul 2024 8.41 AM
root / linksafe
0755
__pycache__
--
25 Jul 2024 8.41 AM
root / linksafe
0755
__init__.py
6.979 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
runtests.py
0.666 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_anon.py
2.003 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_array_in_pointer.py
1.697 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_arrays.py
5.536 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_as_parameter.py
6.625 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_bitfields.py
9.08 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_buffers.py
2.178 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_bytes.py
1.162 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_byteswap.py
10.567 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_callbacks.py
8.773 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_cast.py
3.135 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_cfuncs.py
7.442 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_checkretval.py
0.972 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_delattr.py
0.521 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_errcheck.py
0.466 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_errno.py
2.248 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_find.py
2.412 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_frombuffer.py
2.423 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_funcptr.py
3.819 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_functions.py
12.348 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_incomplete.py
0.999 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_init.py
1.015 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_integers.py
0.094 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_internals.py
2.564 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_keeprefs.py
3.928 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_libc.py
0.981 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_loading.py
3.997 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_macholib.py
1.556 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_memfunctions.py
3.239 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_numbers.py
9.003 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_objects.py
1.724 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_parameters.py
6.16 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_pep3118.py
7.348 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_pickling.py
2.148 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_pointers.py
6.119 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_prototypes.py
6.625 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_python_api.py
3.067 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_random_things.py
2.766 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_refcounts.py
2.516 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_repr.py
0.822 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_returnfuncptrs.py
2.835 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_simplesubclasses.py
1.259 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_sizes.py
0.796 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_slicing.py
5.95 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_stringptr.py
2.477 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_strings.py
6.94 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_struct_fields.py
1.468 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_structures.py
15.431 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_unaligned_structures.py
1.187 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_unicode.py
1.866 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_values.py
3.427 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_varsize_struct.py
1.799 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_win32.py
3.96 KB
17 Apr 2024 4.58 PM
root / linksafe
0644
test_wintypes.py
1.438 KB
17 Apr 2024 4.58 PM
root / linksafe
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF