Skip to content

Commit 36d05c7

Browse files
committed
[JExtract/FFM] Add Data and DataProtocol tests
Also, run Samples:SwiftKitSampleApp:test in CI
1 parent 21cff45 commit 36d05c7

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

Samples/SwiftKitSampleApp/Sources/MySwiftLibrary/MySwiftLibrary.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ public func withBuffer(body: (UnsafeRawBufferPointer) -> Void) {
6363
body(globalBuffer)
6464
}
6565

66-
public func globalReceiveSomeDataProtocol(data: some DataProtocol) {
66+
public func globalReceiveSomeDataProtocol(data: some DataProtocol) -> Int {
6767
p(Array(data).description)
68+
return data.count
6869
}
6970

7071
// ==== Internal helpers

Samples/SwiftKitSampleApp/ci-validate.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
set -x
44
set -e
55

6-
./gradlew run
6+
./gradlew run
7+
./gradlew test
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)