1from PyObjCTools.TestSupport import * 2 3from Foundation import * 4 5class TestNSFileManagerHelper (NSObject): 6 def fileManager_shouldProceedAfterError_(self, a, b): return 1 7 def fileManager_willProcessPath_(self, a, b): pass 8 def fileManager_shouldCopyItemAtPath_toPath_(self, a, b, c): return 1 9 def fileManager_shouldProceedAfterError_copyingItemAtPath_toPath_(self, a, b, c, d): return 1 10 def fileManager_shouldMoveItemAtPath_toPath_(self, a, b, c): return 1 11 def fileManager_shouldProceedAfterError_movingItemAtPath_toPath_(self, a, b, c, d): return 1 12 def fileManager_shouldLinkItemAtPath_toPath_(self, a, b, c): return 1 13 def fileManager_shouldProceedAfterError_linkingItemAtPath_toPath_(self, a, b, c, d): return 1 14 def fileManager_shouldRemoveItemAtPath_(self, a, b): return 1 15 def fileManager_shouldProceedAfterError_removingItemAtPath_(self, a, b, c): return 1 16 17 18 19class TestNSFileManager (TestCase): 20 def testConstants(self): 21 self.assertEquals(NSFoundationVersionWithFileManagerResourceForkSupport, 412) 22 23 self.failUnless( isinstance(NSFileType, unicode) ) 24 self.failUnless( isinstance(NSFileTypeDirectory, unicode) ) 25 self.failUnless( isinstance(NSFileTypeRegular, unicode) ) 26 self.failUnless( isinstance(NSFileTypeSymbolicLink, unicode) ) 27 self.failUnless( isinstance(NSFileTypeSocket, unicode) ) 28 self.failUnless( isinstance(NSFileTypeCharacterSpecial, unicode) ) 29 self.failUnless( isinstance(NSFileTypeBlockSpecial, unicode) ) 30 self.failUnless( isinstance(NSFileTypeUnknown, unicode) ) 31 self.failUnless( isinstance(NSFileSize, unicode) ) 32 self.failUnless( isinstance(NSFileModificationDate, unicode) ) 33 self.failUnless( isinstance(NSFileReferenceCount, unicode) ) 34 self.failUnless( isinstance(NSFileDeviceIdentifier, unicode) ) 35 self.failUnless( isinstance(NSFileOwnerAccountName, unicode) ) 36 self.failUnless( isinstance(NSFileGroupOwnerAccountName, unicode) ) 37 self.failUnless( isinstance(NSFilePosixPermissions, unicode) ) 38 self.failUnless( isinstance(NSFileSystemNumber, unicode) ) 39 self.failUnless( isinstance(NSFileSystemFileNumber, unicode) ) 40 self.failUnless( isinstance(NSFileExtensionHidden, unicode) ) 41 self.failUnless( isinstance(NSFileHFSCreatorCode, unicode) ) 42 self.failUnless( isinstance(NSFileHFSTypeCode, unicode) ) 43 self.failUnless( isinstance(NSFileImmutable, unicode) ) 44 self.failUnless( isinstance(NSFileAppendOnly, unicode) ) 45 self.failUnless( isinstance(NSFileCreationDate, unicode) ) 46 self.failUnless( isinstance(NSFileOwnerAccountID, unicode) ) 47 self.failUnless( isinstance(NSFileGroupOwnerAccountID, unicode) ) 48 self.failUnless( isinstance(NSFileBusy, unicode) ) 49 self.failUnless( isinstance(NSFileSystemSize, unicode) ) 50 self.failUnless( isinstance(NSFileSystemFreeSize, unicode) ) 51 self.failUnless( isinstance(NSFileSystemNodes, unicode) ) 52 self.failUnless( isinstance(NSFileSystemFreeNodes, unicode) ) 53 54 def testOutput(self): 55 obj = NSFileManager.defaultManager() 56 m = obj.setAttributes_ofItemAtPath_error_.__metadata__() 57 self.failUnless(m['arguments'][4]['type'].startswith('o^')) 58 59 m = obj.createDirectoryAtPath_withIntermediateDirectories_attributes_error_.__metadata__() 60 self.failUnless(m['arguments'][3]['type'] == 'Z') 61 self.failUnless(m['arguments'][5]['type'].startswith('o^')) 62 63 m = obj.contentsOfDirectoryAtPath_error_.__metadata__() 64 self.failUnless(m['arguments'][3]['type'].startswith('o^')) 65 66 m = obj.subpathsOfDirectoryAtPath_error_.__metadata__() 67 self.failUnless(m['arguments'][3]['type'].startswith('o^')) 68 69 m = obj.attributesOfItemAtPath_error_.__metadata__() 70 self.failUnless(m['arguments'][3]['type'].startswith('o^')) 71 72 m = obj.attributesOfFileSystemForPath_error_.__metadata__() 73 self.failUnless(m['arguments'][3]['type'].startswith('o^')) 74 75 m = obj.createSymbolicLinkAtPath_withDestinationPath_error_.__metadata__() 76 self.failUnless(m['arguments'][4]['type'].startswith('o^')) 77 78 m = obj.destinationOfSymbolicLinkAtPath_error_.__metadata__() 79 self.failUnless(m['arguments'][3]['type'].startswith('o^')) 80 81 m = obj.copyItemAtPath_toPath_error_.__metadata__() 82 self.failUnless(m['retval']['type'] == 'Z') 83 self.failUnless(m['arguments'][4]['type'].startswith('o^')) 84 85 m = obj.moveItemAtPath_toPath_error_.__metadata__() 86 self.failUnless(m['retval']['type'] == 'Z') 87 self.failUnless(m['arguments'][4]['type'].startswith('o^')) 88 89 m = obj.linkItemAtPath_toPath_error_.__metadata__() 90 self.failUnless(m['retval']['type'] == 'Z') 91 self.failUnless(m['arguments'][4]['type'].startswith('o^')) 92 93 m = obj.removeItemAtPath_error_.__metadata__() 94 self.failUnless(m['retval']['type'] == 'Z') 95 self.failUnless(m['arguments'][3]['type'].startswith('o^')) 96 97 def testProtocols(self): 98 class FileManagerTest1 (NSObject): 99 def fileManager_shouldCopyItemAtPath_toPath_(self, fm, src, dst): 100 return True 101 102 def fileManager_shouldProceedAfterError_copyingItemAtPath_toPath_(self, fm, error, src, dst): 103 return True 104 105 def fileManager_shouldMoveItemAtPath_toPath_(self, fm, src, dst): 106 return True 107 108 def fileManager_shouldProceedAfterError_movingItemAtPath_toPath_(self, fm, error, src, dst): 109 return True 110 111 def fileManager_shouldLinkItemAtPath_toPath_(self, fm, src, dst): 112 return True 113 114 def fileManager_shouldProceedAfterError_linkingItemAtPath_toPath_(self, fm, error, src, dst): 115 return True 116 117 def fileManager_shouldRemoveItemAtPath_(self, fm, src): 118 return True 119 120 def fileManager_shouldProceedAfterError_removingItemAtPath_(self, fm, error, src): 121 return True 122 123 obj = FileManagerTest1.alloc().init() 124 m = obj.fileManager_shouldCopyItemAtPath_toPath_.__metadata__() 125 self.failUnless(m['retval']['type'] == 'Z') 126 127 m = obj.fileManager_shouldProceedAfterError_copyingItemAtPath_toPath_.__metadata__() 128 self.failUnless(m['retval']['type'] == 'Z') 129 130 m = obj.fileManager_shouldMoveItemAtPath_toPath_.__metadata__() 131 self.failUnless(m['retval']['type'] == 'Z') 132 133 m = obj.fileManager_shouldProceedAfterError_movingItemAtPath_toPath_.__metadata__() 134 self.failUnless(m['retval']['type'] == 'Z') 135 136 m = obj.fileManager_shouldLinkItemAtPath_toPath_.__metadata__() 137 self.failUnless(m['retval']['type'] == 'Z') 138 139 m = obj.fileManager_shouldProceedAfterError_linkingItemAtPath_toPath_.__metadata__() 140 self.failUnless(m['retval']['type'] == 'Z') 141 142 m = obj.fileManager_shouldRemoveItemAtPath_.__metadata__() 143 self.failUnless(m['retval']['type'] == 'Z') 144 145 m = obj.fileManager_shouldProceedAfterError_removingItemAtPath_.__metadata__() 146 self.failUnless(m['retval']['type'] == 'Z') 147 148 149 @min_os_level('10.5') 150 def testMethods10_5(self): 151 self.failUnlessResultIsBOOL(NSFileManager.setAttributes_ofItemAtPath_error_) 152 self.failUnlessArgIsOut(NSFileManager.setAttributes_ofItemAtPath_error_, 2) 153 154 self.failUnlessResultIsBOOL(NSFileManager.createDirectoryAtPath_withIntermediateDirectories_attributes_error_) 155 self.failUnlessArgIsBOOL(NSFileManager.createDirectoryAtPath_withIntermediateDirectories_attributes_error_, 1) 156 self.failUnlessArgIsOut(NSFileManager.createDirectoryAtPath_withIntermediateDirectories_attributes_error_, 3) 157 158 self.failUnlessArgIsOut(NSFileManager.contentsOfDirectoryAtPath_error_, 1) 159 self.failUnlessArgIsOut(NSFileManager.subpathsOfDirectoryAtPath_error_, 1) 160 self.failUnlessArgIsOut(NSFileManager.attributesOfItemAtPath_error_, 1) 161 self.failUnlessArgIsOut(NSFileManager.attributesOfFileSystemForPath_error_, 1) 162 163 self.failUnlessResultIsBOOL(NSFileManager.createSymbolicLinkAtPath_withDestinationPath_error_) 164 self.failUnlessArgIsOut(NSFileManager.createSymbolicLinkAtPath_withDestinationPath_error_, 2) 165 166 self.failUnlessArgIsOut(NSFileManager.destinationOfSymbolicLinkAtPath_error_, 1) 167 168 self.failUnlessResultIsBOOL(NSFileManager.copyItemAtPath_toPath_error_) 169 self.failUnlessArgIsOut(NSFileManager.copyItemAtPath_toPath_error_, 2) 170 self.failUnlessResultIsBOOL(NSFileManager.moveItemAtPath_toPath_error_) 171 self.failUnlessArgIsOut(NSFileManager.moveItemAtPath_toPath_error_, 2) 172 self.failUnlessResultIsBOOL(NSFileManager.linkItemAtPath_toPath_error_) 173 self.failUnlessArgIsOut(NSFileManager.linkItemAtPath_toPath_error_, 2) 174 self.failUnlessResultIsBOOL(NSFileManager.removeItemAtPath_error_) 175 self.failUnlessArgIsOut(NSFileManager.removeItemAtPath_error_, 1) 176 177 def testMethods(self): 178 self.failUnlessArgIsBOOL(NSFileManager.fileAttributesAtPath_traverseLink_, 1) 179 self.failUnlessResultIsBOOL(NSFileManager.changeFileAttributes_atPath_) 180 self.failUnlessResultIsBOOL(NSFileManager.createSymbolicLinkAtPath_pathContent_) 181 self.failUnlessResultIsBOOL(NSFileManager.createDirectoryAtPath_attributes_) 182 self.failUnlessResultIsBOOL(NSFileManager.linkPath_toPath_handler_) 183 self.failUnlessResultIsBOOL(NSFileManager.copyPath_toPath_handler_) 184 self.failUnlessResultIsBOOL(NSFileManager.movePath_toPath_handler_) 185 self.failUnlessResultIsBOOL(NSFileManager.removeFileAtPath_handler_) 186 self.failUnlessResultIsBOOL(NSFileManager.changeCurrentDirectoryPath_) 187 self.failUnlessResultIsBOOL(NSFileManager.fileExistsAtPath_) 188 self.failUnlessResultIsBOOL(NSFileManager.fileExistsAtPath_isDirectory_) 189 self.failUnlessArgHasType(NSFileManager.fileExistsAtPath_isDirectory_, 1, 'o^' + objc._C_NSBOOL) 190 self.failUnlessResultIsBOOL(NSFileManager.isReadableFileAtPath_) 191 self.failUnlessResultIsBOOL(NSFileManager.isWritableFileAtPath_) 192 self.failUnlessResultIsBOOL(NSFileManager.isExecutableFileAtPath_) 193 self.failUnlessResultIsBOOL(NSFileManager.isDeletableFileAtPath_) 194 self.failUnlessResultIsBOOL(NSFileManager.contentsEqualAtPath_andPath_) 195 self.failUnlessResultIsBOOL(NSFileManager.createFileAtPath_contents_attributes_) 196 self.failUnlessResultHasType(NSFileManager.fileSystemRepresentationWithPath_, '^' + objc._C_CHAR_AS_TEXT) 197 self.failUnlessResultIsNullTerminated(NSFileManager.fileSystemRepresentationWithPath_) 198 self.failUnlessArgHasType(NSFileManager.stringWithFileSystemRepresentation_length_, 0, 'n^' + objc._C_CHAR_AS_TEXT) 199 self.failUnlessArgSizeInArg(NSFileManager.stringWithFileSystemRepresentation_length_, 0, 1) 200 201 self.failUnlessResultIsBOOL(NSDictionary.fileIsImmutable) 202 self.failUnlessResultIsBOOL(NSDictionary.fileIsAppendOnly) 203 self.failUnlessResultIsBOOL(NSDictionary.fileExtensionHidden) 204 205 def testProtocols(self): 206 self.failUnlessResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_) 207 self.failUnlessResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldCopyItemAtPath_toPath_) 208 self.failUnlessResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_copyingItemAtPath_toPath_) 209 self.failUnlessResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldMoveItemAtPath_toPath_) 210 self.failUnlessResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_movingItemAtPath_toPath_) 211 self.failUnlessResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldLinkItemAtPath_toPath_) 212 self.failUnlessResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_linkingItemAtPath_toPath_) 213 self.failUnlessResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldRemoveItemAtPath_) 214 self.failUnlessResultIsBOOL(TestNSFileManagerHelper.fileManager_shouldProceedAfterError_removingItemAtPath_) 215 216if __name__ == '__main__': 217 main() 218