1from Foundation import * 2from PyObjCTools.TestSupport import * 3import Foundation 4 5class TestHelper (NSObject): 6 def incFoo_(self, foo): 7 foo[0] += 1 8 9class TestNSUndoManager(TestCase): 10 def testUndoManager(self): 11 x = TestHelper.new() 12 m = NSUndoManager.new() 13 l = [ 0 ] 14 15 m.prepareWithInvocationTarget_(x).incFoo_(l) 16 m.undo() 17 18 self.assertEqual(l[0], 1) 19 20 def __del__(self, objc=objc): 21 objc.recycleAutoreleasePool() 22 23## Undo Integer test 24## From David Eppstein 25# test ability of int argument to pass through undo and then 26# be used as parameter to another routine expecting an int 27# 28# the actual routine I want to use is 29# NSTableView.editColumn_row_withEvent_select_ 30# but that involves setting up a UI; instead use NSIndexSpecifier 31 32if hasattr(Foundation, 'NSIndexSpecifier'): 33 class TestUndoInt(TestCase): 34 class UndoInt(NSObject): 35 undo = NSUndoManager.alloc().init() 36 idx = NSIndexSpecifier.alloc().init() 37 idx.setIndex_(0) 38 39 def test_(self,i): 40 self.undo.prepareWithInvocationTarget_(self).test_(self.idx.index()) 41 self.idx.setIndex_(i) 42 43 def testUndoInt(self): 44 # test that undo works 45 x = TestUndoInt.UndoInt.alloc().init() 46 x.test_(3) 47 assert(x.idx.index() == 3) 48 x.undo.undo() 49 assert(x.idx.index() == 0) 50## end Undo Integer test 51 52 53class TestSubclassingUndo(TestCase): 54 # Bugreport: 678759 Subclassing NSUndoManager fails 55 56 def testSubclass(self): 57 class UndoSubclass (NSUndoManager): 58 pass 59 60 x = TestHelper.new() 61 m = UndoSubclass.new() 62 l = [ 0 ] 63 64 m.prepareWithInvocationTarget_(x).incFoo_(l) 65 m.undo() 66 67 self.assertEqual(l[0], 1) 68 69 def testConstants(self): 70 self.assertIsInstance(NSUndoManagerCheckpointNotification, unicode) 71 self.assertIsInstance(NSUndoManagerWillUndoChangeNotification, unicode) 72 self.assertIsInstance(NSUndoManagerWillRedoChangeNotification, unicode) 73 self.assertIsInstance(NSUndoManagerDidUndoChangeNotification, unicode) 74 self.assertIsInstance(NSUndoManagerDidRedoChangeNotification, unicode) 75 self.assertIsInstance(NSUndoManagerDidOpenUndoGroupNotification, unicode) 76 self.assertIsInstance(NSUndoManagerWillCloseUndoGroupNotification, unicode) 77 self.assertEqual(NSUndoCloseGroupingRunLoopOrdering, 350000) 78 79 def testMethods(self): 80 self.assertResultIsBOOL(NSUndoManager.isUndoRegistrationEnabled) 81 self.assertResultIsBOOL(NSUndoManager.groupsByEvent) 82 self.assertArgIsBOOL(NSUndoManager.setGroupsByEvent_, 0) 83 self.assertResultIsBOOL(NSUndoManager.canUndo) 84 self.assertResultIsBOOL(NSUndoManager.canRedo) 85 self.assertResultIsBOOL(NSUndoManager.isUndoing) 86 self.assertResultIsBOOL(NSUndoManager.isRedoing) 87 self.assertArgIsSEL(NSUndoManager.registerUndoWithTarget_selector_object_, 1, b'v@:@') 88 89if __name__ == '__main__': 90 main( ) 91