@@ -53,7 +53,7 @@ class TestURL : TestURLSuper {
53
53
expectTrue ( false , " Unable to write data " )
54
54
}
55
55
56
- // Modify an existing resource values
56
+ // Modify an existing resource value
57
57
do {
58
58
var resourceValues = try file. resourceValues ( forKeys: [ . nameKey] )
59
59
expectNotNil ( resourceValues. name)
@@ -64,9 +64,65 @@ class TestURL : TestURLSuper {
64
64
try file. setResourceValues ( resourceValues)
65
65
} catch {
66
66
expectTrue ( false , " Unable to set resources " )
67
- }
67
+ }
68
68
}
69
69
70
+ #if os(OSX)
71
+ func testQuarantineProperties( ) {
72
+ // Test the quarantine stuff; it has special logic
73
+ if #available( OSX 10 . 11 , iOS 9 . 0 , * ) {
74
+ // Create a temporary file
75
+ var file = URL ( fileURLWithPath: NSTemporaryDirectory ( ) )
76
+ let name = " my_great_file " + UUID( ) . uuidString
77
+ file. appendPathComponent ( name)
78
+ let data = Data ( bytes: [ 1 , 2 , 3 , 4 , 5 ] )
79
+ do {
80
+ try data. write ( to: file)
81
+ } catch {
82
+ expectTrue ( false , " Unable to write data " )
83
+ }
84
+
85
+ // Set the quarantine info on a file
86
+ do {
87
+ var resourceValues = URLResourceValues ( )
88
+ resourceValues. quarantineProperties = [ " LSQuarantineAgentName " : " TestURL " ]
89
+ try file. setResourceValues ( resourceValues)
90
+ } catch {
91
+ expectTrue ( false , " Unable to set quarantine info " )
92
+ }
93
+
94
+ // Get the quarantine info back
95
+ do {
96
+ var resourceValues = try file. resourceValues ( forKeys: [ . quarantinePropertiesKey] )
97
+ expectEqual ( resourceValues. quarantineProperties ? [ " LSQuarantineAgentName " ] as? String , " TestURL " )
98
+ } catch {
99
+ expectTrue ( false , " Unable to get quarantine info " )
100
+ }
101
+
102
+ // Clear the quarantine info
103
+ do {
104
+ var resourceValues = URLResourceValues ( )
105
+ resourceValues. quarantineProperties = nil // this effectively sets a flag
106
+ try file. setResourceValues ( resourceValues)
107
+
108
+ // Make sure that the resourceValues property returns nil
109
+ expectNil ( resourceValues. quarantineProperties)
110
+ } catch {
111
+ expectTrue ( false , " Unable to clear quarantine info " )
112
+ }
113
+
114
+ // Get the quarantine info back again
115
+ do {
116
+ var resourceValues = try file. resourceValues ( forKeys: [ . quarantinePropertiesKey] )
117
+ expectNil ( resourceValues. quarantineProperties)
118
+ } catch {
119
+ expectTrue ( false , " Unable to get quarantine info after clearing " )
120
+ }
121
+
122
+ }
123
+ }
124
+ #endif
125
+
70
126
func testMoreSetProperties( ) {
71
127
// Create a temporary file
72
128
var file = URL ( fileURLWithPath: NSTemporaryDirectory ( ) )
@@ -327,6 +383,9 @@ var URLTests = TestSuite("TestURL")
327
383
URLTests . test ( " testBasics " ) { TestURL ( ) . testBasics ( ) }
328
384
URLTests . test ( " testProperties " ) { TestURL ( ) . testProperties ( ) }
329
385
URLTests . test ( " testSetProperties " ) { TestURL ( ) . testSetProperties ( ) }
386
+ #if os(OSX)
387
+ URLTests . test ( " testQuarantineProperties " ) { TestURL ( ) . testQuarantineProperties ( ) }
388
+ #endif
330
389
URLTests . test ( " testMoreSetProperties " ) { TestURL ( ) . testMoreSetProperties ( ) }
331
390
URLTests . test ( " testURLComponents " ) { TestURL ( ) . testURLComponents ( ) }
332
391
URLTests . test ( " testURLResourceValues " ) { TestURL ( ) . testURLResourceValues ( ) }
0 commit comments