@@ -53,7 +53,7 @@ class TestURL : TestURLSuper {
5353 expectTrue ( false , " Unable to write data " )
5454 }
5555
56- // Modify an existing resource values
56+ // Modify an existing resource value
5757 do {
5858 var resourceValues = try file. resourceValues ( forKeys: [ . nameKey] )
5959 expectNotNil ( resourceValues. name)
@@ -64,9 +64,65 @@ class TestURL : TestURLSuper {
6464 try file. setResourceValues ( resourceValues)
6565 } catch {
6666 expectTrue ( false , " Unable to set resources " )
67- }
67+ }
6868 }
6969
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+
70126 func testMoreSetProperties( ) {
71127 // Create a temporary file
72128 var file = URL ( fileURLWithPath: NSTemporaryDirectory ( ) )
@@ -327,6 +383,9 @@ var URLTests = TestSuite("TestURL")
327383URLTests . test ( " testBasics " ) { TestURL ( ) . testBasics ( ) }
328384URLTests . test ( " testProperties " ) { TestURL ( ) . testProperties ( ) }
329385URLTests . test ( " testSetProperties " ) { TestURL ( ) . testSetProperties ( ) }
386+ #if os(OSX)
387+ URLTests . test ( " testQuarantineProperties " ) { TestURL ( ) . testQuarantineProperties ( ) }
388+ #endif
330389URLTests . test ( " testMoreSetProperties " ) { TestURL ( ) . testMoreSetProperties ( ) }
331390URLTests . test ( " testURLComponents " ) { TestURL ( ) . testURLComponents ( ) }
332391URLTests . test ( " testURLResourceValues " ) { TestURL ( ) . testURLResourceValues ( ) }
0 commit comments