test_splitsig.py :  » Development » PyObjC » trunk » pyobjc » pyobjc-core » PyObjCTest » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » PyObjC 
PyObjC » trunk » pyobjc » pyobjc core » PyObjCTest » test_splitsig.py
from PyObjCTools.TestSupport import *
import objc



gDict = {}

"""
try:
    import Foundation
except ImportError:
    pass

try:
    import AppKit
except ImportError:
    pass

try:
    import PreferencePanes
except ImportError:
    pass

try:
    import ScreenSaver
except ImportError:
    pass

try:
    import InterfaceBuilder
except ImportError:
    pass

try:
    import WebKit
except ImportError:
    pass
"""

import sys


class SplitSignatureTest (TestCase):

    def testSplitSignature(self):
    # This is a very expensive test, with 1 goal: Verify that all method
    # signatures, and therefore all signatures changed by PyObjC, are
    # valid.
        for cls in objc.getClassList():
            for selName in cls.__dict__.keys():
                try:
                    sel = getattr(cls, selName.decode('latin1'))
                except AttributeError:
                    continue

                if not isinstance(sel, objc.selector): continue
                elems = objc.splitSignature(sel.signature)


    def testSimple(self):
        self.assertEquals(objc.splitSignature(b"@:@"), (b'@',b':',b'@'))
        self.assertEquals(objc.splitSignature(b"@:10{NSRect=ff}"), (b'@',b':',b'{NSRect=ff}'))
        self.assertEquals(objc.splitSignature(b"@:o^@"), (b'@',b':',b'o^@'))

        # Block pointer
        self.assertEquals(objc.splitSignature(b"@:@?"), (b'@',b':',b'@?'))

        # struct definition in an struct objc_ivar
        self.assertEquals(objc.splitSignature(b'{_NSRect="origin"{_NSPoint="x"f"y"f}"size"{_NSSize="width"f"height"f}}'), (b'{_NSRect="origin"{_NSPoint="x"f"y"f}"size"{_NSSize="width"f"height"f}}',))

    def testSignatureCount(self):
        EXCEPTIONS=[

            # For some reason this signature doesn't seem to be correct, even
            # though we don't touch it...
            "initWithDocument_URL_windowProperties_locationProperties_interpreterBuiltins_",
            
            # Some unittests...
            "setKey4",
            "get_key2",
            "read_bar",
            "setFoo_",
            "method_with_embedded_underscores",
            "methodWithArg_",
            "myMethod",
            "twoargs",
            "set_helper",

            # dictionary methods
            "get",
            "has_key",
        ]

        for cls in objc.getClassList():
            #if cls.__name__.startswith('OC_'): continue
            if cls.__name__.startswith('OC'): continue
            for selName in cls.__dict__.keys():
                self.assertIsInstance(selName, str)
                if selName in EXCEPTIONS: continue
                if selName.startswith('__') and selName.endswith('__'): continue

                try:
                    sel = getattr(cls, selName)
                except AttributeError:
                    continue

                if not isinstance(sel, objc.selector): continue
                elems = objc.splitSignature(sel.signature)

                argcount = len(elems) - 3 # retval, self, _sel
                coloncount = sel.selector.count(b':')

                self.assertEquals(argcount, coloncount, 
                        '%s [%d:%d] %r %r'%(sel.selector.decode('latin1'), argcount, coloncount, elems, cls))


if __name__ == "__main__":
    main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.