|
10 | 10 | import CoreFoundation
|
11 | 11 |
|
12 | 12 | class TestTimeZone: XCTestCase {
|
13 |
| - |
14 |
| - static var allTests: [(String, (TestTimeZone) -> () throws -> Void)] { |
15 |
| - var tests: [(String, (TestTimeZone) -> () throws -> Void)] = [ |
16 |
| - ("test_abbreviation", test_abbreviation), |
17 |
| - |
18 |
| - // Disabled because `CFTimeZoneSetAbbreviationDictionary()` attempts |
19 |
| - // to release non-CF objects while removing values from |
20 |
| - // `__CFTimeZoneCache` |
21 |
| - // ("test_abbreviationDictionary", test_abbreviationDictionary), |
22 |
| - |
23 |
| - ("test_changingDefaultTimeZone", test_changingDefaultTimeZone), |
24 |
| - ("test_computedPropertiesMatchMethodReturnValues", test_computedPropertiesMatchMethodReturnValues), |
25 |
| - ("test_initializingTimeZoneWithOffset", test_initializingTimeZoneWithOffset), |
26 |
| - ("test_initializingTimeZoneWithAbbreviation", test_initializingTimeZoneWithAbbreviation), |
27 |
| - ("test_localizedName", test_localizedName), |
28 |
| - ("test_customMirror", test_tz_customMirror), |
29 |
| - ("test_knownTimeZones", test_knownTimeZones), |
30 |
| - ("test_systemTimeZoneName", test_systemTimeZoneName), |
31 |
| - ] |
32 |
| - |
33 |
| -#if !os(Windows) |
34 |
| - tests.append(contentsOf: [ |
35 |
| - ("test_systemTimeZoneUsesSystemTime", test_systemTimeZoneUsesSystemTime), |
36 |
| - ]) |
37 |
| -#endif |
38 |
| - |
39 |
| - return tests |
| 13 | + |
| 14 | + var initialDefaultTimeZone: TimeZone? |
| 15 | + |
| 16 | + override func setUp() { |
| 17 | + initialDefaultTimeZone = NSTimeZone.default |
| 18 | + super.setUp() |
| 19 | + } |
| 20 | + |
| 21 | + override func tearDown() { |
| 22 | + super.tearDown() |
| 23 | + if let tz = initialDefaultTimeZone { |
| 24 | + NSTimeZone.default = tz |
| 25 | + } |
40 | 26 | }
|
41 | 27 |
|
42 | 28 | func test_abbreviation() {
|
@@ -220,4 +206,56 @@ class TestTimeZone: XCTestCase {
|
220 | 206 | XCTAssertEqual(CFStringGetLength(timeZoneName), TimeZone.current.identifier.count)
|
221 | 207 | XCTAssertEqual(CFStringGetLength(timeZoneName), createdTimeZone.identifier.count)
|
222 | 208 | }
|
| 209 | + |
| 210 | + func test_autoupdatingTimeZone() { |
| 211 | + let system = NSTimeZone.system |
| 212 | + let date = Date() |
| 213 | + |
| 214 | + for zone in [NSTimeZone.local, TimeZone.autoupdatingCurrent] { |
| 215 | + XCTAssertEqual(zone.identifier, system.identifier) |
| 216 | + XCTAssertEqual(zone.secondsFromGMT(for: date), system.secondsFromGMT(for: date)) |
| 217 | + XCTAssertEqual(zone.abbreviation(for: date), system.abbreviation(for: date)) |
| 218 | + XCTAssertEqual(zone.isDaylightSavingTime(for: date), system.isDaylightSavingTime(for: date)) |
| 219 | + XCTAssertEqual(zone.daylightSavingTimeOffset(for: date), system.daylightSavingTimeOffset(for: date)) |
| 220 | + XCTAssertEqual(zone.nextDaylightSavingTimeTransition(after: date), system.nextDaylightSavingTimeTransition(after: date)) |
| 221 | + |
| 222 | + for style in [NSTimeZone.NameStyle.standard, |
| 223 | + NSTimeZone.NameStyle.shortStandard, |
| 224 | + NSTimeZone.NameStyle.daylightSaving, |
| 225 | + NSTimeZone.NameStyle.shortDaylightSaving, |
| 226 | + NSTimeZone.NameStyle.generic, |
| 227 | + NSTimeZone.NameStyle.shortGeneric,] { |
| 228 | + XCTAssertEqual(zone.localizedName(for: style, locale: NSLocale.system), system.localizedName(for: style, locale: NSLocale.system), "For style: \(style)") |
| 229 | + } |
| 230 | + } |
| 231 | + } |
| 232 | + |
| 233 | + static var allTests: [(String, (TestTimeZone) -> () throws -> Void)] { |
| 234 | + var tests: [(String, (TestTimeZone) -> () throws -> Void)] = [ |
| 235 | + ("test_abbreviation", test_abbreviation), |
| 236 | + |
| 237 | + // Disabled because `CFTimeZoneSetAbbreviationDictionary()` attempts |
| 238 | + // to release non-CF objects while removing values from |
| 239 | + // `__CFTimeZoneCache` |
| 240 | + // ("test_abbreviationDictionary", test_abbreviationDictionary), |
| 241 | + |
| 242 | + ("test_changingDefaultTimeZone", test_changingDefaultTimeZone), |
| 243 | + ("test_computedPropertiesMatchMethodReturnValues", test_computedPropertiesMatchMethodReturnValues), |
| 244 | + ("test_initializingTimeZoneWithOffset", test_initializingTimeZoneWithOffset), |
| 245 | + ("test_initializingTimeZoneWithAbbreviation", test_initializingTimeZoneWithAbbreviation), |
| 246 | + ("test_localizedName", test_localizedName), |
| 247 | + ("test_customMirror", test_tz_customMirror), |
| 248 | + ("test_knownTimeZones", test_knownTimeZones), |
| 249 | + ("test_systemTimeZoneName", test_systemTimeZoneName), |
| 250 | + ("test_autoupdatingTimeZone", test_autoupdatingTimeZone), |
| 251 | + ] |
| 252 | + |
| 253 | + #if !os(Windows) |
| 254 | + tests.append(contentsOf: [ |
| 255 | + ("test_systemTimeZoneUsesSystemTime", test_systemTimeZoneUsesSystemTime), |
| 256 | + ]) |
| 257 | + #endif |
| 258 | + |
| 259 | + return tests |
| 260 | + } |
223 | 261 | }
|
0 commit comments