Skip to content

Commit d94be7e

Browse files
authored
Merge pull request #1189 from johnno1962c/master
2 parents 21fb8e7 + e07e101 commit d94be7e

18 files changed

+163
-22
lines changed

Foundation/NSTimeZone.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ open class NSTimeZone : NSObject, NSCopying, NSSecureCoding, NSCoding {
2929
}
3030

3131
public init?(name tzName: String, data aData: Data?) {
32+
#if os(Android)
33+
var tzName = tzName
34+
if tzName == "UTC" || tzName == "GMT" {
35+
tzName = "GMT+0000"
36+
}
37+
else if !(tzName.hasPrefix("GMT+") || tzName.hasPrefix("GMT-")) {
38+
NSLog("Time zone database not available on Android")
39+
}
40+
#endif
3241
super.init()
3342
if !_CFTimeZoneInit(_cfObject, tzName._cfObject, aData?._cfObject) {
3443
return nil
@@ -170,6 +179,14 @@ open class NSTimeZone : NSObject, NSCopying, NSSecureCoding, NSCoding {
170179
extension NSTimeZone {
171180

172181
open class var system: TimeZone {
182+
#if os(Android)
183+
var now = time(nil), info = tm()
184+
if localtime_r(&now, &info) != nil {
185+
// NOTE: this is not a real time zone but a fixed offset from GMT.
186+
// It will be incorrect outside the current daylight saving period.
187+
return TimeZone(reference: NSTimeZone(forSecondsFromGMT: info.tm_gmtoff))
188+
}
189+
#endif
173190
return CFTimeZoneCopySystem()._swiftObject
174191
}
175192

TestFoundation/HTTPServer.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class _TCPSocket {
7070
public private(set) var port: UInt16
7171

7272
init(port: UInt16?) throws {
73-
#if os(Linux)
73+
#if os(Linux) && !os(Android)
7474
let SOCKSTREAM = Int32(SOCK_STREAM.rawValue)
7575
#else
7676
let SOCKSTREAM = SOCK_STREAM
@@ -102,7 +102,9 @@ class _TCPSocket {
102102
// asking to accept incoming connections if the firewall is enabled.
103103
let addr = UInt32(INADDR_LOOPBACK).bigEndian
104104
let netPort = UInt16(bigEndian: port ?? 0)
105-
#if os(Linux)
105+
#if os(Android)
106+
return sockaddr_in(sin_family: sa_family_t(AF_INET), sin_port: netPort, sin_addr: in_addr(s_addr: addr), __pad: (0,0,0,0,0,0,0,0))
107+
#elseif os(Linux)
106108
return sockaddr_in(sin_family: sa_family_t(AF_INET), sin_port: netPort, sin_addr: in_addr(s_addr: addr), sin_zero: (0,0,0,0,0,0,0,0))
107109
#else
108110
return sockaddr_in(sin_len: 0, sin_family: sa_family_t(AF_INET), sin_port: netPort, sin_addr: in_addr(s_addr: addr), sin_zero: (0,0,0,0,0,0,0,0))

TestFoundation/TestCodable.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ class TestCodable : XCTestCase {
307307

308308
// MARK: - TimeZone
309309
lazy var timeZoneValues: [TimeZone] = {
310+
#if !os(Android)
310311
var values = [
311312
TimeZone(identifier: "America/Los_Angeles")!,
312313
TimeZone(identifier: "UTC")!,
@@ -318,7 +319,12 @@ class TestCodable : XCTestCase {
318319
// causing encode -> decode -> compare test to fail.
319320
values.append(TimeZone.current)
320321
#endif
321-
322+
#else
323+
var values = [
324+
TimeZone(identifier: "UTC")!,
325+
TimeZone.current
326+
]
327+
#endif
322328
return values
323329
}()
324330

TestFoundation/TestDecimal.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class TestDecimal: XCTestCase {
277277
}
278278
}
279279
}
280-
XCTAssertEqual(Decimal(186243*15673), Decimal(186243) * Decimal(15673))
280+
XCTAssertEqual(Decimal(186243 * 15673 as Int64), Decimal(186243) * Decimal(15673))
281281
}
282282

283283
func test_Misc() {
@@ -308,7 +308,9 @@ class TestDecimal: XCTestCase {
308308
XCTAssertFalse(Decimal.nan.isTotallyOrdered(belowOrEqualTo: Decimal(2.3)))
309309
XCTAssertTrue(Decimal(2) < Decimal(3))
310310
XCTAssertTrue(Decimal(3) > Decimal(2))
311+
#if !arch(arm)
311312
XCTAssertEqual(3275573729074, Decimal(1234).hashValue)
313+
#endif
312314
XCTAssertEqual(Decimal(-9), Decimal(1) - Decimal(10))
313315
XCTAssertEqual(Decimal(3), Decimal(2).nextUp)
314316
XCTAssertEqual(Decimal(2), Decimal(3).nextDown)

TestFoundation/TestHTTPCookieStorage.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class TestHTTPCookieStorage: XCTestCase {
239239
}
240240

241241
func test_cookieInXDGSpecPath() {
242+
#if !os(Android)
242243
//Test without setting the environment variable
243244
let testCookie = HTTPCookie(properties: [
244245
.name: "TestCookie0",
@@ -287,5 +288,6 @@ class TestHTTPCookieStorage: XCTestCase {
287288
let terminationReason = task.terminationReason
288289
XCTAssertEqual(terminationReason, Process.TerminationReason.exit)
289290
try? fm.removeItem(atPath: testPath)
291+
#endif
290292
}
291293
}

TestFoundation/TestISO8601DateFormatter.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class TestISO8601DateFormatter: XCTestCase {
100100
isoFormatter.formatOptions = [.withMonth, .withDay, .withWeekOfYear, .withDashSeparatorInDate]
101101
XCTAssertEqual(isoFormatter.string(from: someDateTime!), "10-W40-06")
102102

103+
#if !os(Android)
103104
/*
104105
The following tests cover various cases when changing the .formatOptions property with a different TimeZone set.
105106
*/
@@ -141,7 +142,7 @@ class TestISO8601DateFormatter: XCTestCase {
141142

142143
isoFormatter.formatOptions = [.withDay, .withWeekOfYear, .withMonth, .withTimeZone, .withColonSeparatorInTimeZone, .withDashSeparatorInDate]
143144
XCTAssertEqual(isoFormatter.string(from: someDateTime!), "10-W40-06-07:00")
144-
145+
#endif
145146
}
146147

147148

@@ -248,6 +249,7 @@ class TestISO8601DateFormatter: XCTestCase {
248249
formatOptions = [.withMonth, .withDay, .withWeekOfYear, .withDashSeparatorInDate]
249250
XCTAssertEqual(ISO8601DateFormatter.string(from: someDateTime!, timeZone: timeZone!, formatOptions: formatOptions), "10-W40-06")
250251

252+
#if !os(Android)
251253
/*
252254
The following tests cover various cases when changing the .formatOptions property with a different TimeZone set.
253255
*/
@@ -289,7 +291,7 @@ class TestISO8601DateFormatter: XCTestCase {
289291

290292
formatOptions = [.withDay, .withWeekOfYear, .withMonth, .withTimeZone, .withColonSeparatorInTimeZone, .withDashSeparatorInDate]
291293
XCTAssertEqual(ISO8601DateFormatter.string(from: someDateTime!, timeZone: timeZone!, formatOptions: formatOptions), "10-W40-06-07:00")
292-
294+
#endif
293295
}
294296

295297
}

TestFoundation/TestJSONEncoder.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,15 @@ class TestJSONEncoder : XCTestCase {
354354
}
355355

356356
func test_codingOfInt64() {
357+
#if !arch(arm)
357358
test_codingOf(value: Int64(-9000000000000000042), toAndFrom: "-9000000000000000042")
359+
#endif
358360
}
359361

360362
func test_codingOfUInt64() {
363+
#if !arch(arm)
361364
test_codingOf(value: UInt64(9000000000000000042), toAndFrom: "9000000000000000042")
365+
#endif
362366
}
363367

364368
func test_codingOfInt() {
@@ -367,7 +371,11 @@ class TestJSONEncoder : XCTestCase {
367371
case 4: // 32-bit
368372
test_codingOf(value: Int(-2000000042), toAndFrom: "-2000000042")
369373
case 8: // 64-bit
374+
#if arch(arm)
375+
break
376+
#else
370377
test_codingOf(value: Int(-9000000000000000042), toAndFrom: "-9000000000000000042")
378+
#endif
371379
default:
372380
XCTFail("Unexpected UInt size: \(intSize)")
373381
}
@@ -379,7 +387,11 @@ class TestJSONEncoder : XCTestCase {
379387
case 4: // 32-bit
380388
test_codingOf(value: UInt(2000000042), toAndFrom: "2000000042")
381389
case 8: // 64-bit
390+
#if arch(arm)
391+
break
392+
#else
382393
test_codingOf(value: UInt(9000000000000000042), toAndFrom: "9000000000000000042")
394+
#endif
383395
default:
384396
XCTFail("Unexpected UInt size: \(uintSize)")
385397
}

TestFoundation/TestNSAttributedString.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ class TestNSAttributedString : XCTestCase {
155155
}
156156

157157
func test_enumerateAttributes() {
158+
#if os(Android)
159+
// Invalid dictionary returned by CFAttributedStringGetAttributesAndLongestEffectiveRange
160+
XCTFail("Intermittent failures on Android")
161+
#else
158162
let string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus consectetur et sem vitae consectetur. Nam venenatis lectus a laoreet blandit."
159163

160164
let attrKey1 = "attribute.placeholder.key1"
@@ -213,6 +217,7 @@ class TestNSAttributedString : XCTestCase {
213217
}
214218
XCTAssertEqual(rangeDescriptionString, "(0,10)")
215219
XCTAssertEqual(attrsDescriptionString, "[attribute.placeholder.key1:attribute.placeholder.value1]")
220+
#endif
216221
}
217222
}
218223

TestFoundation/TestNSData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ class TestNSData: XCTestCase {
515515

516516
func test_writeToURLOptions() {
517517
let saveData = try! Data(contentsOf: Bundle.main.url(forResource: "Test", withExtension: "plist")!)
518-
let savePath = URL(fileURLWithPath: "/var/tmp/Test.plist")
518+
let savePath = URL(fileURLWithPath: NSTemporaryDirectory() + "Test1.plist")
519519
do {
520520
try saveData.write(to: savePath, options: .atomic)
521521
let fileManager = FileManager.default

TestFoundation/TestNSLocale.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,16 @@ class TestNSLocale : XCTestCase {
115115
}
116116

117117
func test_localeProperties(){
118+
#if os(Android)
119+
XCTFail("Locale lookup unavailable on Android")
120+
#else
118121
let enUSID = "en_US"
119122
let locale = Locale(identifier: enUSID)
120123
XCTAssertEqual(String(describing: locale.languageCode!), "en")
121124
XCTAssertEqual(String(describing: locale.decimalSeparator!), ".")
122125
XCTAssertEqual(String(describing: locale.currencyCode!), "USD")
123126
XCTAssertEqual(String(describing: locale.collatorIdentifier!), enUSID)
127+
#endif
124128
}
125129

126130
}

TestFoundation/TestNSNumber.swift

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ class TestNSNumber : XCTestCase {
297297
let uintSize = MemoryLayout<UInt>.size
298298
switch uintSize {
299299
case 4: XCTAssertEqual(NSNumber(value: Int16.min).uintValue, 4294934528)
300-
case 8: XCTAssertEqual(NSNumber(value: Int16.min).uintValue, 18446744073709518848)
300+
case 8:
301+
#if arch(arm)
302+
break
303+
#else
304+
XCTAssertEqual(NSNumber(value: Int16.min).uintValue, 18446744073709518848)
305+
#endif
301306
default: XCTFail("Unexpected UInt size: \(uintSize)")
302307
}
303308

@@ -402,7 +407,12 @@ class TestNSNumber : XCTestCase {
402407
let uintSize = MemoryLayout<UInt>.size
403408
switch uintSize {
404409
case 4: XCTAssertEqual(NSNumber(value: Int32.min).uintValue, 2147483648)
405-
case 8: XCTAssertEqual(NSNumber(value: Int32.min).uintValue, 18446744071562067968)
410+
case 8:
411+
#if arch(arm)
412+
break
413+
#else
414+
XCTAssertEqual(NSNumber(value: Int32.min).uintValue, 18446744071562067968)
415+
#endif
406416
default: XCTFail("Unexpected UInt size: \(uintSize)")
407417
}
408418

@@ -466,7 +476,12 @@ class TestNSNumber : XCTestCase {
466476
let intSize = MemoryLayout<Int>.size
467477
switch intSize {
468478
case 4: XCTAssertEqual(NSNumber(value: UInt32.max).intValue, -1)
469-
case 8: XCTAssertEqual(NSNumber(value: UInt32.max).intValue, 4294967295)
479+
case 8:
480+
#if arch(arm)
481+
break
482+
#else
483+
XCTAssertEqual(NSNumber(value: UInt32.max).intValue, 4294967295)
484+
#endif
470485
default: XCTFail("Unexpected Int size: \(intSize)")
471486
}
472487
XCTAssertEqual(NSNumber(value: UInt32.max).uintValue, 4294967295)
@@ -511,14 +526,24 @@ class TestNSNumber : XCTestCase {
511526
let intSize = MemoryLayout<Int>.size
512527
switch intSize {
513528
case 4: XCTAssertEqual(NSNumber(value: Int64.min).intValue, 0)
514-
case 8: XCTAssertEqual(NSNumber(value: Int64.min).intValue, -9223372036854775808)
529+
case 8:
530+
#if arch(arm)
531+
break
532+
#else
533+
XCTAssertEqual(NSNumber(value: Int64.min).intValue, -9223372036854775808)
534+
#endif
515535
default: XCTFail("Unexpected Int size: \(intSize)")
516536
}
517537

518538
let uintSize = MemoryLayout<UInt>.size
519539
switch uintSize {
520540
case 4: XCTAssertEqual(NSNumber(value: Int64.min).uintValue, 0)
521-
case 8: XCTAssertEqual(NSNumber(value: Int64.min).uintValue, 9223372036854775808)
541+
case 8:
542+
#if arch(arm)
543+
break
544+
#else
545+
XCTAssertEqual(NSNumber(value: Int64.min).uintValue, 9223372036854775808)
546+
#endif
522547
default: XCTFail("Unexpected UInt size: \(uintSize)")
523548
}
524549

@@ -541,13 +566,23 @@ class TestNSNumber : XCTestCase {
541566

542567
switch intSize {
543568
case 4: XCTAssertEqual(NSNumber(value: Int64.max).intValue, -1)
544-
case 8: XCTAssertEqual(NSNumber(value: Int64.max).intValue, 9223372036854775807)
569+
case 8:
570+
#if arch(arm)
571+
break
572+
#else
573+
XCTAssertEqual(NSNumber(value: Int64.max).intValue, 9223372036854775807)
574+
#endif
545575
default: XCTFail("Unexpected Int size: \(intSize)")
546576
}
547577

548578
switch uintSize {
549579
case 4: XCTAssertEqual(NSNumber(value: Int64.max).uintValue, 4294967295)
550-
case 8: XCTAssertEqual(NSNumber(value: Int64.max).uintValue, 9223372036854775807)
580+
case 8:
581+
#if arch(arm)
582+
break
583+
#else
584+
XCTAssertEqual(NSNumber(value: Int64.max).uintValue, 9223372036854775807)
585+
#endif
551586
default: XCTFail("Unexpected UInt size: \(uintSize)")
552587
}
553588

@@ -592,7 +627,12 @@ class TestNSNumber : XCTestCase {
592627
let uintSize = MemoryLayout<UInt>.size
593628
switch uintSize {
594629
case 4: XCTAssertEqual(NSNumber(value: UInt64.max).uintValue, 4294967295)
595-
case 8: XCTAssertEqual(NSNumber(value: UInt64.max).uintValue, 18446744073709551615)
630+
case 8:
631+
#if arch(arm)
632+
break
633+
#else
634+
XCTAssertEqual(NSNumber(value: UInt64.max).uintValue, 18446744073709551615)
635+
#endif
596636
default: XCTFail("Unexpected UInt size: \(uintSize)")
597637
}
598638

@@ -638,8 +678,9 @@ class TestNSNumber : XCTestCase {
638678
XCTAssertEqual(NSNumber(value: Int.min).uint64Value, 18446744071562067968)
639679

640680
XCTAssertEqual(NSNumber(value: Int.min).intValue, -2147483648)
681+
#if !arch(arm)
641682
XCTAssertEqual(NSNumber(value: Int.min).uintValue, 18446744071562067968)
642-
683+
#endif
643684
XCTAssertEqual(NSNumber(value: Int.min).floatValue, Float(Int.min))
644685
XCTAssertEqual(NSNumber(value: Int.min).doubleValue, Double(Int.min))
645686

@@ -664,6 +705,9 @@ class TestNSNumber : XCTestCase {
664705
XCTAssertEqual(NSNumber(value: Int.max).doubleValue, Double(Int.max))
665706

666707
case (8, 8):
708+
#if arch(arm)
709+
break
710+
#else
667711
XCTAssertEqual(NSNumber(value: Int.min).boolValue, false)
668712

669713
XCTAssertEqual(NSNumber(value: Int.min).int8Value, 0)
@@ -701,7 +745,7 @@ class TestNSNumber : XCTestCase {
701745

702746
XCTAssertEqual(NSNumber(value: Int.max).floatValue, Float(Int.max))
703747
XCTAssertEqual(NSNumber(value: Int.max).doubleValue, Double(Int.max))
704-
748+
#endif
705749
default: XCTFail("Unexpected mismatched Int & UInt sizes: \(intSize) & \(uintSize)")
706750
}
707751
}
@@ -743,7 +787,9 @@ class TestNSNumber : XCTestCase {
743787
XCTAssertEqual(NSNumber(value: UInt.max).uint32Value, 4294967295)
744788
XCTAssertEqual(NSNumber(value: UInt.max).uint64Value, 4294967295)
745789

790+
#if !arch(arm)
746791
XCTAssertEqual(NSNumber(value: UInt.max).intValue, 4294967295)
792+
#endif
747793
XCTAssertEqual(NSNumber(value: UInt.max).uintValue, 4294967295)
748794

749795
XCTAssertEqual(NSNumber(value: UInt.max).floatValue, Float(UInt.max))
@@ -763,7 +809,9 @@ class TestNSNumber : XCTestCase {
763809
XCTAssertEqual(NSNumber(value: UInt.max).uint64Value, 18446744073709551615)
764810

765811
XCTAssertEqual(NSNumber(value: UInt.max).intValue, -1)
812+
#if !arch(arm)
766813
XCTAssertEqual(NSNumber(value: UInt.max).uintValue, 18446744073709551615)
814+
#endif
767815

768816
XCTAssertEqual(NSNumber(value: UInt.max).floatValue, Float(UInt.max))
769817
XCTAssertEqual(NSNumber(value: UInt.max).doubleValue, Double(UInt.max))

TestFoundation/TestNSString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ class TestNSString : XCTestCase {
913913
let path = NSString(string: "~\(userName)/")
914914
let result = path.expandingTildeInPath
915915
// next assert fails in VirtualBox because home directory for unknown user resolved to /var/run/vboxadd
916-
XCTAssert(result == "~\(userName)", "Return copy of reciver if home directory could no be resolved.")
916+
XCTAssertEqual(result, "~\(userName)", "Return copy of receiver if home directory could not be resolved.")
917917
}
918918
}
919919

0 commit comments

Comments
 (0)