config root man

Current Path : /usr/local/lib/python2.5/ctypes/test/

FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64
Upload File :
Current File : //usr/local/lib/python2.5/ctypes/test/test_simplesubclasses.py

import unittest
from ctypes import *

class MyInt(c_int):
    def __cmp__(self, other):
        if type(other) != MyInt:
            return -1
        return cmp(self.value, other.value)

class Test(unittest.TestCase):

    def test_compare(self):
        self.failUnlessEqual(MyInt(3), MyInt(3))
        self.failIfEqual(MyInt(42), MyInt(43))

    def test_ignore_retval(self):
        # Test if the return value of a callback is ignored
        # if restype is None
        proto = CFUNCTYPE(None)
        def func():
            return (1, "abc", None)

        cb = proto(func)
        self.failUnlessEqual(None, cb())


    def test_int_callback(self):
        args = []
        def func(arg):
            args.append(arg)
            return arg

        cb = CFUNCTYPE(None, MyInt)(func)

        self.failUnlessEqual(None, cb(42))
        self.failUnlessEqual(type(args[-1]), MyInt)

        cb = CFUNCTYPE(c_int, c_int)(func)

        self.failUnlessEqual(42, cb(42))
        self.failUnlessEqual(type(args[-1]), int)

    def test_int_struct(self):
        class X(Structure):
            _fields_ = [("x", MyInt)]

        self.failUnlessEqual(X().x, MyInt())

        s = X()
        s.x = MyInt(42)

        self.failUnlessEqual(s.x, MyInt(42))

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

Man Man