test_nsundomanager.py :  » Development » PyObjC » trunk » pyobjc » pyobjc-framework-Cocoa » 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 framework Cocoa » PyObjCTest » test_nsundomanager.py
from Foundation import *
from PyObjCTools.TestSupport import *
import Foundation

class TestHelper (NSObject):
    def incFoo_(self, foo):
        foo[0] += 1

class TestNSUndoManager(TestCase):
    def testUndoManager(self):
        x = TestHelper.new()
        m = NSUndoManager.new()
        l = [ 0 ]

        m.prepareWithInvocationTarget_(x).incFoo_(l)
        m.undo()

        self.assertEqual(l[0], 1)

    def __del__(self, objc=objc):
        objc.recycleAutoreleasePool()

## Undo Integer test
## From David Eppstein
# test ability of int argument to pass through undo and then
# be used as parameter to another routine expecting an int
#
# the actual routine I want to use is
# NSTableView.editColumn_row_withEvent_select_
# but that involves setting up a UI; instead use NSIndexSpecifier

if hasattr(Foundation, 'NSIndexSpecifier'):
    class TestUndoInt(TestCase):
        class UndoInt(NSObject):
            undo = NSUndoManager.alloc().init()
            idx = NSIndexSpecifier.alloc().init()
            idx.setIndex_(0)

            def test_(self,i):
                self.undo.prepareWithInvocationTarget_(self).test_(self.idx.index())
                self.idx.setIndex_(i)

        def testUndoInt(self):
            # test that undo works
            x = TestUndoInt.UndoInt.alloc().init()
            x.test_(3)
            assert(x.idx.index() == 3)
            x.undo.undo()
            assert(x.idx.index() == 0)
## end Undo Integer test


class TestSubclassingUndo(TestCase):
    # Bugreport: 678759 Subclassing NSUndoManager fails

    def testSubclass(self):
        class UndoSubclass (NSUndoManager):
            pass

        x = TestHelper.new()
        m = UndoSubclass.new()
        l = [ 0 ]

        m.prepareWithInvocationTarget_(x).incFoo_(l)
        m.undo()

        self.assertEqual(l[0], 1)

    def testConstants(self):
        self.assertIsInstance(NSUndoManagerCheckpointNotification, unicode)
        self.assertIsInstance(NSUndoManagerWillUndoChangeNotification, unicode)
        self.assertIsInstance(NSUndoManagerWillRedoChangeNotification, unicode)
        self.assertIsInstance(NSUndoManagerDidUndoChangeNotification, unicode)
        self.assertIsInstance(NSUndoManagerDidRedoChangeNotification, unicode)
        self.assertIsInstance(NSUndoManagerDidOpenUndoGroupNotification, unicode)
        self.assertIsInstance(NSUndoManagerWillCloseUndoGroupNotification, unicode)
        self.assertEqual(NSUndoCloseGroupingRunLoopOrdering, 350000)

    def testMethods(self):
        self.assertResultIsBOOL(NSUndoManager.isUndoRegistrationEnabled)
        self.assertResultIsBOOL(NSUndoManager.groupsByEvent)
        self.assertArgIsBOOL(NSUndoManager.setGroupsByEvent_, 0)
        self.assertResultIsBOOL(NSUndoManager.canUndo)
        self.assertResultIsBOOL(NSUndoManager.canRedo)
        self.assertResultIsBOOL(NSUndoManager.isUndoing)
        self.assertResultIsBOOL(NSUndoManager.isRedoing)
        self.assertArgIsSEL(NSUndoManager.registerUndoWithTarget_selector_object_, 1, b'v@:@')

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.