|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 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 | +package com.example.swift; |
| 16 | + |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | +import org.swift.swiftkit.ffm.AllocatingSwiftArena; |
| 19 | + |
| 20 | +import static org.junit.jupiter.api.Assertions.*; |
| 21 | + |
| 22 | +public class DataImportTest { |
| 23 | + @Test |
| 24 | + void test_Data_receiveAndReturn() { |
| 25 | + try (var arena = AllocatingSwiftArena.ofConfined()) { |
| 26 | + var origBytes = arena.allocateFrom("foobar"); |
| 27 | + var origDat = Data.init(origBytes, origBytes.byteSize(), arena); |
| 28 | + assertEquals(7, origDat.getCount()); |
| 29 | + |
| 30 | + var retDat = MySwiftLibrary.globalReceiveReturnData(origDat, arena); |
| 31 | + assertEquals(7, retDat.getCount()); |
| 32 | + retDat.withUnsafeBytes((retBytes) -> { |
| 33 | + assertEquals(7, retBytes.byteSize()); |
| 34 | + var str = retBytes.getString(0); |
| 35 | + assertEquals("foobar", str); |
| 36 | + }); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + void test_DataProtocol_receive() { |
| 42 | + try (var arena = AllocatingSwiftArena.ofConfined()) { |
| 43 | + var bytes = arena.allocateFrom("hello"); |
| 44 | + var dat = Data.init(bytes, bytes.byteSize(), arena); |
| 45 | + var result = MySwiftLibrary.globalReceiveSomeDataProtocol(dat); |
| 46 | + assertEquals(6, result); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments