1313//===----------------------------------------------------------------------===//
1414
1515import JExtractSwiftLib
16+ import SwiftJavaConfigurationShared
1617import Testing
1718
1819@ Suite
@@ -35,6 +36,8 @@ struct JNIVariablesTests {
3536 }
3637 public var someBoolean: Bool
3738 public var isBoolean: Bool
39+ public private(set) var privateSetCounter: Int64
40+ public internal(set) var internalSetCounter: Int64
3841 }
3942 """
4043
@@ -447,4 +450,135 @@ struct JNIVariablesTests {
447450 ]
448451 )
449452 }
453+
454+ @ Test
455+ func privateSetCounter_javaBindings ( ) throws {
456+ try assertOutput (
457+ input : membersSource ,
458+ . jni ,
459+ . java ,
460+ detectChunkByInitialLines : 8 ,
461+ expectedChunks : [
462+ """
463+ /**
464+ * Downcall to Swift:
465+ * {@snippet lang=swift :
466+ * public private(set) var privateSetCounter: Int64
467+ * }
468+ */
469+ public long getPrivateSetCounter() {
470+ return MyClass.$getPrivateSetCounter(this.$memoryAddress());
471+ }
472+ """ ,
473+ """
474+ private static native long $getPrivateSetCounter(long selfPointer);
475+ """ ,
476+ ] ,
477+ notExpectedChunks : [
478+ " setPrivateSetCounter " ,
479+ " $setPrivateSetCounter " ,
480+ ]
481+ )
482+ }
483+
484+ @ Test
485+ func privateSetCounter_swiftThunks ( ) throws {
486+ try assertOutput (
487+ input : membersSource ,
488+ . jni ,
489+ . swift ,
490+ detectChunkByInitialLines : 1 ,
491+ expectedChunks : [
492+ """
493+ @_cdecl( " Java_com_example_swift_MyClass__00024getPrivateSetCounter__J " )
494+ public func Java_com_example_swift_MyClass__00024getPrivateSetCounter__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, selfPointer: jlong) -> jlong {
495+ ...
496+ return selfPointer$.pointee.privateSetCounter.getJNILocalRefValue(in: environment)
497+ }
498+ """
499+ ] ,
500+ notExpectedChunks : [
501+ " setPrivateSetCounter "
502+ ]
503+ )
504+ }
505+
506+ @ Test
507+ func internalSetCounter_javaBindings ( ) throws {
508+ try assertOutput (
509+ input : membersSource ,
510+ . jni ,
511+ . java ,
512+ detectChunkByInitialLines : 8 ,
513+ expectedChunks : [
514+ """
515+ /**
516+ * Downcall to Swift:
517+ * {@snippet lang=swift :
518+ * public internal(set) var internalSetCounter: Int64
519+ * }
520+ */
521+ public long getInternalSetCounter() {
522+ return MyClass.$getInternalSetCounter(this.$memoryAddress());
523+ }
524+ """ ,
525+ """
526+ private static native long $getInternalSetCounter(long selfPointer);
527+ """ ,
528+ ] ,
529+ notExpectedChunks : [
530+ " setInternalSetCounter " ,
531+ " $setInternalSetCounter " ,
532+ ]
533+ )
534+ }
535+
536+ @ Test
537+ func packageSet_javaBindings_atPackageLevel ( ) throws {
538+ let src =
539+ """
540+ public class MyClass {
541+ public package(set) var packageSetCounter: Int64
542+ }
543+ """
544+ var config = Configuration ( )
545+ config . minimumInputAccessLevelMode = . package
546+ try assertOutput (
547+ input : src ,
548+ config : config ,
549+ . jni ,
550+ . java ,
551+ detectChunkByInitialLines : 8 ,
552+ expectedChunks : [
553+ """
554+ /**
555+ * Downcall to Swift:
556+ * {@snippet lang=swift :
557+ * public package(set) var packageSetCounter: Int64
558+ * }
559+ */
560+ public long getPackageSetCounter() {
561+ return MyClass.$getPackageSetCounter(this.$memoryAddress());
562+ }
563+ """ ,
564+ """
565+ /**
566+ * Downcall to Swift:
567+ * {@snippet lang=swift :
568+ * public package(set) var packageSetCounter: Int64
569+ * }
570+ */
571+ public void setPackageSetCounter(long newValue) {
572+ MyClass.$setPackageSetCounter(newValue, this.$memoryAddress());
573+ }
574+ """ ,
575+ """
576+ private static native long $getPackageSetCounter(long selfPointer);
577+ """ ,
578+ """
579+ private static native void $setPackageSetCounter(long newValue, long selfPointer);
580+ """ ,
581+ ]
582+ )
583+ }
450584}
0 commit comments