1from PyObjCTools.TestSupport import * 2import AppKit 3from AppKit import * 4 5try: 6 unicode 7except NameError: 8 unicode = str 9 10class TestNSImageHelper (NSObject): 11 def image_didLoadRepresentation_withStatus_(self, i, r, s): pass 12 def image_didLoadPartOfRepresentation_withValidRows_(self, i, r, c): pass 13 14class TestNSImage (TestCase): 15 def test_compositePoint(self): 16 # comes straight from ReSTedit. Works on PPC, not on Intel (as of r1791) 17 ws = AppKit.NSWorkspace.sharedWorkspace() 18 txtIcon = ws.iconForFileType_("txt") 19 txtIcon.setSize_( (16,16) ) 20 htmlIcon = ws.iconForFileType_("html") 21 htmlIcon.setSize_( (16,16) ) 22 23 comboIcon = AppKit.NSImage.alloc().initWithSize_( (100,100) ) 24 comboIcon.lockFocus() 25 txtIcon.compositeToPoint_fromRect_operation_((0,0), ((0,0),(16,16)), AppKit.NSCompositeCopy) 26 htmlIcon.compositeToPoint_fromRect_operation_((8,0), ((8,0),(8,16)), AppKit.NSCompositeCopy) 27 comboIcon.unlockFocus() 28 29 def testConstants(self): 30 self.assertEqual(NSImageLoadStatusCompleted, 0) 31 self.assertEqual(NSImageLoadStatusCancelled, 1) 32 self.assertEqual(NSImageLoadStatusInvalidData, 2) 33 self.assertEqual(NSImageLoadStatusUnexpectedEOF, 3) 34 self.assertEqual(NSImageLoadStatusReadError, 4) 35 36 self.assertEqual(NSImageCacheDefault, 0) 37 self.assertEqual(NSImageCacheAlways, 1) 38 self.assertEqual(NSImageCacheBySize, 2) 39 self.assertEqual(NSImageCacheNever, 3) 40 41 42 @min_os_level("10.5") 43 def testConstants10_5(self): 44 self.assertIsInstance( NSImageNameQuickLookTemplate, unicode) 45 self.assertIsInstance( NSImageNameBluetoothTemplate, unicode) 46 self.assertIsInstance( NSImageNameIChatTheaterTemplate, unicode) 47 self.assertIsInstance( NSImageNameSlideshowTemplate, unicode) 48 self.assertIsInstance( NSImageNameActionTemplate, unicode) 49 self.assertIsInstance( NSImageNameSmartBadgeTemplate, unicode) 50 self.assertIsInstance( NSImageNameIconViewTemplate, unicode) 51 self.assertIsInstance( NSImageNameListViewTemplate, unicode) 52 self.assertIsInstance( NSImageNameColumnViewTemplate, unicode) 53 self.assertIsInstance( NSImageNameFlowViewTemplate, unicode) 54 self.assertIsInstance( NSImageNamePathTemplate, unicode) 55 self.assertIsInstance( NSImageNameInvalidDataFreestandingTemplate, unicode) 56 self.assertIsInstance( NSImageNameLockLockedTemplate, unicode) 57 self.assertIsInstance( NSImageNameLockUnlockedTemplate, unicode) 58 self.assertIsInstance( NSImageNameGoRightTemplate, unicode) 59 self.assertIsInstance( NSImageNameGoLeftTemplate, unicode) 60 self.assertIsInstance( NSImageNameRightFacingTriangleTemplate, unicode) 61 self.assertIsInstance( NSImageNameLeftFacingTriangleTemplate, unicode) 62 self.assertIsInstance( NSImageNameAddTemplate, unicode) 63 self.assertIsInstance( NSImageNameRemoveTemplate, unicode) 64 self.assertIsInstance( NSImageNameRevealFreestandingTemplate, unicode) 65 self.assertIsInstance( NSImageNameFollowLinkFreestandingTemplate, unicode) 66 self.assertIsInstance( NSImageNameEnterFullScreenTemplate, unicode) 67 self.assertIsInstance( NSImageNameExitFullScreenTemplate, unicode) 68 self.assertIsInstance( NSImageNameStopProgressTemplate, unicode) 69 self.assertIsInstance( NSImageNameStopProgressFreestandingTemplate, unicode) 70 self.assertIsInstance( NSImageNameRefreshTemplate, unicode) 71 self.assertIsInstance( NSImageNameRefreshFreestandingTemplate, unicode) 72 self.assertIsInstance( NSImageNameBonjour, unicode) 73 self.assertIsInstance( NSImageNameDotMac, unicode) 74 self.assertIsInstance( NSImageNameComputer, unicode) 75 self.assertIsInstance( NSImageNameFolderBurnable, unicode) 76 self.assertIsInstance( NSImageNameFolderSmart, unicode) 77 self.assertIsInstance( NSImageNameNetwork, unicode) 78 self.assertIsInstance( NSImageNameMultipleDocuments, unicode) 79 self.assertIsInstance( NSImageNameUserAccounts, unicode) 80 self.assertIsInstance( NSImageNamePreferencesGeneral, unicode) 81 self.assertIsInstance( NSImageNameAdvanced, unicode) 82 self.assertIsInstance( NSImageNameInfo, unicode) 83 self.assertIsInstance( NSImageNameFontPanel, unicode) 84 self.assertIsInstance( NSImageNameColorPanel, unicode) 85 self.assertIsInstance( NSImageNameUser, unicode) 86 self.assertIsInstance( NSImageNameUserGroup, unicode) 87 self.assertIsInstance( NSImageNameEveryone, unicode) 88 89 def testMethods(self): 90 self.assertResultIsBOOL(NSImage.setName_) 91 self.assertArgIsBOOL(NSImage.setScalesWhenResized_, 0) 92 self.assertResultIsBOOL(NSImage.scalesWhenResized) 93 self.assertArgIsBOOL(NSImage.setDataRetained_, 0) 94 self.assertResultIsBOOL(NSImage.isDataRetained) 95 self.assertArgIsBOOL(NSImage.setCachedSeparately_, 0) 96 self.assertResultIsBOOL(NSImage.isCachedSeparately) 97 self.assertArgIsBOOL(NSImage.setCacheDepthMatchesImageDepth_, 0) 98 self.assertResultIsBOOL(NSImage.cacheDepthMatchesImageDepth) 99 self.assertArgIsBOOL(NSImage.setUsesEPSOnResolutionMismatch_, 0) 100 self.assertResultIsBOOL(NSImage.usesEPSOnResolutionMismatch) 101 self.assertArgIsBOOL(NSImage.setPrefersColorMatch_, 0) 102 self.assertResultIsBOOL(NSImage.prefersColorMatch) 103 self.assertArgIsBOOL(NSImage.setMatchesOnMultipleResolution_, 0) 104 self.assertResultIsBOOL(NSImage.matchesOnMultipleResolution) 105 self.assertResultIsBOOL(NSImage.drawRepresentation_inRect_) 106 self.assertResultIsBOOL(NSImage.isValid) 107 self.assertResultIsBOOL(NSImage.canInitWithPasteboard_) 108 self.assertResultIsBOOL(NSImage.isFlipped) 109 self.assertArgIsBOOL(NSImage.setFlipped_, 0) 110 self.assertResultIsBOOL(NSImage.isTemplate) 111 self.assertArgIsBOOL(NSImage.setTemplate_, 0) 112 113 def testProtocols(self): 114 self.assertArgHasType(TestNSImageHelper.image_didLoadPartOfRepresentation_withValidRows_, 2, objc._C_NSInteger) 115 self.assertArgHasType(TestNSImageHelper.image_didLoadRepresentation_withStatus_, 2, objc._C_NSUInteger) 116 117 118 @min_os_level('10.6') 119 def testMethods10_6(self): 120 self.assertArgHasType(NSImage.drawInRect_fromRect_operation_fraction_respectFlipped_hints_, 121 0, NSRect.__typestr__) 122 self.assertArgIsBOOL(NSImage.drawInRect_fromRect_operation_fraction_respectFlipped_hints_, 4) 123 self.assertArgIsBOOL(NSImage.lockFocusFlipped_, 0) 124 self.assertArgHasType(NSImage.initWithCGImage_size_, 1, NSSize.__typestr__) 125 self.assertArgHasType(NSImage.CGImageForProposedRect_context_hints_, 0, b'o^' + NSRect.__typestr__) 126 self.assertArgHasType(NSImage.bestRepresentationForRect_context_hints_, 0, NSRect.__typestr__) 127 128 self.assertResultIsBOOL(NSImage.hitTestRect_withImageDestinationRect_context_hints_flipped_) 129 self.assertArgHasType(NSImage.hitTestRect_withImageDestinationRect_context_hints_flipped_, 0, NSRect.__typestr__) 130 self.assertArgHasType(NSImage.hitTestRect_withImageDestinationRect_context_hints_flipped_, 1, NSRect.__typestr__) 131 132 @min_os_level('10.7') 133 def testMethods10_7(self): 134 self.assertResultIsBOOL(NSImage.matchesOnlyOnBestFittingAxis) 135 self.assertArgIsBOOL(NSImage.setMatchesOnlyOnBestFittingAxis_, 0) 136 137 @min_os_level('10.8') 138 def testMethods10_8(self): 139 self.assertArgIsBOOL(NSImage.imageWithSize_flipped_drawingHandler_, 1) 140 self.assertArgIsBlock(NSImage.imageWithSize_flipped_drawingHandler_, 2, 141 objc._C_NSBOOL + NSRect.__typestr__) 142 143 144 @min_os_level('10.6') 145 def testConstants10_6(self): 146 self.assertIsInstance(NSImageHintCTM, unicode) 147 self.assertIsInstance(NSImageHintInterpolation, unicode) 148 self.assertIsInstance(NSImageNameFolder, unicode) 149 self.assertIsInstance(NSImageNameMobileMe, unicode) 150 self.assertIsInstance(NSImageNameUserGuest, unicode) 151 self.assertIsInstance(NSImageNameMenuOnStateTemplate, unicode) 152 self.assertIsInstance(NSImageNameMenuMixedStateTemplate, unicode) 153 self.assertIsInstance(NSImageNameApplicationIcon, unicode) 154 self.assertIsInstance(NSImageNameTrashEmpty, unicode) 155 self.assertIsInstance(NSImageNameTrashFull, unicode) 156 self.assertIsInstance(NSImageNameHomeTemplate, unicode) 157 self.assertIsInstance(NSImageNameBookmarksTemplate, unicode) 158 self.assertIsInstance(NSImageNameCaution, unicode) 159 self.assertIsInstance(NSImageNameStatusAvailable, unicode) 160 self.assertIsInstance(NSImageNameStatusPartiallyAvailable, unicode) 161 self.assertIsInstance(NSImageNameStatusUnavailable, unicode) 162 self.assertIsInstance(NSImageNameStatusNone, unicode) 163 164 @min_os_level('10.8') 165 def testConstants10_8(self): 166 self.assertIsInstance(NSImageNameShareTemplate, unicode) 167 168if __name__ == "__main__": 169 main() 170