forked from swiftlang/swift-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaKitArrayRuntimeTests.swift
More file actions
96 lines (77 loc) · 2.42 KB
/
JavaKitArrayRuntimeTests.swift
File metadata and controls
96 lines (77 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import JavaKitExample
import SwiftJava
import Testing
@Suite
struct JavaKitArrayRuntimeTests {
let jvm = try JavaKitSampleJVM.shared
@Test
func getFixedBytes() throws {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)
let bytes: [Int8] = arrays.getFixedBytes()
#expect(bytes == [1, 2, 3, 4, 5])
}
@Test
func getEmptyBytes() throws {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)
let bytes: [Int8] = arrays.getEmptyBytes()
#expect(bytes.isEmpty)
}
@Test
func filledBytes() throws {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)
let bytes: [Int8] = arrays.filledBytes(4, 42)
#expect(bytes == [42, 42, 42, 42])
}
@Test
func reverseBytes() throws {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)
let reversed: [Int8] = arrays.reverseBytes([10, 20, 30])
#expect(reversed == [30, 20, 10])
}
@Test
func getFixedInts() throws {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)
let ints: [Int32] = arrays.getFixedInts()
#expect(ints == [100, 200, 300])
}
@Test
func doubleLongs() throws {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)
let longs: [Int64] = arrays.doubleLongs([1, 2, 3])
#expect(longs == [1, 2, 3, 1, 2, 3])
}
@Test
func stringToBytes() throws {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)
let bytes: [Int8] = arrays.stringToBytes("Hi")
// "Hi" in UTF-8 is [0x48, 0x69]
#expect(bytes == [0x48, 0x69])
}
@Test
func getGreetings() throws {
let env = try jvm.environment()
let arrays = HelloJavaKitArrays(environment: env)
let greetings: [String] = arrays.getGreetings()
#expect(greetings == ["hello", "world", "from", "java"])
}
}