@@ -16,6 +16,10 @@ class TestFileManager : XCTestCase {
16
16
( " test_moveFile " , test_moveFile) ,
17
17
( " test_fileSystemRepresentation " , test_fileSystemRepresentation) ,
18
18
( " test_fileExists " , test_fileExists) ,
19
+ ( " test_isReadableFile " , test_isReadableFile) ,
20
+ ( " test_isWritableFile " , test_isWritableFile) ,
21
+ ( " test_isExecutableFile " , test_isExecutableFile) ,
22
+ ( " test_isDeletableFile " , test_isDeletableFile) ,
19
23
( " test_fileAttributes " , test_fileAttributes) ,
20
24
( " test_fileSystemAttributes " , test_fileSystemAttributes) ,
21
25
( " test_setFileAttributes " , test_setFileAttributes) ,
@@ -202,6 +206,62 @@ class TestFileManager : XCTestCase {
202
206
ignoreError { try fm. removeItem ( atPath: tmpDir. path) }
203
207
}
204
208
209
+ func test_isReadableFile( ) {
210
+ let fm = FileManager . default
211
+ let path = NSTemporaryDirectory ( ) + " test_fileAttributes \( NSUUID ( ) . uuidString) "
212
+
213
+ XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) , attributes: nil ) )
214
+
215
+ do {
216
+ let attrs = try fm. attributesOfItem ( atPath: path)
217
+ let permissions = attrs [ FileAttributeKey . posixPermissions] as! UInt16
218
+ let fileIsReadableFile = ( permissions & S_IRUSR == S_IRUSR)
219
+ let fmIsReadableFile = fm. isReadableFile ( atPath: path)
220
+ XCTAssertTrue ( fileIsReadableFile == fmIsReadableFile)
221
+ } catch let e {
222
+ XCTFail ( " \( e) " )
223
+ }
224
+ }
225
+
226
+ func test_isWritableFile( ) {
227
+ let fm = FileManager . default
228
+ let path = NSTemporaryDirectory ( ) + " test_fileAttributes \( NSUUID ( ) . uuidString) "
229
+
230
+ XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) , attributes: nil ) )
231
+
232
+ do {
233
+ let attrs = try fm. attributesOfItem ( atPath: path)
234
+ let permissions = attrs [ FileAttributeKey . posixPermissions] as! UInt16
235
+ let fileIsReadableFile = ( permissions & S_IWUSR == S_IWUSR)
236
+ let fmIsReadableFile = fm. isReadableFile ( atPath: path)
237
+ XCTAssertTrue ( fileIsReadableFile == fmIsReadableFile)
238
+ } catch let e {
239
+ XCTFail ( " \( e) " )
240
+ }
241
+ }
242
+
243
+ func test_isExecutableFile( ) {
244
+ let fm = FileManager . default
245
+ let path = NSTemporaryDirectory ( ) + " test_fileAttributes \( NSUUID ( ) . uuidString) "
246
+
247
+ XCTAssertTrue ( fm. createFile ( atPath: path, contents: Data ( ) , attributes: nil ) )
248
+
249
+ do {
250
+ let attrs = try fm. attributesOfItem ( atPath: path)
251
+ let permissions = attrs [ FileAttributeKey . posixPermissions] as! UInt16
252
+ let fileIsReadableFile = ( permissions & S_IXUSR == S_IXUSR)
253
+ let fmIsReadableFile = fm. isReadableFile ( atPath: path)
254
+ XCTAssertTrue ( fileIsReadableFile == fmIsReadableFile)
255
+ } catch let e {
256
+ XCTFail ( " \( e) " )
257
+ }
258
+ }
259
+
260
+ func test_isDeletableFile( ) {
261
+ // TODO: Implement test
262
+ // how to test?
263
+ }
264
+
205
265
func test_fileAttributes( ) {
206
266
let fm = FileManager . default
207
267
let path = NSTemporaryDirectory ( ) + " test_fileAttributes \( NSUUID ( ) . uuidString) "
0 commit comments