|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2024 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 JExtractSwift |
| 16 | +import Testing |
| 17 | + |
| 18 | +struct ClassPrintingTests { |
| 19 | + let class_interfaceFile = |
| 20 | + """ |
| 21 | + // swift-interface-format-version: 1.0 |
| 22 | + // swift-compiler-version: Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.7.6 clang-1600.0.24.1) |
| 23 | + // swift-module-flags: -target arm64-apple-macosx15.0 -enable-objc-interop -enable-library-evolution -module-name MySwiftLibrary |
| 24 | + import Darwin.C |
| 25 | + import Darwin |
| 26 | + import Swift |
| 27 | + import _Concurrency |
| 28 | + import _StringProcessing |
| 29 | + import _SwiftConcurrencyShims |
| 30 | +
|
| 31 | + public class MySwiftClass { |
| 32 | + public init(len: Swift.Int, cap: Swift.Int) |
| 33 | +
|
| 34 | + public func helloMemberFunction() |
| 35 | +
|
| 36 | + public func makeInt() -> Int |
| 37 | +
|
| 38 | + @objc deinit |
| 39 | + } |
| 40 | + """ |
| 41 | + |
| 42 | + @Test("Import: class layout") |
| 43 | + func class_layout() throws { |
| 44 | + let st = Swift2JavaTranslator( |
| 45 | + javaPackage: "com.example.swift", |
| 46 | + swiftModuleName: "__FakeModule" |
| 47 | + ) |
| 48 | + |
| 49 | + try assertOutput(st, input: class_interfaceFile, .java, expectedChunks: [ |
| 50 | + """ |
| 51 | + public static final SwiftAnyType TYPE_METADATA = |
| 52 | + new SwiftAnyType(SwiftKit.swiftjava.getType("__FakeModule", "MySwiftClass")); |
| 53 | + public final SwiftAnyType $swiftType() { |
| 54 | + return TYPE_METADATA; |
| 55 | + } |
| 56 | +
|
| 57 | + |
| 58 | + private static final GroupLayout $LAYOUT = (GroupLayout) SwiftValueWitnessTable.layoutOfSwiftType(TYPE_METADATA.$memorySegment()); |
| 59 | + public final GroupLayout $layout() { |
| 60 | + return $LAYOUT; |
| 61 | + } |
| 62 | + """ |
| 63 | + ]) |
| 64 | + } |
| 65 | +} |
0 commit comments