-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename AndroidBridge to SkipAndroidBridge
- Loading branch information
Showing
9 changed files
with
127 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
Sources/AndroidBridge/Skip/skip.yml → Sources/SkipAndroidBridge/Skip/skip.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# Configuration file for https://skip.tools project | ||
skip: | ||
mode: 'swift' | ||
|
||
mode: 'kotlin' |
50 changes: 50 additions & 0 deletions
50
Sources/SkipAndroidBridge/Swift/AndroidBridgeToKotlin.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2024 Skip | ||
// | ||
// This is free software: you can redistribute and/or modify it | ||
// under the terms of the GNU Lesser General Public License 3.0 | ||
// as published by the Free Software Foundation https://fsf.org | ||
|
||
//import Foundation | ||
import SkipBridge | ||
|
||
// Current limitations on Robolectric testing require us to go through a compiled wrapper in order to perform our | ||
// tests of bridging Kotlin to Swift. | ||
|
||
// FIXME: JNI method loading is logged for SkipBridgeSamples, but not for AndroidBridge, and the native method invocations do nothing (returns null or 0, but they don't crash) | ||
// [3.972s][debug][jni,resolve] [Dynamic-linking native method skip.bridge.samples.BridgeToSwiftTestsSupportKt.Swift_testSupport_appendStrings ... JNI] | ||
|
||
// If we use the wrong name in SkopBridgeSamples, we get a good error: | ||
// testAndroidBridge$SkipBridgeSamples_debugUnitTest java.lang.UnsatisfiedLinkError: 'java.lang.String skip.bridge.samples.BridgeToSwiftTestsSupportKt.Swift_testSupport_appendStrings(java.lang.String, java.lang.String)' | ||
|
||
|
||
|
||
// SKIP @BridgeToKotlin | ||
func testSupport_appendStrings(_ a: String, _ b: String) -> String { | ||
a + b | ||
} | ||
|
||
// SKIP @BridgeToKotlin | ||
func testSupport_isSkipMode() -> Int64 { | ||
#if SKIP | ||
fatalError("testSupport_isSkipMode should never be transpiled") | ||
return -1 // this should NEVER be transpiled | ||
#else | ||
//fatalError("### testSupport_isSkipMode NEVER CALLED") | ||
let mode = isAndroidBridgeToSwiftTranspiled() | ||
if mode == 0 { | ||
fatalError("### MODE WAS 0!") | ||
} | ||
return mode | ||
#endif | ||
} | ||
|
||
// SKIP @BridgeToKotlin | ||
func testSupport_getJavaSystemProperty(_ name: String) -> String? { | ||
getJavaSystemProperty(name) | ||
} | ||
|
||
// SKIP @BridgeToKotlin | ||
func testSupport_getAndroidContext() -> AndroidContext! { | ||
AndroidContext.shared | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 Skip | ||
// | ||
// This is free software: you can redistribute and/or modify it | ||
// under the terms of the GNU Lesser General Public License 3.0 | ||
// as published by the Free Software Foundation https://fsf.org | ||
|
||
import XCTest | ||
import OSLog | ||
import Foundation | ||
import SkipBridge | ||
@testable import SkipAndroidBridge | ||
|
||
let logger: Logger = Logger(subsystem: "SkipAndroidBridge", category: "Tests") | ||
|
||
@available(macOS 13, *) | ||
final class AndroidBridgeTests: XCTestCase { | ||
override func setUp() { | ||
#if SKIP | ||
loadPeerLibrary(packageName: "skip-android-bridge", moduleName: "SkipAndroidBridge") | ||
#endif | ||
} | ||
|
||
func testSampleFunction() throws { | ||
XCTAssertEqual("ABCXYZ", testSupport_appendStrings("ABC", "XYZ")) | ||
} | ||
|
||
func testAndroidBridge() throws { | ||
let mode = testSupport_isSkipMode() | ||
XCTAssertEqual(isJava ? 1 : -2, mode, "@BridgeToSwift should be transpiled: \(mode)") | ||
|
||
#if SKIP | ||
let tmpdir = testSupport_getJavaSystemProperty("java.io.tmpdir") | ||
XCTAssertEqual(isRobolectric ? NSTemporaryDirectory() : "/data/user/0/skip.android.bridge.test/cache", tmpdir) | ||
|
||
XCTAssertNotNil(ProcessInfo.processInfo.androidContext, "ProcessInfo.processInfo.androidContext was nil") | ||
|
||
let context = AndroidContext.shared | ||
|
||
XCTAssertNotNil(context, "bridged context was nil") | ||
|
||
let filesDir = URL(fileURLWithPath: context.filesDir, isDirectory: true) | ||
let cacheDir = URL(fileURLWithPath: context.cacheDir, isDirectory: true) | ||
|
||
// Robolectric's files folder is tough to predict /var/folders/zl/wkdjv4s1271fbm6w0plzknkh0000gn/T/robolectric-AndroidBridgeTests_testAndroidBridge_SkipAndroidBridge_debugUnitTest10131350412654065418/skip.android.bridge.test-dataDir/files | ||
if !isRobolectric { | ||
// …but Android is predictable | ||
XCTAssertEqual("/data/user/0/skip.android.bridge.test/files", filesDir) | ||
XCTAssertEqual("/data/user/0/skip.android.bridge.test/cache", cacheDir) | ||
} | ||
|
||
// make sure we can read and write to the filesDir | ||
try "ABC".write(to: filesDir.appendingPathComponent("test.txt"), atomically: true, encoding: .utf8) | ||
try "XYZ".write(to: cacheDir.appendingPathComponent("test.txt"), atomically: true, encoding: .utf8) | ||
#endif | ||
} | ||
} |
File renamed without changes.
File renamed without changes.