Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HosseinYousefi committed Nov 28, 2024
1 parent 55a26bf commit d05f2f0
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
26 changes: 26 additions & 0 deletions pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,32 @@ class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?>
.object<$U?>(U.nullableType);
}

static final _id_setNullableU = _class.instanceMethodId(
r'setNullableU',
r'(Ljava/lang/Object;)V',
);

static final _setNullableU = _$jni.ProtectedJniExtensions.lookup<
_$jni.NativeFunction<
_$jni.JThrowablePtr Function(
_$jni.Pointer<_$jni.Void>,
_$jni.JMethodIDPtr,
_$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>(
'globalEnv_CallVoidMethod')
.asFunction<
_$jni.JThrowablePtr Function(_$jni.Pointer<_$jni.Void>,
_$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>();

/// from: `public final void setNullableU(U object)`
void setNullableU(
$U? object,
) {
final _$object = object?.reference ?? _$jni.jNullReference;
_setNullableU(reference.pointer, _id_setNullableU as _$jni.JMethodIDPtr,
_$object.pointer)
.check();
}

static final _id_hello = _class.instanceMethodId(
r'hello',
r'()Ljava/lang/String;',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.dart_lang.jnigen

class Nullabilty<T: Any?, U>(val t: T, val u: U, val nullableU: U?) {
class Nullabilty<T: Any?, U>(val t: T, val u: U, var nullableU: U?) {
fun hello(): String {
return "hello"
}
Expand Down
81 changes: 81 additions & 0 deletions pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,86 @@ void registerTests(String groupName, TestRunnerCallback test) {
expect(speed.convertValue(SpeedUnit.KmPerHour), closeTo(36, 1e-6));
});
});

group('Nullability', () {
Nullabilty<JString?, JString> testObject(Arena arena) {
return Nullabilty(
null,
'hello'.toJString(),
null,
T: JString.nullableType,
U: JString.type,
)..releasedBy(arena);
}

test('Getters', () {
using((arena) {
final obj = testObject(arena);
expect(
obj.getU().toDartString(releaseOriginal: true),
'hello',
);
expect(obj.getT(), null);
expect(obj.getNullableU(), null);
});
});
test('Setters', () {
using((arena) {
final obj = testObject(arena);
obj.setNullableU('hello'.toJString()..releasedBy(arena));
expect(
obj.getNullableU()!.toDartString(releaseOriginal: true),
'hello',
);
});
});
test('Methods', () {
using((arena) {
final obj = testObject(arena);
expect(obj.hello().toDartString(releaseOriginal: true), 'hello');
expect(
obj.nullableHello(false)!.toDartString(releaseOriginal: true),
'hello',
);
expect(obj.nullableHello(true), null);
expect(
obj
.classGenericEcho('hello'.toJString()..releasedBy(arena))
.toDartString(releaseOriginal: true),
'hello',
);
expect(
obj
.classGenericNullableEcho(
'hello'.toJString()..releasedBy(arena))!
.toDartString(releaseOriginal: true),
'hello',
);
expect(obj.classGenericNullableEcho(null), null);
expect(
obj
.methodGenericEcho(
'hello'.toJString()..releasedBy(arena),
V: JString.type,
)
.toDartString(releaseOriginal: true),
'hello',
);
expect(
obj
.methodGenericNullableEcho(
'hello'.toJString()..releasedBy(arena),
V: JString.nullableType,
)!
.toDartString(releaseOriginal: true),
'hello',
);
expect(
obj.methodGenericNullableEcho(null, V: JString.nullableType),
null,
);
});
});
});
});
}

0 comments on commit d05f2f0

Please sign in to comment.