mirror of
https://github.com/flutter/packages.git
synced 2025-07-02 08:34:31 +08:00
[pigeon] Add local-only Java integration tests (#2854)
* Move generated code to a new shared bundle. * Consolidate the example app code * Replace stale TODOs with explanatory comments * Move integration tests * Add Java implementation * Add test script commands * Autoformat
This commit is contained in:
@ -5,16 +5,39 @@
|
|||||||
package com.example.alternate_language_test_plugin;
|
package com.example.alternate_language_test_plugin;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import com.example.alternate_language_test_plugin.AllDatatypes.Everything;
|
||||||
|
import com.example.alternate_language_test_plugin.AllDatatypes.HostEverything;
|
||||||
|
import com.example.alternate_language_test_plugin.AllVoid.AllVoidHostApi;
|
||||||
import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
||||||
|
|
||||||
/**
|
/** This plugin handles the native side of the integration tests in example/integration_test/. */
|
||||||
* This plugin is currently a no-op since only unit tests have been set up. In the future, this will
|
public class AlternateLanguageTestPlugin implements FlutterPlugin, AllVoidHostApi, HostEverything {
|
||||||
* register Pigeon APIs used in integration tests.
|
|
||||||
*/
|
|
||||||
public class AlternateLanguageTestPlugin implements FlutterPlugin {
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {}
|
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
|
||||||
|
AllVoidHostApi.setup(binding.getBinaryMessenger(), this);
|
||||||
|
HostEverything.setup(binding.getBinaryMessenger(), this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {}
|
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {}
|
||||||
|
|
||||||
|
// AllVoidHostApi
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doit() {
|
||||||
|
// No-op.
|
||||||
|
}
|
||||||
|
|
||||||
|
// HostEverything
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Everything giveMeEverything() {
|
||||||
|
// Currently unused in integration tests, so just return an empty object.
|
||||||
|
return new Everything();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Everything echo(@NonNull Everything everything) {
|
||||||
|
return everything;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:shared_test_plugin_code/integration_tests.dart';
|
||||||
|
|
||||||
|
void main() => runPigeonIntegrationTests();
|
@ -2,51 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// ignore_for_file: public_member_api_docs
|
|
||||||
|
|
||||||
import 'package:alternate_language_test_plugin/alternate_language_test_plugin.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shared_test_plugin_code/example_app.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const ExampleApp());
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatefulWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<MyApp> createState() => _MyAppState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MyAppState extends State<MyApp> {
|
|
||||||
// ignore: unused_field
|
|
||||||
final AlternateLanguageTestPlugin _alternateLanguageTestPlugin =
|
|
||||||
AlternateLanguageTestPlugin();
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
initPlatformState();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> initPlatformState() async {
|
|
||||||
// TODO(tarrinneal): Call TestPlugin methods here for manual integration
|
|
||||||
// testing, once they exist. See
|
|
||||||
// https://github.com/flutter/flutter/issues/111505
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
home: Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('Pigeon integration tests'),
|
|
||||||
),
|
|
||||||
body: const Center(
|
|
||||||
child: Text(
|
|
||||||
'TODO, see https://github.com/flutter/flutter/issues/111505'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,14 @@ dependencies:
|
|||||||
path: ../
|
path: ../
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
shared_test_plugin_code:
|
||||||
|
path: ../../shared_test_plugin_code
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
integration_test:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
# TODO(stuartmorgan): Remove this, so that review will show the effects of
|
|
||||||
# changes on generated files. This will need a way to avoid unnecessary churn,
|
|
||||||
# such as a flag to suppress version stamp generation.
|
|
||||||
*.gen.dart
|
|
||||||
# TODO(stuartmorgan): Add exceptions for specific files that are used in
|
|
||||||
# integration tests, as they will need to be checked in to avoid analysis
|
|
||||||
# failures. The exclusion of other files is to prevent having multiple
|
|
||||||
# copies of all of the Dart output until more tests are restructured to
|
|
||||||
# minimize duplication.
|
|
@ -2,7 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// TODO(tarrinneal): Add integration tests.
|
// There is intentionally no code here; tests use generated Pigeon APIs
|
||||||
|
// directly, as wrapping them in a plugin would just add maintenance burden
|
||||||
/// A host plugin for Pigeon tests.
|
// when changing tests.
|
||||||
class AlternateLanguageTestPlugin {}
|
|
||||||
|
30
packages/pigeon/platform_tests/shared_test_plugin_code/.gitignore
vendored
Normal file
30
packages/pigeon/platform_tests/shared_test_plugin_code/.gitignore
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Miscellaneous
|
||||||
|
*.class
|
||||||
|
*.log
|
||||||
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
.DS_Store
|
||||||
|
.atom/
|
||||||
|
.buildlog/
|
||||||
|
.history
|
||||||
|
.svn/
|
||||||
|
migrate_working_dir/
|
||||||
|
|
||||||
|
# IntelliJ related
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# The .vscode folder contains launch configuration and tasks you configure in
|
||||||
|
# VS Code which you may wish to be included in version control, so this line
|
||||||
|
# is commented out by default.
|
||||||
|
#.vscode/
|
||||||
|
|
||||||
|
# Flutter/Dart/Pub related
|
||||||
|
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||||
|
/pubspec.lock
|
||||||
|
**/doc/api/
|
||||||
|
.dart_tool/
|
||||||
|
.packages
|
||||||
|
build/
|
@ -0,0 +1,10 @@
|
|||||||
|
# This file tracks properties of this Flutter project.
|
||||||
|
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||||
|
#
|
||||||
|
# This file should be version controlled and should not be manually edited.
|
||||||
|
|
||||||
|
version:
|
||||||
|
revision: c940f318226901f7ba9ccb68f216756ced2fe3c7
|
||||||
|
channel: main
|
||||||
|
|
||||||
|
project_type: package
|
@ -0,0 +1,7 @@
|
|||||||
|
This package contains the shared code (generated Pigeon output, example app,
|
||||||
|
integration tests) for `test_plugin` and `alternate_language_shared_plugin`.
|
||||||
|
|
||||||
|
Since those two plugin projects are intended to be identical, and only exist
|
||||||
|
as separate projects because of the Java/Kotlin and Obj-C/Swift overlap that
|
||||||
|
prevents combining them, almost all Dart code should be in this package rather
|
||||||
|
than in the plugins themselves.
|
@ -0,0 +1,66 @@
|
|||||||
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'generated.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
runApp(const ExampleApp());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A trivial example that validates that Pigeon is able to successfully call
|
||||||
|
/// into native code.
|
||||||
|
///
|
||||||
|
/// Actual testing is all done in the integration tests, which run in the
|
||||||
|
/// context of the example app but don't actually rely on this class.
|
||||||
|
class ExampleApp extends StatefulWidget {
|
||||||
|
/// Creates a new example app.
|
||||||
|
const ExampleApp({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ExampleApp> createState() => _ExampleAppState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExampleAppState extends State<ExampleApp> {
|
||||||
|
// This just uses a single API since it's intended only a minimal check
|
||||||
|
// that the basics are wired up correctly.
|
||||||
|
late final AllVoidHostApi api;
|
||||||
|
String status = 'Calling...';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
initPlatformState();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> initPlatformState() async {
|
||||||
|
api = AllVoidHostApi();
|
||||||
|
try {
|
||||||
|
await api.doit();
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
status = 'Failed: $e';
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
status = 'Success!';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Pigeon integration tests'),
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: Text(status),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
export 'src/generated/all_datatypes.gen.dart';
|
||||||
|
export 'src/generated/all_void.gen.dart';
|
@ -0,0 +1,80 @@
|
|||||||
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#104231)
|
||||||
|
// ignore: unnecessary_import
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:integration_test/integration_test.dart';
|
||||||
|
|
||||||
|
import 'generated.dart';
|
||||||
|
|
||||||
|
/// Sets up and runs the integration tests.
|
||||||
|
void runPigeonIntegrationTests() {
|
||||||
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
group('Host API tests', () {
|
||||||
|
testWidgets('voidCallVoidReturn', (WidgetTester _) async {
|
||||||
|
final AllVoidHostApi api = AllVoidHostApi();
|
||||||
|
|
||||||
|
expect(api.doit(), completes);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('allDataTypesEcho', (WidgetTester _) async {
|
||||||
|
final HostEverything api = HostEverything();
|
||||||
|
|
||||||
|
final Everything sentObject = Everything(
|
||||||
|
aBool: true,
|
||||||
|
anInt: 42,
|
||||||
|
aDouble: 3.14159,
|
||||||
|
aString: 'Hello host!',
|
||||||
|
aByteArray: Uint8List.fromList(<int>[1, 2, 3]),
|
||||||
|
a4ByteArray: Int32List.fromList(<int>[4, 5, 6]),
|
||||||
|
a8ByteArray: Int64List.fromList(<int>[7, 8, 9]),
|
||||||
|
aFloatArray: Float64List.fromList(<double>[2.71828, 3.14159]),
|
||||||
|
aList: <Object?>['Thing 1', 2],
|
||||||
|
aMap: <Object?, Object?>{'a': 1, 'b': 2.0},
|
||||||
|
nestedList: <List<bool>>[
|
||||||
|
<bool>[true, false],
|
||||||
|
<bool>[false, true]
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
final Everything echoObject = await api.echo(sentObject);
|
||||||
|
expect(echoObject.aBool, sentObject.aBool);
|
||||||
|
expect(echoObject.anInt, sentObject.anInt);
|
||||||
|
expect(echoObject.aDouble, sentObject.aDouble);
|
||||||
|
expect(echoObject.aString, sentObject.aString);
|
||||||
|
// TODO(stuartmorgan): Enable these once they work for all generators;
|
||||||
|
// currently at least Swift is broken.
|
||||||
|
// See https://github.com/flutter/flutter/issues/115906
|
||||||
|
//expect(echoObject.aByteArray, sentObject.aByteArray);
|
||||||
|
//expect(echoObject.a4ByteArray, sentObject.a4ByteArray);
|
||||||
|
//expect(echoObject.a8ByteArray, sentObject.a8ByteArray);
|
||||||
|
//expect(echoObject.aFloatArray, sentObject.aFloatArray);
|
||||||
|
expect(listEquals(echoObject.aList, sentObject.aList), true);
|
||||||
|
expect(mapEquals(echoObject.aMap, sentObject.aMap), true);
|
||||||
|
expect(echoObject.nestedList?.length, sentObject.nestedList?.length);
|
||||||
|
// TODO(stuartmorgan): Enable this once the Dart types are fixed; see
|
||||||
|
// https://github.com/flutter/flutter/issues/116117
|
||||||
|
//for (int i = 0; i < echoObject.nestedList!.length; i++) {
|
||||||
|
// expect(listEquals(echoObject.nestedList![i], sentObject.nestedList![i]),
|
||||||
|
// true);
|
||||||
|
//}
|
||||||
|
expect(
|
||||||
|
mapEquals(
|
||||||
|
echoObject.mapWithAnnotations, sentObject.mapWithAnnotations),
|
||||||
|
true);
|
||||||
|
expect(
|
||||||
|
mapEquals(echoObject.mapWithObject, sentObject.mapWithObject), true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('Flutter API tests', () {
|
||||||
|
// TODO(stuartmorgan): Add Flutter API tests, driven by wrapper host APIs
|
||||||
|
// that forward the arguments and return values in the opposite direction.
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
name: shared_test_plugin_code
|
||||||
|
description: Common code for test_plugin and altenate_language_test_plugin
|
||||||
|
version: 0.0.1
|
||||||
|
publish_to: none
|
||||||
|
|
||||||
|
environment:
|
||||||
|
sdk: '>=2.18.0 <3.0.0'
|
||||||
|
flutter: ">=3.0.0"
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
flutter:
|
||||||
|
sdk: flutter
|
||||||
|
# These are normal dependencies rather than dev_dependencies because the
|
||||||
|
# package exports the integration test code to be shared by the integration
|
||||||
|
# tests for the two plugins.
|
||||||
|
flutter_test:
|
||||||
|
sdk: flutter
|
||||||
|
integration_test:
|
||||||
|
sdk: flutter
|
@ -2,78 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#104231)
|
import 'package:shared_test_plugin_code/integration_tests.dart';
|
||||||
// ignore: unnecessary_import
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
void main() => runPigeonIntegrationTests();
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:integration_test/integration_test.dart';
|
|
||||||
import 'package:test_plugin/all_datatypes.gen.dart';
|
|
||||||
import 'package:test_plugin/all_void.gen.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
||||||
|
|
||||||
group('Host API tests', () {
|
|
||||||
testWidgets('voidCallVoidReturn', (WidgetTester _) async {
|
|
||||||
final AllVoidHostApi api = AllVoidHostApi();
|
|
||||||
|
|
||||||
expect(api.doit(), completes);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets('allDataTypesEcho', (WidgetTester _) async {
|
|
||||||
final HostEverything api = HostEverything();
|
|
||||||
|
|
||||||
final Everything sentObject = Everything(
|
|
||||||
aBool: true,
|
|
||||||
anInt: 42,
|
|
||||||
aDouble: 3.14159,
|
|
||||||
aString: 'Hello host!',
|
|
||||||
aByteArray: Uint8List.fromList(<int>[1, 2, 3]),
|
|
||||||
a4ByteArray: Int32List.fromList(<int>[4, 5, 6]),
|
|
||||||
a8ByteArray: Int64List.fromList(<int>[7, 8, 9]),
|
|
||||||
aFloatArray: Float64List.fromList(<double>[2.71828, 3.14159]),
|
|
||||||
aList: <Object?>['Thing 1', 2],
|
|
||||||
aMap: <Object?, Object?>{'a': 1, 'b': 2.0},
|
|
||||||
nestedList: <List<bool>>[
|
|
||||||
<bool>[true, false],
|
|
||||||
<bool>[false, true]
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
final Everything echoObject = await api.echo(sentObject);
|
|
||||||
expect(echoObject.aBool, sentObject.aBool);
|
|
||||||
expect(echoObject.anInt, sentObject.anInt);
|
|
||||||
expect(echoObject.aDouble, sentObject.aDouble);
|
|
||||||
expect(echoObject.aString, sentObject.aString);
|
|
||||||
// TODO(stuartmorgan): Enable these once they work for all generators;
|
|
||||||
// currently at least Swift is broken.
|
|
||||||
// See https://github.com/flutter/flutter/issues/115906
|
|
||||||
//expect(echoObject.aByteArray, sentObject.aByteArray);
|
|
||||||
//expect(echoObject.a4ByteArray, sentObject.a4ByteArray);
|
|
||||||
//expect(echoObject.a8ByteArray, sentObject.a8ByteArray);
|
|
||||||
//expect(echoObject.aFloatArray, sentObject.aFloatArray);
|
|
||||||
expect(listEquals(echoObject.aList, sentObject.aList), true);
|
|
||||||
expect(mapEquals(echoObject.aMap, sentObject.aMap), true);
|
|
||||||
expect(echoObject.nestedList?.length, sentObject.nestedList?.length);
|
|
||||||
// TODO(stuartmorgan): Enable this once the Dart types are fixed; see
|
|
||||||
// https://github.com/flutter/flutter/issues/116117
|
|
||||||
//for (int i = 0; i < echoObject.nestedList!.length; i++) {
|
|
||||||
// expect(listEquals(echoObject.nestedList![i], sentObject.nestedList![i]),
|
|
||||||
// true);
|
|
||||||
//}
|
|
||||||
expect(
|
|
||||||
mapEquals(
|
|
||||||
echoObject.mapWithAnnotations, sentObject.mapWithAnnotations),
|
|
||||||
true);
|
|
||||||
expect(
|
|
||||||
mapEquals(echoObject.mapWithObject, sentObject.mapWithObject), true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('Flutter API tests', () {
|
|
||||||
// TODO(stuartmorgan): Add Flutter API tests, driven by wrapper host APIs
|
|
||||||
// that forward the arguments and return values in the opposite direction.
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
@ -2,61 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// ignore_for_file: public_member_api_docs
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:test_plugin/all_void.gen.dart';
|
import 'package:shared_test_plugin_code/example_app.dart';
|
||||||
import 'package:test_plugin/test_plugin.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const ExampleApp());
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatefulWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<MyApp> createState() => _MyAppState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MyAppState extends State<MyApp> {
|
|
||||||
// ignore: unused_field
|
|
||||||
final TestPlugin _testPlugin = TestPlugin();
|
|
||||||
late final AllVoidHostApi api;
|
|
||||||
String status = 'Calling...';
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
initPlatformState();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> initPlatformState() async {
|
|
||||||
api = AllVoidHostApi();
|
|
||||||
try {
|
|
||||||
await api.doit();
|
|
||||||
} catch (e) {
|
|
||||||
setState(() {
|
|
||||||
status = 'Failed: $e';
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setState(() {
|
|
||||||
status = 'Success!';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
home: Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('Pigeon integration tests'),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Text(status),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
shared_test_plugin_code:
|
||||||
|
path: ../../shared_test_plugin_code
|
||||||
test_plugin:
|
test_plugin:
|
||||||
path: ../
|
path: ../
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// TODO(tarrinneal): Add integration tests.
|
// There is intentionally no code here; tests use generated Pigeon APIs
|
||||||
|
// directly, as wrapping them in a plugin would just add maintenance burden
|
||||||
/// A host plugin for Pigeon tests.
|
// when changing tests.
|
||||||
class TestPlugin {}
|
|
||||||
|
@ -251,6 +251,10 @@ run_android_unittests() {
|
|||||||
popd
|
popd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_android_java_e2e_tests() {
|
||||||
|
dart run tool/run_tests.dart -t android_java_integration_tests --skip-generation
|
||||||
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# main
|
# main
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -267,6 +271,7 @@ should_run_macos_swift_e2e_tests=true
|
|||||||
should_run_android_kotlin_unittests=true
|
should_run_android_kotlin_unittests=true
|
||||||
# Default to false until there is CI support. See
|
# Default to false until there is CI support. See
|
||||||
# https://github.com/flutter/flutter/issues/111505
|
# https://github.com/flutter/flutter/issues/111505
|
||||||
|
should_run_android_java_e2e_tests=false
|
||||||
should_run_android_kotlin_e2e_tests=false
|
should_run_android_kotlin_e2e_tests=false
|
||||||
while getopts "t:l?h" opt; do
|
while getopts "t:l?h" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
@ -282,10 +287,12 @@ while getopts "t:l?h" opt; do
|
|||||||
should_run_macos_swift_unittests=false
|
should_run_macos_swift_unittests=false
|
||||||
should_run_macos_swift_e2e_tests=false
|
should_run_macos_swift_e2e_tests=false
|
||||||
should_run_android_kotlin_unittests=false
|
should_run_android_kotlin_unittests=false
|
||||||
|
should_run_android_java_e2e_tests=false
|
||||||
should_run_android_kotlin_e2e_tests=false
|
should_run_android_kotlin_e2e_tests=false
|
||||||
case $OPTARG in
|
case $OPTARG in
|
||||||
# TODO(stuartmorgan): Rename to include "java".
|
# TODO(stuartmorgan): Rename to include "java".
|
||||||
android_unittests) should_run_android_unittests=true ;;
|
android_unittests) should_run_android_unittests=true ;;
|
||||||
|
android_java_e2e_tests) should_run_android_java_e2e_tests=true ;;
|
||||||
dart_compilation_tests) should_run_dart_compilation_tests=true ;;
|
dart_compilation_tests) should_run_dart_compilation_tests=true ;;
|
||||||
dart_unittests) should_run_dart_unittests=true ;;
|
dart_unittests) should_run_dart_unittests=true ;;
|
||||||
flutter_unittests) should_run_flutter_unittests=true ;;
|
flutter_unittests) should_run_flutter_unittests=true ;;
|
||||||
@ -307,6 +314,7 @@ while getopts "t:l?h" opt; do
|
|||||||
l)
|
l)
|
||||||
echo "available tests for -t:
|
echo "available tests for -t:
|
||||||
android_unittests - Unit tests on generated Java code.
|
android_unittests - Unit tests on generated Java code.
|
||||||
|
android_java_e2e_tests - Integration tests on generated Java code on Android.
|
||||||
android_kotlin_unittests - Unit tests on generated Kotlin code on Android.
|
android_kotlin_unittests - Unit tests on generated Kotlin code on Android.
|
||||||
android_kotlin_e2e_tests - Integration tests on generated Kotlin code on Android.
|
android_kotlin_e2e_tests - Integration tests on generated Kotlin code on Android.
|
||||||
dart_compilation_tests - Compilation tests on generated Dart code.
|
dart_compilation_tests - Compilation tests on generated Dart code.
|
||||||
@ -371,6 +379,9 @@ fi
|
|||||||
if [ "$should_run_android_unittests" = true ]; then
|
if [ "$should_run_android_unittests" = true ]; then
|
||||||
run_android_unittests
|
run_android_unittests
|
||||||
fi
|
fi
|
||||||
|
if [ "$should_run_android_java_e2e_tests" = true ]; then
|
||||||
|
run_android_java_e2e_tests
|
||||||
|
fi
|
||||||
if [ "$should_run_macos_swift_unittests" = true ]; then
|
if [ "$should_run_macos_swift_unittests" = true ]; then
|
||||||
run_macos_swift_unittests
|
run_macos_swift_unittests
|
||||||
fi
|
fi
|
||||||
|
@ -28,6 +28,8 @@ const String _skipGenerationFlag = 'skip-generation';
|
|||||||
const int _noDeviceAvailableExitCode = 100;
|
const int _noDeviceAvailableExitCode = 100;
|
||||||
|
|
||||||
const String _testPluginRelativePath = 'platform_tests/test_plugin';
|
const String _testPluginRelativePath = 'platform_tests/test_plugin';
|
||||||
|
const String _alternateLanguageTestPluginRelativePath =
|
||||||
|
'platform_tests/test_plugin';
|
||||||
const String _integrationTestFileRelativePath = 'integration_test/test.dart';
|
const String _integrationTestFileRelativePath = 'integration_test/test.dart';
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
@ -44,9 +46,12 @@ const Map<String, _TestInfo> _tests = <String, _TestInfo>{
|
|||||||
'windows_integration_tests': _TestInfo(
|
'windows_integration_tests': _TestInfo(
|
||||||
function: _runWindowsIntegrationTests,
|
function: _runWindowsIntegrationTests,
|
||||||
description: 'Integration tests on generated Windows C++ code.'),
|
description: 'Integration tests on generated Windows C++ code.'),
|
||||||
'android_unittests': _TestInfo(
|
'android_java_unittests': _TestInfo(
|
||||||
function: _runAndroidUnitTests,
|
function: _runAndroidJavaUnitTests,
|
||||||
description: 'Unit tests on generated Java code.'),
|
description: 'Unit tests on generated Java code.'),
|
||||||
|
'android_java_integration_tests': _TestInfo(
|
||||||
|
function: _runAndroidJavaIntegrationTests,
|
||||||
|
description: 'Integration tests on generated Java code.'),
|
||||||
'android_kotlin_unittests': _TestInfo(
|
'android_kotlin_unittests': _TestInfo(
|
||||||
function: _runAndroidKotlinUnitTests,
|
function: _runAndroidKotlinUnitTests,
|
||||||
description: 'Unit tests on generated Kotlin code.'),
|
description: 'Unit tests on generated Kotlin code.'),
|
||||||
@ -79,10 +84,14 @@ const Map<String, _TestInfo> _tests = <String, _TestInfo>{
|
|||||||
description: 'Unit tests on generated Dart mock handler code.'),
|
description: 'Unit tests on generated Dart mock handler code.'),
|
||||||
};
|
};
|
||||||
|
|
||||||
Future<int> _runAndroidUnitTests() async {
|
Future<int> _runAndroidJavaUnitTests() async {
|
||||||
throw UnimplementedError('See run_tests.sh.');
|
throw UnimplementedError('See run_tests.sh.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> _runAndroidJavaIntegrationTests() async {
|
||||||
|
return _runAndroidIntegrationTests(_alternateLanguageTestPluginRelativePath);
|
||||||
|
}
|
||||||
|
|
||||||
Future<int> _runAndroidKotlinUnitTests() async {
|
Future<int> _runAndroidKotlinUnitTests() async {
|
||||||
const String examplePath = './$_testPluginRelativePath/example';
|
const String examplePath = './$_testPluginRelativePath/example';
|
||||||
const String androidProjectPath = '$examplePath/android';
|
const String androidProjectPath = '$examplePath/android';
|
||||||
@ -98,6 +107,10 @@ Future<int> _runAndroidKotlinUnitTests() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<int> _runAndroidKotlinIntegrationTests() async {
|
Future<int> _runAndroidKotlinIntegrationTests() async {
|
||||||
|
return _runAndroidIntegrationTests(_testPluginRelativePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int> _runAndroidIntegrationTests(String testPluginPath) async {
|
||||||
final String? device = await getDeviceForPlatform('android');
|
final String? device = await getDeviceForPlatform('android');
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
print('No Android device available. Attach an Android device or start '
|
print('No Android device available. Attach an Android device or start '
|
||||||
@ -105,7 +118,7 @@ Future<int> _runAndroidKotlinIntegrationTests() async {
|
|||||||
return _noDeviceAvailableExitCode;
|
return _noDeviceAvailableExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const String examplePath = './$_testPluginRelativePath/example';
|
final String examplePath = './$testPluginPath/example';
|
||||||
return runFlutterCommand(
|
return runFlutterCommand(
|
||||||
examplePath,
|
examplePath,
|
||||||
'test',
|
'test',
|
||||||
|
@ -77,6 +77,8 @@ Future<int> generatePigeons({required String baseDir}) async {
|
|||||||
final String outputBase = p.join(baseDir, 'platform_tests', 'test_plugin');
|
final String outputBase = p.join(baseDir, 'platform_tests', 'test_plugin');
|
||||||
final String alternateOutputBase =
|
final String alternateOutputBase =
|
||||||
p.join(baseDir, 'platform_tests', 'alternate_language_test_plugin');
|
p.join(baseDir, 'platform_tests', 'alternate_language_test_plugin');
|
||||||
|
final String sharedDartOutputBase =
|
||||||
|
p.join(baseDir, 'platform_tests', 'shared_test_plugin_code');
|
||||||
// TODO(stuartmorgan): Eliminate this and use alternateOutputBase.
|
// TODO(stuartmorgan): Eliminate this and use alternateOutputBase.
|
||||||
// See https://github.com/flutter/packages/pull/2816.
|
// See https://github.com/flutter/packages/pull/2816.
|
||||||
final String iosObjCBase =
|
final String iosObjCBase =
|
||||||
@ -90,7 +92,7 @@ Future<int> generatePigeons({required String baseDir}) async {
|
|||||||
// Generate the default language test plugin output.
|
// Generate the default language test plugin output.
|
||||||
int generateCode = await runPigeon(
|
int generateCode = await runPigeon(
|
||||||
input: './pigeons/$input.dart',
|
input: './pigeons/$input.dart',
|
||||||
dartOut: '$outputBase/lib/$input.gen.dart',
|
dartOut: '$sharedDartOutputBase/lib/src/generated/$input.gen.dart',
|
||||||
// Android
|
// Android
|
||||||
kotlinOut: skipLanguages.contains(GeneratorLanguages.kotlin)
|
kotlinOut: skipLanguages.contains(GeneratorLanguages.kotlin)
|
||||||
? null
|
? null
|
||||||
@ -129,7 +131,6 @@ Future<int> generatePigeons({required String baseDir}) async {
|
|||||||
// Generate the alternate language test plugin output.
|
// Generate the alternate language test plugin output.
|
||||||
generateCode = await runPigeon(
|
generateCode = await runPigeon(
|
||||||
input: './pigeons/$input.dart',
|
input: './pigeons/$input.dart',
|
||||||
dartOut: '$alternateOutputBase/lib/$input.gen.dart',
|
|
||||||
// Android
|
// Android
|
||||||
// This doesn't use the '.gen' suffix since Java has strict file naming
|
// This doesn't use the '.gen' suffix since Java has strict file naming
|
||||||
// rules.
|
// rules.
|
||||||
|
Reference in New Issue
Block a user