Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-hegde committed Jul 8, 2022
1 parent 9762fca commit b506a9b
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
Expand Down Expand Up @@ -129,6 +129,7 @@ jobs:
- run: flutter config --enable-linux-desktop
- run: flutter pub get
- run: flutter test
- run: flutter test integration_test/integration_test.dart -d linux
- run: flutter build linux

build_jni_example_windows:
Expand All @@ -147,6 +148,7 @@ jobs:
java-version: '11'
- run: flutter config --enable-windows-desktop
- run: flutter pub get
- run: flutter test integration_test/integration_test.dart -d windows
- run: flutter build windows

build_jni_example_macos:
Expand Down
39 changes: 39 additions & 0 deletions jni/example/integration_test/integration_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'dart:io';
// import 'package:path/path.dart' as path;
import 'package:ffi/ffi.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:jni/jni.dart';

void main() {
if (!Platform.isAndroid) {
Jni.spawn();
}

var jni = Jni.getInstance();

testWidgets('Manually lookup & call Long.toHexString static method',
(tester) async {
final arena = Arena();
final env = jni.getEnv();

final longClass = env.FindClass("java/lang/Long".toNativeChars(arena));
final hexMethod = env.GetStaticMethodID(
longClass,
"toHexString".toNativeChars(arena),
"(J)Ljava/lang/String;".toNativeChars(arena));

for (var i in [1, 80, 13, 76, 1134453224145]) {
final jres = env.CallStaticObjectMethodA(
longClass, hexMethod, Jni.jvalues([JValueLong(i)], allocator: arena));

final res = env.asDartString(jres);
expect(res, equals(i.toRadixString(16)));

env.DeleteLocalRef(jres);
}
env.DeleteLocalRef(longClass);
arena.releaseAll();
});
}
80 changes: 79 additions & 1 deletion jni/example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.11"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -43,6 +50,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -64,11 +78,23 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_driver:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
Expand All @@ -81,6 +107,16 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
integration_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
jni:
dependency: "direct main"
description:
Expand Down Expand Up @@ -117,19 +153,33 @@ packages:
source: hosted
version: "1.7.0"
path:
dependency: transitive
dependency: "direct main"
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.4"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -163,6 +213,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
sync_http:
dependency: transitive
description:
name: sync_http
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
term_glyph:
dependency: transitive
description:
Expand All @@ -177,12 +234,33 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "8.2.2"
webdriver:
dependency: transitive
description:
name: webdriver
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
sdks:
dart: ">=2.17.5 <3.0.0"
4 changes: 3 additions & 1 deletion jni/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies:
sdk: flutter

ffi:

path:
jni:
# When depending on this package from a real application you should use:
# jni: ^x.y.z
Expand All @@ -47,6 +47,8 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter

# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
Expand Down

0 comments on commit b506a9b

Please sign in to comment.