Skip to content

Commit 69cfa27

Browse files
committed
[android] fix android test builds to ensure they work with new Android overlay module
1 parent 44773d2 commit 69cfa27

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

Tests/Foundation/FTPServer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Dispatch
1515
import Glibc
1616
#elseif canImport(Darwin)
1717
import Darwin
18+
#elseif canImport(Android)
19+
import Android
1820
#endif
1921

2022
public class ServerSemaphore {

Tests/Foundation/HTTPServer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import Dispatch
2121
import Darwin
2222
#elseif canImport(Glibc)
2323
import Glibc
24+
#elseif canImport(Android)
25+
import Android
2426
#endif
2527

2628
#if !os(Windows)

Tests/Foundation/Tests/TestFileHandle.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,14 @@ class TestFileHandle : XCTestCase {
111111
#else
112112
var fds: [Int32] = [-1, -1]
113113
fds.withUnsafeMutableBufferPointer { (pointer) -> Void in
114-
pipe(pointer.baseAddress)
114+
let baseAddress = pointer.baseAddress
115+
#if canImport(Android)
116+
// pipe takes in a non-nullable pointer in the Android NDK only.
117+
guard let baseAddress else {
118+
return
119+
}
120+
#endif
121+
pipe(baseAddress)
115122
}
116123

117124
close(fds[1])

Tests/Foundation/Tests/TestNSData.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ class TestNSData: LoopbackServerTest {
589589
let permission = try fileManager._permissionsOfItem(atPath: url.path)
590590
#if canImport(Darwin)
591591
let expected = Int(S_IRUSR) | Int(S_IWUSR) | Int(S_IRGRP) | Int(S_IWGRP) | Int(S_IROTH) | Int(S_IWOTH)
592+
#elseif canImport(Android)
593+
let expected = Int(Android.S_IRUSR) | Int(Android.S_IWUSR) | Int(Android.S_IRGRP) | Int(Android.S_IWGRP) | Int(Android.S_IROTH) | Int(Android.S_IWOTH)
592594
#else
593595
let expected = Int(Glibc.S_IRUSR) | Int(Glibc.S_IWUSR) | Int(Glibc.S_IRGRP) | Int(Glibc.S_IWGRP) | Int(Glibc.S_IROTH) | Int(Glibc.S_IWOTH)
594596
#endif
@@ -612,6 +614,8 @@ class TestNSData: LoopbackServerTest {
612614
let permission = try fileManager._permissionsOfItem(atPath: url.path)
613615
#if canImport(Darwin)
614616
let expected = Int(S_IRUSR) | Int(S_IWUSR) | Int(S_IRGRP) | Int(S_IWGRP) | Int(S_IROTH) | Int(S_IWOTH)
617+
#elseif canImport(Android)
618+
let expected = Int(Android.S_IRUSR) | Int(Android.S_IWUSR) | Int(Android.S_IRGRP) | Int(Android.S_IWGRP) | Int(Android.S_IROTH) | Int(Android.S_IWOTH)
615619
#else
616620
let expected = Int(Glibc.S_IRUSR) | Int(Glibc.S_IWUSR) | Int(Glibc.S_IRGRP) | Int(Glibc.S_IWGRP) | Int(Glibc.S_IROTH) | Int(Glibc.S_IWOTH)
617621
#endif

Tests/Foundation/Tests/TestTimeZone.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ class TestTimeZone: XCTestCase {
160160
var lt = tm()
161161
localtime_r(&t, &lt)
162162
let zoneName = NSTimeZone.system.abbreviation() ?? "Invalid Abbreviation"
163-
let expectedName = String(cString: lt.tm_zone, encoding: .ascii) ?? "Invalid Zone"
163+
// tm_zone is nullable in the Android NDK only.
164+
let tm_zone: UnsafePointer<CChar>? = lt.tm_zone
165+
guard let tm_zone else {
166+
return
167+
}
168+
let expectedName = String(cString: tm_zone, encoding: .ascii) ?? "Invalid Zone"
164169
XCTAssertEqual(zoneName, expectedName, "expected name \"\(expectedName)\" is not equal to \"\(zoneName)\"")
165170
}
166171
#endif

Tests/Foundation/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import Darwin
1414
#elseif canImport(Glibc)
1515
import Glibc
16+
#elseif canImport(Android)
17+
import Android
1618
#elseif canImport(CRT)
1719
import CRT
1820
#endif

0 commit comments

Comments
 (0)