1from Foundation import * 2from PyObjCTools.TestSupport import * 3 4try: 5 unicode 6except NameError: 7 unicode = str 8 9 10class TestNSURL (TestCase): 11 def testMethods(self): 12 self.assertArgIsBOOL(NSURL.initFileURLWithPath_isDirectory_, 1) 13 self.assertArgIsBOOL(NSURL.fileURLWithPath_isDirectory_, 1) 14 self.assertResultIsBOOL(NSURL.isFileURL) 15 16 self.assertArgIsBOOL(NSURL.resourceDataUsingCache_, 0) 17 self.assertArgIsBOOL(NSURL.loadResourceDataNotifyingClient_usingCache_, 1) 18 self.assertResultIsBOOL(NSURL.setResourceData_) 19 self.assertResultIsBOOL(NSURL.setProperty_forKey_) 20 self.assertArgIsBOOL(NSURL.URLHandleUsingCache_, 0) 21 22 def testConstants(self): 23 self.assertIsInstance(NSURLFileScheme, unicode) 24 25 @min_os_level('10.6') 26 def testConstants10_6(self): 27 self.assertEqual(NSURLBookmarkCreationPreferFileIDResolution, ( 1 << 8 )) 28 self.assertEqual(NSURLBookmarkCreationMinimalBookmark, ( 1 << 9 )) 29 self.assertEqual(NSURLBookmarkCreationSuitableForBookmarkFile, ( 1 << 10 )) 30 self.assertEqual(NSURLBookmarkResolutionWithoutUI, ( 1 << 8 )) 31 self.assertEqual(NSURLBookmarkResolutionWithoutMounting, ( 1 << 9 )) 32 33 self.assertIsInstance(NSURLNameKey, unicode) 34 self.assertIsInstance(NSURLLocalizedNameKey, unicode) 35 self.assertIsInstance(NSURLIsRegularFileKey, unicode) 36 self.assertIsInstance(NSURLIsDirectoryKey, unicode) 37 self.assertIsInstance(NSURLIsSymbolicLinkKey, unicode) 38 self.assertIsInstance(NSURLIsVolumeKey, unicode) 39 self.assertIsInstance(NSURLIsPackageKey, unicode) 40 self.assertIsInstance(NSURLIsSystemImmutableKey, unicode) 41 self.assertIsInstance(NSURLIsUserImmutableKey, unicode) 42 self.assertIsInstance(NSURLIsHiddenKey, unicode) 43 self.assertIsInstance(NSURLHasHiddenExtensionKey, unicode) 44 self.assertIsInstance(NSURLCreationDateKey, unicode) 45 self.assertIsInstance(NSURLContentAccessDateKey, unicode) 46 self.assertIsInstance(NSURLContentModificationDateKey, unicode) 47 self.assertIsInstance(NSURLAttributeModificationDateKey, unicode) 48 self.assertIsInstance(NSURLLinkCountKey, unicode) 49 self.assertIsInstance(NSURLParentDirectoryURLKey, unicode) 50 self.assertIsInstance(NSURLVolumeURLKey, unicode) 51 self.assertIsInstance(NSURLTypeIdentifierKey, unicode) 52 self.assertIsInstance(NSURLLocalizedTypeDescriptionKey, unicode) 53 self.assertIsInstance(NSURLLabelNumberKey, unicode) 54 self.assertIsInstance(NSURLLabelColorKey, unicode) 55 self.assertIsInstance(NSURLLocalizedLabelKey, unicode) 56 self.assertIsInstance(NSURLEffectiveIconKey, unicode) 57 self.assertIsInstance(NSURLCustomIconKey, unicode) 58 self.assertIsInstance(NSURLFileSizeKey, unicode) 59 self.assertIsInstance(NSURLFileAllocatedSizeKey, unicode) 60 self.assertIsInstance(NSURLIsAliasFileKey, unicode) 61 self.assertIsInstance(NSURLVolumeLocalizedFormatDescriptionKey, unicode) 62 self.assertIsInstance(NSURLVolumeTotalCapacityKey, unicode) 63 self.assertIsInstance(NSURLVolumeAvailableCapacityKey, unicode) 64 self.assertIsInstance(NSURLVolumeResourceCountKey, unicode) 65 66 @min_os_level('10.6') 67 def testConstants10_6_2(self): 68 self.assertIsInstance(NSURLVolumeSupportsPersistentIDsKey, unicode) 69 self.assertIsInstance(NSURLVolumeSupportsSymbolicLinksKey, unicode) 70 self.assertIsInstance(NSURLVolumeSupportsHardLinksKey, unicode) 71 self.assertIsInstance(NSURLVolumeSupportsJournalingKey, unicode) 72 self.assertIsInstance(NSURLVolumeIsJournalingKey, unicode) 73 self.assertIsInstance(NSURLVolumeSupportsSparseFilesKey, unicode) 74 self.assertIsInstance(NSURLVolumeSupportsZeroRunsKey, unicode) 75 self.assertIsInstance(NSURLVolumeSupportsCaseSensitiveNamesKey, unicode) 76 self.assertIsInstance(NSURLVolumeSupportsCasePreservedNamesKey, unicode) 77 78 @min_os_level('10.7') 79 def testConstants10_7(self): 80 self.assertIsInstance(NSURLKeysOfUnsetValuesKey, unicode) 81 82 self.assertIsInstance(NSURLFileResourceIdentifierKey, unicode) 83 self.assertIsInstance(NSURLVolumeIdentifierKey, unicode) 84 self.assertIsInstance(NSURLPreferredIOBlockSizeKey, unicode) 85 self.assertIsInstance(NSURLIsReadableKey, unicode) 86 self.assertIsInstance(NSURLIsWritableKey, unicode) 87 self.assertIsInstance(NSURLIsExecutableKey, unicode) 88 self.assertIsInstance(NSURLIsMountTriggerKey, unicode) 89 self.assertIsInstance(NSURLFileSecurityKey, unicode) 90 self.assertIsInstance(NSURLFileResourceTypeKey, unicode) 91 self.assertIsInstance(NSURLFileResourceTypeNamedPipe, unicode) 92 self.assertIsInstance(NSURLFileResourceTypeCharacterSpecial, unicode) 93 self.assertIsInstance(NSURLFileResourceTypeDirectory, unicode) 94 self.assertIsInstance(NSURLFileResourceTypeBlockSpecial, unicode) 95 self.assertIsInstance(NSURLFileResourceTypeRegular, unicode) 96 self.assertIsInstance(NSURLFileResourceTypeSymbolicLink, unicode) 97 self.assertIsInstance(NSURLFileResourceTypeSocket, unicode) 98 self.assertIsInstance(NSURLFileResourceTypeUnknown, unicode) 99 self.assertIsInstance(NSURLTotalFileSizeKey, unicode) 100 self.assertIsInstance(NSURLTotalFileAllocatedSizeKey, unicode) 101 self.assertIsInstance(NSURLVolumeSupportsRootDirectoryDatesKey, unicode) 102 self.assertIsInstance(NSURLVolumeSupportsVolumeSizesKey, unicode) 103 self.assertIsInstance(NSURLVolumeSupportsRenamingKey, unicode) 104 self.assertIsInstance(NSURLVolumeSupportsAdvisoryFileLockingKey, unicode) 105 self.assertIsInstance(NSURLVolumeSupportsExtendedSecurityKey, unicode) 106 self.assertIsInstance(NSURLVolumeIsBrowsableKey, unicode) 107 self.assertIsInstance(NSURLVolumeMaximumFileSizeKey, unicode) 108 self.assertIsInstance(NSURLVolumeIsEjectableKey, unicode) 109 self.assertIsInstance(NSURLVolumeIsRemovableKey, unicode) 110 self.assertIsInstance(NSURLVolumeIsInternalKey, unicode) 111 self.assertIsInstance(NSURLVolumeIsAutomountedKey, unicode) 112 self.assertIsInstance(NSURLVolumeIsLocalKey, unicode) 113 self.assertIsInstance(NSURLVolumeIsReadOnlyKey, unicode) 114 self.assertIsInstance(NSURLVolumeCreationDateKey, unicode) 115 self.assertIsInstance(NSURLVolumeURLForRemountingKey, unicode) 116 self.assertIsInstance(NSURLVolumeUUIDStringKey, unicode) 117 self.assertIsInstance(NSURLVolumeNameKey, unicode) 118 self.assertIsInstance(NSURLVolumeLocalizedNameKey, unicode) 119 self.assertIsInstance(NSURLIsUbiquitousItemKey, unicode) 120 self.assertIsInstance(NSURLUbiquitousItemHasUnresolvedConflictsKey, unicode) 121 self.assertIsInstance(NSURLUbiquitousItemIsDownloadedKey, unicode) 122 self.assertIsInstance(NSURLUbiquitousItemIsDownloadingKey, unicode) 123 self.assertIsInstance(NSURLUbiquitousItemIsUploadedKey, unicode) 124 self.assertIsInstance(NSURLUbiquitousItemIsUploadingKey, unicode) 125 self.assertIsInstance(NSURLUbiquitousItemPercentDownloadedKey, unicode) 126 self.assertIsInstance(NSURLUbiquitousItemPercentUploadedKey, unicode) 127 128 @min_os_level('10.8') 129 def testConstants10_8(self): 130 self.assertIsInstance(NSURLIsExcludedFromBackupKey, unicode) 131 self.assertIsInstance(NSURLPathKey, unicode) 132 133 @min_os_level('10.6') 134 def testMethods10_6(self): 135 self.assertArgIsBOOL(NSURL.URLByAppendingPathComponent_isDirectory_, 1) 136 137 self.assertResultIsBOOL(NSURL.getResourceValue_forKey_error_) 138 self.assertArgIsOut(NSURL.getResourceValue_forKey_error_, 0) 139 self.assertArgIsOut(NSURL.getResourceValue_forKey_error_, 2) 140 self.assertArgIsOut(NSURL.resourceValuesForKeys_error_, 1) 141 self.assertResultIsBOOL(NSURL.setResourceValue_forKey_error_) 142 self.assertArgIsOut(NSURL.setResourceValue_forKey_error_, 2) 143 self.assertResultIsBOOL(NSURL.setResourceValues_error_) 144 self.assertArgIsOut(NSURL.setResourceValues_error_, 1) 145 self.assertResultIsBOOL(NSURL.checkResourceIsReachableAndReturnError_) 146 self.assertArgIsOut(NSURL.checkResourceIsReachableAndReturnError_, 0) 147 self.assertResultIsBOOL(NSURL.isFileReferenceURL) 148 149 self.assertArgIsOut(NSURL.bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error_, 3) 150 self.assertArgHasType(NSURL.initByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_, 3, b'o^' + objc._C_NSBOOL) 151 self.assertArgIsOut(NSURL.initByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_, 4) 152 self.assertArgHasType(NSURL.URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_, 3, b'o^' + objc._C_NSBOOL) 153 self.assertArgIsOut(NSURL.URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_, 4) 154 self.assertResultIsBOOL(NSURL.writeBookmarkData_toURL_options_error_) 155 self.assertArgIsOut(NSURL.writeBookmarkData_toURL_options_error_, 3) 156 self.assertArgIsOut(NSURL.bookmarkDataWithContentsOfURL_error_, 1) 157 158if __name__ == "__main__": 159 main() 160