1 2from PyObjCTools.TestSupport import * 3from AppKit import * 4 5class TestNSTextHelper (NSObject): 6 def textShouldBeginEditing_(self, t): return 1 7 def textShouldEndEditing_(self, t): return 1 8 9class TestNSText (TestCase): 10 def testConstants(self): 11 self.assertEqual(NSEnterCharacter, unichr(0x0003)) 12 self.assertEqual(NSBackspaceCharacter, unichr(0x0008)) 13 self.assertEqual(NSTabCharacter, unichr(0x0009)) 14 self.assertEqual(NSNewlineCharacter, unichr(0x000a)) 15 self.assertEqual(NSFormFeedCharacter, unichr(0x000c)) 16 self.assertEqual(NSCarriageReturnCharacter, unichr(0x000d)) 17 self.assertEqual(NSBackTabCharacter, unichr(0x0019)) 18 self.assertEqual(NSDeleteCharacter, unichr(0x007f)) 19 self.assertEqual(NSLineSeparatorCharacter, unichr(0x2028)) 20 self.assertEqual(NSParagraphSeparatorCharacter, unichr(0x2029)) 21 self.assertEqual(NSLeftTextAlignment, 0) 22 self.assertEqual(NSRightTextAlignment, 1) 23 self.assertEqual(NSCenterTextAlignment, 2) 24 self.assertEqual(NSJustifiedTextAlignment, 3) 25 self.assertEqual(NSNaturalTextAlignment, 4) 26 27 self.assertEqual(NSWritingDirectionNatural, -1) 28 self.assertEqual(NSWritingDirectionLeftToRight, 0) 29 self.assertEqual(NSWritingDirectionRightToLeft, 1) 30 31 self.assertEqual(NSIllegalTextMovement, 0) 32 self.assertEqual(NSReturnTextMovement, 0x10) 33 self.assertEqual(NSTabTextMovement, 0x11) 34 self.assertEqual(NSBacktabTextMovement, 0x12) 35 self.assertEqual(NSLeftTextMovement, 0x13) 36 self.assertEqual(NSRightTextMovement, 0x14) 37 self.assertEqual(NSUpTextMovement, 0x15) 38 self.assertEqual(NSDownTextMovement, 0x16) 39 self.assertEqual(NSCancelTextMovement, 0x17) 40 self.assertEqual(NSOtherTextMovement, 0) 41 42 self.assertIsInstance(NSTextDidBeginEditingNotification, unicode) 43 self.assertIsInstance(NSTextDidEndEditingNotification, unicode) 44 self.assertIsInstance(NSTextDidChangeNotification, unicode) 45 46 @min_os_level('10.6') 47 def testConstants10_6(self): 48 self.assertEqual(NSTextWritingDirectionEmbedding, 0<<1) 49 self.assertEqual(NSTextWritingDirectionOverride, 1<<1) 50 51 def testMehods(self): 52 self.assertResultIsBOOL(NSText.writeRTFDToFile_atomically_) 53 self.assertArgIsBOOL(NSText.writeRTFDToFile_atomically_, 1) 54 self.assertResultIsBOOL(NSText.readRTFDFromFile_) 55 self.assertResultIsBOOL(NSText.isEditable) 56 self.assertArgIsBOOL(NSText.setEditable_, 0) 57 self.assertResultIsBOOL(NSText.isSelectable) 58 self.assertArgIsBOOL(NSText.setSelectable_, 0) 59 self.assertResultIsBOOL(NSText.isRichText) 60 self.assertArgIsBOOL(NSText.setRichText_, 0) 61 self.assertResultIsBOOL(NSText.importsGraphics) 62 self.assertArgIsBOOL(NSText.setImportsGraphics_, 0) 63 self.assertResultIsBOOL(NSText.isFieldEditor) 64 self.assertArgIsBOOL(NSText.setFieldEditor_, 0) 65 self.assertResultIsBOOL(NSText.usesFontPanel) 66 self.assertArgIsBOOL(NSText.setUsesFontPanel_, 0) 67 self.assertResultIsBOOL(NSText.drawsBackground) 68 self.assertArgIsBOOL(NSText.setDrawsBackground_, 0) 69 self.assertResultIsBOOL(NSText.isRulerVisible) 70 self.assertResultIsBOOL(NSText.isHorizontallyResizable) 71 self.assertArgIsBOOL(NSText.setHorizontallyResizable_, 0) 72 self.assertResultIsBOOL(NSText.isVerticallyResizable) 73 self.assertArgIsBOOL(NSText.setVerticallyResizable_, 0) 74 75 def testProtocols(self): 76 self.assertResultIsBOOL(TestNSTextHelper.textShouldBeginEditing_) 77 self.assertResultIsBOOL(TestNSTextHelper.textShouldEndEditing_) 78 79if __name__ == "__main__": 80 main() 81