|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2026 Apple Inc. and the Swift.org project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of Swift.org project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +import JExtractSwiftLib |
| 16 | +import SwiftJavaConfigurationShared |
| 17 | +import Testing |
| 18 | + |
| 19 | +struct TimeIntervalTests { |
| 20 | + @Test( |
| 21 | + "Import: accept TimeInterval (resolves to Double)", |
| 22 | + arguments: [ |
| 23 | + ( |
| 24 | + JExtractGenerationMode.jni, |
| 25 | + /* expected Java chunks */ |
| 26 | + [ |
| 27 | + """ |
| 28 | + public static void delay(double seconds) { |
| 29 | + SwiftModule.$delay(seconds); |
| 30 | + } |
| 31 | + """ |
| 32 | + ], |
| 33 | + /* expected Swift chunks */ |
| 34 | + [ |
| 35 | + """ |
| 36 | + @_cdecl("Java_com_example_swift_SwiftModule__00024delay__D") |
| 37 | + public func Java_com_example_swift_SwiftModule__00024delay__D(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, seconds: jdouble) { |
| 38 | + SwiftModule.delay(seconds: Double(fromJNI: seconds, in: environment)) |
| 39 | + } |
| 40 | + """ |
| 41 | + ], |
| 42 | + ) |
| 43 | + ] |
| 44 | + ) |
| 45 | + func func_accept_timeInterval( |
| 46 | + mode: JExtractGenerationMode, |
| 47 | + expectedJavaChunks: [String], |
| 48 | + expectedSwiftChunks: [String] |
| 49 | + ) throws { |
| 50 | + let text = |
| 51 | + """ |
| 52 | + import Foundation |
| 53 | +
|
| 54 | + public func delay(seconds: TimeInterval) |
| 55 | + """ |
| 56 | + |
| 57 | + try assertOutput( |
| 58 | + input: text, |
| 59 | + mode, |
| 60 | + .java, |
| 61 | + detectChunkByInitialLines: 1, |
| 62 | + expectedChunks: expectedJavaChunks |
| 63 | + ) |
| 64 | + |
| 65 | + try assertOutput( |
| 66 | + input: text, |
| 67 | + mode, |
| 68 | + .swift, |
| 69 | + detectChunkByInitialLines: 1, |
| 70 | + expectedChunks: expectedSwiftChunks |
| 71 | + ) |
| 72 | + } |
| 73 | + |
| 74 | + @Test( |
| 75 | + "Import: return TimeInterval (resolves to Double)", |
| 76 | + arguments: [ |
| 77 | + ( |
| 78 | + JExtractGenerationMode.jni, |
| 79 | + /* expected Java chunks */ |
| 80 | + [ |
| 81 | + """ |
| 82 | + public static double now() { |
| 83 | + return SwiftModule.$now(); |
| 84 | + } |
| 85 | + """ |
| 86 | + ], |
| 87 | + /* expected Swift chunks */ |
| 88 | + [ |
| 89 | + """ |
| 90 | + @_cdecl("Java_com_example_swift_SwiftModule__00024now__") |
| 91 | + public func Java_com_example_swift_SwiftModule__00024now__(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass) -> jdouble { |
| 92 | + return SwiftModule.now() |
| 93 | + } |
| 94 | + """ |
| 95 | + ] |
| 96 | + ) |
| 97 | + ] |
| 98 | + ) |
| 99 | + func func_return_timeInterval( |
| 100 | + mode: JExtractGenerationMode, |
| 101 | + expectedJavaChunks: [String], |
| 102 | + expectedSwiftChunks: [String] |
| 103 | + ) throws { |
| 104 | + let text = |
| 105 | + """ |
| 106 | + import Foundation |
| 107 | + public func now() -> TimeInterval |
| 108 | + """ |
| 109 | + |
| 110 | + try assertOutput( |
| 111 | + input: text, |
| 112 | + mode, |
| 113 | + .java, |
| 114 | + detectChunkByInitialLines: 1, |
| 115 | + expectedChunks: expectedJavaChunks |
| 116 | + ) |
| 117 | + |
| 118 | + try assertOutput( |
| 119 | + input: text, |
| 120 | + mode, |
| 121 | + .swift, |
| 122 | + detectChunkByInitialLines: 1, |
| 123 | + expectedChunks: expectedSwiftChunks |
| 124 | + ) |
| 125 | + } |
| 126 | +} |
0 commit comments