diff --git a/Foundation/NSTimeZone.swift b/Foundation/NSTimeZone.swift index f022dfa401..0d647954dc 100644 --- a/Foundation/NSTimeZone.swift +++ b/Foundation/NSTimeZone.swift @@ -29,6 +29,15 @@ open class NSTimeZone : NSObject, NSCopying, NSSecureCoding, NSCoding { } public init?(name tzName: String, data aData: Data?) { +#if os(Android) + var tzName = tzName + if tzName == "UTC" || tzName == "GMT" { + tzName = "GMT+0000" + } + else if !(tzName.hasPrefix("GMT+") || tzName.hasPrefix("GMT-")) { + NSLog("Time zone database not available on Android") + } +#endif super.init() if !_CFTimeZoneInit(_cfObject, tzName._cfObject, aData?._cfObject) { return nil @@ -170,6 +179,14 @@ open class NSTimeZone : NSObject, NSCopying, NSSecureCoding, NSCoding { extension NSTimeZone { open class var system: TimeZone { +#if os(Android) + var now = time(nil), info = tm() + if localtime_r(&now, &info) != nil { + // NOTE: this is not a real time zone but a fixed offset from GMT. + // It will be incorrect outside the current daylight saving period. + return TimeZone(reference: NSTimeZone(forSecondsFromGMT: info.tm_gmtoff)) + } +#endif return CFTimeZoneCopySystem()._swiftObject } diff --git a/TestFoundation/HTTPServer.swift b/TestFoundation/HTTPServer.swift index ec2055f4d2..4caab62519 100644 --- a/TestFoundation/HTTPServer.swift +++ b/TestFoundation/HTTPServer.swift @@ -70,7 +70,7 @@ class _TCPSocket { public private(set) var port: UInt16 init(port: UInt16?) throws { - #if os(Linux) + #if os(Linux) && !os(Android) let SOCKSTREAM = Int32(SOCK_STREAM.rawValue) #else let SOCKSTREAM = SOCK_STREAM @@ -102,7 +102,9 @@ class _TCPSocket { // asking to accept incoming connections if the firewall is enabled. let addr = UInt32(INADDR_LOOPBACK).bigEndian let netPort = UInt16(bigEndian: port ?? 0) - #if os(Linux) + #if os(Android) + 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)) + #elseif os(Linux) 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)) #else 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)) diff --git a/TestFoundation/TestCodable.swift b/TestFoundation/TestCodable.swift index f1fb7d68db..d616a95ae5 100644 --- a/TestFoundation/TestCodable.swift +++ b/TestFoundation/TestCodable.swift @@ -307,6 +307,7 @@ class TestCodable : XCTestCase { // MARK: - TimeZone lazy var timeZoneValues: [TimeZone] = { +#if !os(Android) var values = [ TimeZone(identifier: "America/Los_Angeles")!, TimeZone(identifier: "UTC")!, @@ -318,7 +319,12 @@ class TestCodable : XCTestCase { // causing encode -> decode -> compare test to fail. values.append(TimeZone.current) #endif - +#else + var values = [ + TimeZone(identifier: "UTC")!, + TimeZone.current + ] +#endif return values }() diff --git a/TestFoundation/TestDecimal.swift b/TestFoundation/TestDecimal.swift index f34d9f7ae6..1fe51a858c 100644 --- a/TestFoundation/TestDecimal.swift +++ b/TestFoundation/TestDecimal.swift @@ -277,7 +277,7 @@ class TestDecimal: XCTestCase { } } } - XCTAssertEqual(Decimal(186243*15673), Decimal(186243) * Decimal(15673)) + XCTAssertEqual(Decimal(186243 * 15673 as Int64), Decimal(186243) * Decimal(15673)) } func test_Misc() { @@ -308,7 +308,9 @@ class TestDecimal: XCTestCase { XCTAssertFalse(Decimal.nan.isTotallyOrdered(belowOrEqualTo: Decimal(2.3))) XCTAssertTrue(Decimal(2) < Decimal(3)) XCTAssertTrue(Decimal(3) > Decimal(2)) +#if !arch(arm) XCTAssertEqual(3275573729074, Decimal(1234).hashValue) +#endif XCTAssertEqual(Decimal(-9), Decimal(1) - Decimal(10)) XCTAssertEqual(Decimal(3), Decimal(2).nextUp) XCTAssertEqual(Decimal(2), Decimal(3).nextDown) diff --git a/TestFoundation/TestHTTPCookieStorage.swift b/TestFoundation/TestHTTPCookieStorage.swift index f65a01e942..757f64b494 100644 --- a/TestFoundation/TestHTTPCookieStorage.swift +++ b/TestFoundation/TestHTTPCookieStorage.swift @@ -239,6 +239,7 @@ class TestHTTPCookieStorage: XCTestCase { } func test_cookieInXDGSpecPath() { +#if !os(Android) //Test without setting the environment variable let testCookie = HTTPCookie(properties: [ .name: "TestCookie0", @@ -287,5 +288,6 @@ class TestHTTPCookieStorage: XCTestCase { let terminationReason = task.terminationReason XCTAssertEqual(terminationReason, Process.TerminationReason.exit) try? fm.removeItem(atPath: testPath) +#endif } } diff --git a/TestFoundation/TestISO8601DateFormatter.swift b/TestFoundation/TestISO8601DateFormatter.swift index 2173a2218c..5806ddb3b0 100644 --- a/TestFoundation/TestISO8601DateFormatter.swift +++ b/TestFoundation/TestISO8601DateFormatter.swift @@ -100,6 +100,7 @@ class TestISO8601DateFormatter: XCTestCase { isoFormatter.formatOptions = [.withMonth, .withDay, .withWeekOfYear, .withDashSeparatorInDate] XCTAssertEqual(isoFormatter.string(from: someDateTime!), "10-W40-06") +#if !os(Android) /* The following tests cover various cases when changing the .formatOptions property with a different TimeZone set. */ @@ -141,7 +142,7 @@ class TestISO8601DateFormatter: XCTestCase { isoFormatter.formatOptions = [.withDay, .withWeekOfYear, .withMonth, .withTimeZone, .withColonSeparatorInTimeZone, .withDashSeparatorInDate] XCTAssertEqual(isoFormatter.string(from: someDateTime!), "10-W40-06-07:00") - +#endif } @@ -248,6 +249,7 @@ class TestISO8601DateFormatter: XCTestCase { formatOptions = [.withMonth, .withDay, .withWeekOfYear, .withDashSeparatorInDate] XCTAssertEqual(ISO8601DateFormatter.string(from: someDateTime!, timeZone: timeZone!, formatOptions: formatOptions), "10-W40-06") +#if !os(Android) /* The following tests cover various cases when changing the .formatOptions property with a different TimeZone set. */ @@ -289,7 +291,7 @@ class TestISO8601DateFormatter: XCTestCase { formatOptions = [.withDay, .withWeekOfYear, .withMonth, .withTimeZone, .withColonSeparatorInTimeZone, .withDashSeparatorInDate] XCTAssertEqual(ISO8601DateFormatter.string(from: someDateTime!, timeZone: timeZone!, formatOptions: formatOptions), "10-W40-06-07:00") - +#endif } } diff --git a/TestFoundation/TestJSONEncoder.swift b/TestFoundation/TestJSONEncoder.swift index 76dc81a6b4..cfb2011045 100644 --- a/TestFoundation/TestJSONEncoder.swift +++ b/TestFoundation/TestJSONEncoder.swift @@ -354,11 +354,15 @@ class TestJSONEncoder : XCTestCase { } func test_codingOfInt64() { +#if !arch(arm) test_codingOf(value: Int64(-9000000000000000042), toAndFrom: "-9000000000000000042") +#endif } func test_codingOfUInt64() { +#if !arch(arm) test_codingOf(value: UInt64(9000000000000000042), toAndFrom: "9000000000000000042") +#endif } func test_codingOfInt() { @@ -367,7 +371,11 @@ class TestJSONEncoder : XCTestCase { case 4: // 32-bit test_codingOf(value: Int(-2000000042), toAndFrom: "-2000000042") case 8: // 64-bit +#if arch(arm) + break +#else test_codingOf(value: Int(-9000000000000000042), toAndFrom: "-9000000000000000042") +#endif default: XCTFail("Unexpected UInt size: \(intSize)") } @@ -379,7 +387,11 @@ class TestJSONEncoder : XCTestCase { case 4: // 32-bit test_codingOf(value: UInt(2000000042), toAndFrom: "2000000042") case 8: // 64-bit +#if arch(arm) + break +#else test_codingOf(value: UInt(9000000000000000042), toAndFrom: "9000000000000000042") +#endif default: XCTFail("Unexpected UInt size: \(uintSize)") } diff --git a/TestFoundation/TestNSAttributedString.swift b/TestFoundation/TestNSAttributedString.swift index edeb6d1814..a1f2a35cdb 100644 --- a/TestFoundation/TestNSAttributedString.swift +++ b/TestFoundation/TestNSAttributedString.swift @@ -155,6 +155,10 @@ class TestNSAttributedString : XCTestCase { } func test_enumerateAttributes() { +#if os(Android) + // Invalid dictionary returned by CFAttributedStringGetAttributesAndLongestEffectiveRange + XCTFail("Intermittent failures on Android") +#else let string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus consectetur et sem vitae consectetur. Nam venenatis lectus a laoreet blandit." let attrKey1 = "attribute.placeholder.key1" @@ -213,6 +217,7 @@ class TestNSAttributedString : XCTestCase { } XCTAssertEqual(rangeDescriptionString, "(0,10)") XCTAssertEqual(attrsDescriptionString, "[attribute.placeholder.key1:attribute.placeholder.value1]") +#endif } } diff --git a/TestFoundation/TestNSData.swift b/TestFoundation/TestNSData.swift index 3bacd6e2b0..6045edefc2 100644 --- a/TestFoundation/TestNSData.swift +++ b/TestFoundation/TestNSData.swift @@ -513,7 +513,7 @@ class TestNSData: XCTestCase { func test_writeToURLOptions() { let saveData = try! Data(contentsOf: Bundle.main.url(forResource: "Test", withExtension: "plist")!) - let savePath = URL(fileURLWithPath: "/var/tmp/Test.plist") + let savePath = URL(fileURLWithPath: NSTemporaryDirectory() + "Test1.plist") do { try saveData.write(to: savePath, options: .atomic) let fileManager = FileManager.default diff --git a/TestFoundation/TestNSLocale.swift b/TestFoundation/TestNSLocale.swift index 3f9a48e0b7..11398ef416 100644 --- a/TestFoundation/TestNSLocale.swift +++ b/TestFoundation/TestNSLocale.swift @@ -115,12 +115,16 @@ class TestNSLocale : XCTestCase { } func test_localeProperties(){ +#if os(Android) + XCTFail("Locale lookup unavailable on Android") +#else let enUSID = "en_US" let locale = Locale(identifier: enUSID) XCTAssertEqual(String(describing: locale.languageCode!), "en") XCTAssertEqual(String(describing: locale.decimalSeparator!), ".") XCTAssertEqual(String(describing: locale.currencyCode!), "USD") XCTAssertEqual(String(describing: locale.collatorIdentifier!), enUSID) +#endif } } diff --git a/TestFoundation/TestNSNumber.swift b/TestFoundation/TestNSNumber.swift index 9d2ac9c8c7..28a7b800f7 100644 --- a/TestFoundation/TestNSNumber.swift +++ b/TestFoundation/TestNSNumber.swift @@ -297,7 +297,12 @@ class TestNSNumber : XCTestCase { let uintSize = MemoryLayout.size switch uintSize { case 4: XCTAssertEqual(NSNumber(value: Int16.min).uintValue, 4294934528) - case 8: XCTAssertEqual(NSNumber(value: Int16.min).uintValue, 18446744073709518848) + case 8: +#if arch(arm) + break +#else + XCTAssertEqual(NSNumber(value: Int16.min).uintValue, 18446744073709518848) +#endif default: XCTFail("Unexpected UInt size: \(uintSize)") } @@ -402,7 +407,12 @@ class TestNSNumber : XCTestCase { let uintSize = MemoryLayout.size switch uintSize { case 4: XCTAssertEqual(NSNumber(value: Int32.min).uintValue, 2147483648) - case 8: XCTAssertEqual(NSNumber(value: Int32.min).uintValue, 18446744071562067968) + case 8: +#if arch(arm) + break +#else + XCTAssertEqual(NSNumber(value: Int32.min).uintValue, 18446744071562067968) +#endif default: XCTFail("Unexpected UInt size: \(uintSize)") } @@ -466,7 +476,12 @@ class TestNSNumber : XCTestCase { let intSize = MemoryLayout.size switch intSize { case 4: XCTAssertEqual(NSNumber(value: UInt32.max).intValue, -1) - case 8: XCTAssertEqual(NSNumber(value: UInt32.max).intValue, 4294967295) + case 8: +#if arch(arm) + break +#else + XCTAssertEqual(NSNumber(value: UInt32.max).intValue, 4294967295) +#endif default: XCTFail("Unexpected Int size: \(intSize)") } XCTAssertEqual(NSNumber(value: UInt32.max).uintValue, 4294967295) @@ -511,14 +526,24 @@ class TestNSNumber : XCTestCase { let intSize = MemoryLayout.size switch intSize { case 4: XCTAssertEqual(NSNumber(value: Int64.min).intValue, 0) - case 8: XCTAssertEqual(NSNumber(value: Int64.min).intValue, -9223372036854775808) + case 8: +#if arch(arm) + break +#else + XCTAssertEqual(NSNumber(value: Int64.min).intValue, -9223372036854775808) +#endif default: XCTFail("Unexpected Int size: \(intSize)") } let uintSize = MemoryLayout.size switch uintSize { case 4: XCTAssertEqual(NSNumber(value: Int64.min).uintValue, 0) - case 8: XCTAssertEqual(NSNumber(value: Int64.min).uintValue, 9223372036854775808) + case 8: +#if arch(arm) + break +#else + XCTAssertEqual(NSNumber(value: Int64.min).uintValue, 9223372036854775808) +#endif default: XCTFail("Unexpected UInt size: \(uintSize)") } @@ -541,13 +566,23 @@ class TestNSNumber : XCTestCase { switch intSize { case 4: XCTAssertEqual(NSNumber(value: Int64.max).intValue, -1) - case 8: XCTAssertEqual(NSNumber(value: Int64.max).intValue, 9223372036854775807) + case 8: +#if arch(arm) + break +#else + XCTAssertEqual(NSNumber(value: Int64.max).intValue, 9223372036854775807) +#endif default: XCTFail("Unexpected Int size: \(intSize)") } switch uintSize { case 4: XCTAssertEqual(NSNumber(value: Int64.max).uintValue, 4294967295) - case 8: XCTAssertEqual(NSNumber(value: Int64.max).uintValue, 9223372036854775807) + case 8: +#if arch(arm) + break +#else + XCTAssertEqual(NSNumber(value: Int64.max).uintValue, 9223372036854775807) +#endif default: XCTFail("Unexpected UInt size: \(uintSize)") } @@ -592,7 +627,12 @@ class TestNSNumber : XCTestCase { let uintSize = MemoryLayout.size switch uintSize { case 4: XCTAssertEqual(NSNumber(value: UInt64.max).uintValue, 4294967295) - case 8: XCTAssertEqual(NSNumber(value: UInt64.max).uintValue, 18446744073709551615) + case 8: +#if arch(arm) + break +#else + XCTAssertEqual(NSNumber(value: UInt64.max).uintValue, 18446744073709551615) +#endif default: XCTFail("Unexpected UInt size: \(uintSize)") } @@ -638,8 +678,9 @@ class TestNSNumber : XCTestCase { XCTAssertEqual(NSNumber(value: Int.min).uint64Value, 18446744071562067968) XCTAssertEqual(NSNumber(value: Int.min).intValue, -2147483648) +#if !arch(arm) XCTAssertEqual(NSNumber(value: Int.min).uintValue, 18446744071562067968) - +#endif XCTAssertEqual(NSNumber(value: Int.min).floatValue, Float(Int.min)) XCTAssertEqual(NSNumber(value: Int.min).doubleValue, Double(Int.min)) @@ -664,6 +705,9 @@ class TestNSNumber : XCTestCase { XCTAssertEqual(NSNumber(value: Int.max).doubleValue, Double(Int.max)) case (8, 8): +#if arch(arm) + break +#else XCTAssertEqual(NSNumber(value: Int.min).boolValue, false) XCTAssertEqual(NSNumber(value: Int.min).int8Value, 0) @@ -701,7 +745,7 @@ class TestNSNumber : XCTestCase { XCTAssertEqual(NSNumber(value: Int.max).floatValue, Float(Int.max)) XCTAssertEqual(NSNumber(value: Int.max).doubleValue, Double(Int.max)) - +#endif default: XCTFail("Unexpected mismatched Int & UInt sizes: \(intSize) & \(uintSize)") } } @@ -743,7 +787,9 @@ class TestNSNumber : XCTestCase { XCTAssertEqual(NSNumber(value: UInt.max).uint32Value, 4294967295) XCTAssertEqual(NSNumber(value: UInt.max).uint64Value, 4294967295) +#if !arch(arm) XCTAssertEqual(NSNumber(value: UInt.max).intValue, 4294967295) +#endif XCTAssertEqual(NSNumber(value: UInt.max).uintValue, 4294967295) XCTAssertEqual(NSNumber(value: UInt.max).floatValue, Float(UInt.max)) @@ -763,7 +809,9 @@ class TestNSNumber : XCTestCase { XCTAssertEqual(NSNumber(value: UInt.max).uint64Value, 18446744073709551615) XCTAssertEqual(NSNumber(value: UInt.max).intValue, -1) +#if !arch(arm) XCTAssertEqual(NSNumber(value: UInt.max).uintValue, 18446744073709551615) +#endif XCTAssertEqual(NSNumber(value: UInt.max).floatValue, Float(UInt.max)) XCTAssertEqual(NSNumber(value: UInt.max).doubleValue, Double(UInt.max)) diff --git a/TestFoundation/TestNSString.swift b/TestFoundation/TestNSString.swift index e75bd4ff05..1cdfc37a6c 100644 --- a/TestFoundation/TestNSString.swift +++ b/TestFoundation/TestNSString.swift @@ -913,7 +913,7 @@ class TestNSString : XCTestCase { let path = NSString(string: "~\(userName)/") let result = path.expandingTildeInPath // next assert fails in VirtualBox because home directory for unknown user resolved to /var/run/vboxadd - XCTAssert(result == "~\(userName)", "Return copy of reciver if home directory could no be resolved.") + XCTAssertEqual(result, "~\(userName)", "Return copy of receiver if home directory could not be resolved.") } } diff --git a/TestFoundation/TestNumberFormatter.swift b/TestFoundation/TestNumberFormatter.swift index 02914ad54d..7a470b243c 100644 --- a/TestFoundation/TestNumberFormatter.swift +++ b/TestFoundation/TestNumberFormatter.swift @@ -162,9 +162,11 @@ class TestNumberFormatter: XCTestCase { numberFormatter.plusSign = sign XCTAssertEqual(numberFormatter.plusSign, sign) +#if !os(Android) let formattedString = numberFormatter.string(from: 420000000000000000) XCTAssertNotNil(formattedString) XCTAssertEqual(formattedString, "4.2E👍17") +#endif // Verify a negative exponent does not have the 👍 let noPlusString = numberFormatter.string(from: -0.420) diff --git a/TestFoundation/TestProcess.swift b/TestFoundation/TestProcess.swift index d19340bc10..8ebc3cef00 100644 --- a/TestFoundation/TestProcess.swift +++ b/TestFoundation/TestProcess.swift @@ -17,6 +17,9 @@ class TestProcess : XCTestCase { static var allTests: [(String, (TestProcess) -> () throws -> Void)] { +#if os(Android) + return [] +#else return [ ("test_exit0" , test_exit0), ("test_exit1" , test_exit1), @@ -34,8 +37,10 @@ class TestProcess : XCTestCase { ("test_no_environment", test_no_environment), ("test_custom_environment", test_custom_environment), ] +#endif } +#if !os(Android) func test_exit0() { let process = Process() @@ -281,6 +286,7 @@ class TestProcess : XCTestCase { XCTFail("Test failed: \(error)") } } +#endif } private func mkstemp(template: String, body: (FileHandle) throws -> Void) rethrows { @@ -303,6 +309,7 @@ private enum Error: Swift.Error { case InvalidEnvironmentVariable(String) } +#if !os(Android) private func runTask(_ arguments: [String], environment: [String: String]? = nil, currentDirectoryPath: String? = nil) throws -> (String, String) { let process = Process() @@ -353,5 +360,5 @@ private func parseEnv(_ env: String) throws -> [String: String] { } return result } - +#endif diff --git a/TestFoundation/TestThread.swift b/TestFoundation/TestThread.swift index 6098b02466..f5b224b8e3 100644 --- a/TestFoundation/TestThread.swift +++ b/TestFoundation/TestThread.swift @@ -20,6 +20,9 @@ import CoreFoundation class TestThread : XCTestCase { static var allTests: [(String, (TestThread) -> () throws -> Void)] { +#if os(Android) + return [] +#endif return [ ("test_currentThread", test_currentThread ), ("test_threadStart", test_threadStart), diff --git a/TestFoundation/TestTimeZone.swift b/TestFoundation/TestTimeZone.swift index d696c932c6..2bbb523fc8 100644 --- a/TestFoundation/TestTimeZone.swift +++ b/TestFoundation/TestTimeZone.swift @@ -121,6 +121,9 @@ class TestTimeZone: XCTestCase { } func test_localizedName() { +#if os(Android) + XCTFail("Named timezones not available on Android") +#else let initialTimeZone = NSTimeZone.default NSTimeZone.default = TimeZone(identifier: "America/New_York")! let defaultTimeZone = NSTimeZone.default @@ -132,6 +135,7 @@ class TestTimeZone: XCTestCase { XCTAssertEqual(defaultTimeZone.localizedName(for: .shortDaylightSaving, locale: locale), "EDT") XCTAssertEqual(defaultTimeZone.localizedName(for: .shortGeneric, locale: locale), "ET") NSTimeZone.default = initialTimeZone //reset the TimeZone +#endif } func test_initializingTimeZoneWithOffset() { diff --git a/TestFoundation/TestURL.swift b/TestFoundation/TestURL.swift index 1ce0bf9e1f..0a9b652730 100644 --- a/TestFoundation/TestURL.swift +++ b/TestFoundation/TestURL.swift @@ -78,6 +78,9 @@ class TestURL : XCTestCase { #if os(OSX) let baseURL = URL(fileURLWithPath: homeDirectory, isDirectory: true) let relativePath = "Documents" + #elseif os(Android) + let baseURL = URL(fileURLWithPath: "/data", isDirectory: true) + let relativePath = "local" #elseif os(Linux) let baseURL = URL(fileURLWithPath: "/usr", isDirectory: true) let relativePath = "include" @@ -260,6 +263,10 @@ class TestURL : XCTestCase { return false } + #if os(Android) + chdir("/data/local/tmp") + #endif + let cwd = FileManager.default.currentDirectoryPath let cwdURL = URL(fileURLWithPath: cwd, isDirectory: true) // 1 for path separator @@ -309,7 +316,7 @@ class TestURL : XCTestCase { let actualLength = strlen(fileSystemRep) // 1 for path separator let expectedLength = UInt(strlen(TestURL.gFileDoesNotExistName)) + TestURL.gRelativeOffsetFromBaseCurrentWorkingDirectory - XCTAssertTrue(UInt(actualLength) == expectedLength, "fileSystemRepresentation was too short") + XCTAssertEqual(UInt(actualLength), expectedLength, "fileSystemRepresentation was too short") XCTAssertTrue(strncmp(TestURL.gBaseCurrentWorkingDirectoryPath, fileSystemRep, Int(strlen(TestURL.gBaseCurrentWorkingDirectoryPath))) == 0, "fileSystemRepresentation of base path is wrong") let lengthOfRelativePath = Int(strlen(TestURL.gFileDoesNotExistName)) let relativePath = fileSystemRep.advanced(by: Int(TestURL.gRelativeOffsetFromBaseCurrentWorkingDirectory)) @@ -364,7 +371,7 @@ class TestURL : XCTestCase { let actualLength = UInt(strlen(fileSystemRep)) // 1 for path separator let expectedLength = UInt(strlen(TestURL.gFileDoesNotExistName)) + TestURL.gRelativeOffsetFromBaseCurrentWorkingDirectory - XCTAssertTrue(actualLength == expectedLength, "fileSystemRepresentation was too short") + XCTAssertEqual(actualLength, expectedLength, "fileSystemRepresentation was too short") XCTAssertTrue(strncmp(TestURL.gBaseCurrentWorkingDirectoryPath, fileSystemRep, Int(strlen(TestURL.gBaseCurrentWorkingDirectoryPath))) == 0, "fileSystemRepresentation of base path is wrong") let lengthOfRelativePath = Int(strlen(TestURL.gFileDoesNotExistName)) let relativePath = fileSystemRep.advanced(by: Int(TestURL.gRelativeOffsetFromBaseCurrentWorkingDirectory)) @@ -426,7 +433,11 @@ class TestURL : XCTestCase { } func test_reachable() { + #if os(Android) + var url = URL(fileURLWithPath: "/data") + #else var url = URL(fileURLWithPath: "/usr") + #endif XCTAssertEqual(true, try? url.checkResourceIsReachable()) url = URL(string: "https://www.swift.org")! @@ -451,7 +462,11 @@ class TestURL : XCTestCase { XCTFail() } + #if os(Android) + var nsURL = NSURL(fileURLWithPath: "/data") + #else var nsURL = NSURL(fileURLWithPath: "/usr") + #endif XCTAssertEqual(true, try? nsURL.checkResourceIsReachable()) nsURL = NSURL(string: "https://www.swift.org")! diff --git a/TestFoundation/TestURLSession.swift b/TestFoundation/TestURLSession.swift index c941f1c9a7..0a535e9c7f 100644 --- a/TestFoundation/TestURLSession.swift +++ b/TestFoundation/TestURLSession.swift @@ -212,6 +212,9 @@ class TestURLSession : LoopbackServerTest { } func test_cancelTask() { +#if os(Android) + XCTFail("Intermittent failures on Android") +#else let urlString = "http://127.0.0.1:\(TestURLSession.serverPort)/Peru" let url = URL(string: urlString)! let d = DataTask(with: expectation(description: "GET \(urlString): task cancelation")) @@ -219,6 +222,7 @@ class TestURLSession : LoopbackServerTest { d.run(with: url) d.cancel() waitForExpectations(timeout: 12) +#endif } func test_verifyRequestHeaders() { @@ -467,10 +471,16 @@ class TestURLSession : LoopbackServerTest { } func test_concurrentRequests() { +#if os(Android) + let tasks = 10 + XCTFail("640 tasks causes other tests to fail on Android") +#else + let tasks = 640 +#endif let syncQ = dispatchQueueMake("test_dataTaskWithURL.syncQ") var dataTasks: [DataTask] = [] let g = dispatchGroupMake() - for f in 0..<640 { + for f in 0..