Skip to content

Commit

Permalink
[pigeon] Consolidate integration test pigeons (#2859)
Browse files Browse the repository at this point in the history
* Switch to a new file for integration tests

https://xkcd.com/927/

* Remove all_datatypes.dart and migrate tests to core_tests.dart

* Remove all_void

* Missed type updates

* Typo fix for analyzer

* Fix Windows compilation

* Update ObjC integration tests for changes
  • Loading branch information
stuartmorgan committed Dec 1, 2022
1 parent 891ae3b commit 9f00b52
Show file tree
Hide file tree
Showing 37 changed files with 605 additions and 555 deletions.
5 changes: 5 additions & 0 deletions packages/pigeon/pigeons/README.md
@@ -0,0 +1,5 @@
This directory contains Pigeon API definitions used to generate code for tests.

Please do not add new files to this directory unless absolutely neccessary;
most additions should go into core_tests.dart. See
https://github.com/flutter/flutter/issues/115168 for context.
35 changes: 0 additions & 35 deletions packages/pigeon/pigeons/all_datatypes.dart

This file was deleted.

15 changes: 0 additions & 15 deletions packages/pigeon/pigeons/all_void.dart

This file was deleted.

64 changes: 64 additions & 0 deletions packages/pigeon/pigeons/core_tests.dart
@@ -0,0 +1,64 @@
// 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:pigeon/pigeon.dart';

// A class containing all supported types.
class AllTypes {
bool? aBool;
int? anInt;
double? aDouble;
String? aString;
Uint8List? aByteArray;
Int32List? a4ByteArray;
Int64List? a8ByteArray;
Float64List? aFloatArray;
// ignore: always_specify_types, strict_raw_type
List? aList;
// ignore: always_specify_types, strict_raw_type
Map? aMap;
List<List<bool?>?>? nestedList;
Map<String?, String?>? mapWithAnnotations;
Map<String?, Object?>? mapWithObject;
}

/// The core interface that each host language plugin must implement in
/// platform_test integration tests.
@HostApi()
abstract class HostIntegrationCoreApi {
/// A no-op function taking no arguments and returning no value, to sanity
/// test basic calling.
void noop();

/// Returns the passed object, to test serialization and deserialization.
@ObjCSelector('echoAllTypes:')
AllTypes echoAllTypes(AllTypes everything);

// TODO(stuartmorgan): Add wrapper methods to trigger calls back into
// FlutterIntegrationCore methods, to allow Dart-driven integration testing
// of host->Dart calls. Each wrapper would be implemented by calling the
// corresponding FlutterIntegrationCore method, passing arguments and return
// values along unchanged. Since these will need to be async, we also need
// async host API tests here, so that failures in Dart->host async calling
// don't only show up here.
}

/// The core interface that the Dart platform_test code implements for host
/// integration tests to call into.
@FlutterApi()
abstract class FlutterIntegrationCoreApi {
/// A no-op function taking no arguments and returning no value, to sanity
/// test basic calling.
void noop();

/// Returns the passed object, to test serialization and deserialization.
@ObjCSelector('echoAllTypes:')
AllTypes echoAllTypes(AllTypes everything);
}

/// An API that can be implemented for minimal, compile-only tests.
@HostApi()
abstract class HostTrivialApi {
void noop();
}
Expand Up @@ -5,39 +5,27 @@
package com.example.alternate_language_test_plugin;

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 com.example.alternate_language_test_plugin.CoreTests.AllTypes;
import com.example.alternate_language_test_plugin.CoreTests.HostIntegrationCoreApi;
import io.flutter.embedding.engine.plugins.FlutterPlugin;

/** This plugin handles the native side of the integration tests in example/integration_test/. */
public class AlternateLanguageTestPlugin implements FlutterPlugin, AllVoidHostApi, HostEverything {
public class AlternateLanguageTestPlugin implements FlutterPlugin, HostIntegrationCoreApi {
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
AllVoidHostApi.setup(binding.getBinaryMessenger(), this);
HostEverything.setup(binding.getBinaryMessenger(), this);
HostIntegrationCoreApi.setup(binding.getBinaryMessenger(), this);
}

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {}

// AllVoidHostApi
// HostIntegrationCoreApi

@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();
}
public void noop() {}

@Override
public @NonNull Everything echo(@NonNull Everything everything) {
public @NonNull AllTypes echoAllTypes(@NonNull AllTypes everything) {
return everything;
}
}
Expand Up @@ -7,7 +7,8 @@
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import com.example.alternate_language_test_plugin.AllDatatypes.*;
import com.example.alternate_language_test_plugin.CoreTests.AllTypes;
import com.example.alternate_language_test_plugin.CoreTests.FlutterIntegrationCoreApi;
import io.flutter.plugin.common.BinaryMessenger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand All @@ -19,25 +20,26 @@
public class AllDatatypesTest {
@Test
public void nullValues() {
Everything everything = new Everything();
AllTypes everything = new AllTypes();
BinaryMessenger binaryMessenger = mock(BinaryMessenger.class);
doAnswer(
invocation -> {
ByteBuffer message = invocation.getArgument(1);
BinaryMessenger.BinaryReply reply = invocation.getArgument(2);
message.position(0);
ArrayList<Object> args =
(ArrayList<Object>) FlutterEverything.getCodec().decodeMessage(message);
ByteBuffer replyData = FlutterEverything.getCodec().encodeMessage(args.get(0));
(ArrayList<Object>) FlutterIntegrationCoreApi.getCodec().decodeMessage(message);
ByteBuffer replyData =
FlutterIntegrationCoreApi.getCodec().encodeMessage(args.get(0));
replyData.position(0);
reply.reply(replyData);
return null;
})
.when(binaryMessenger)
.send(anyString(), any(), any());
FlutterEverything api = new FlutterEverything(binaryMessenger);
FlutterIntegrationCoreApi api = new FlutterIntegrationCoreApi(binaryMessenger);
boolean[] didCall = {false};
api.echo(
api.echoAllTypes(
everything,
(result) -> {
didCall[0] = true;
Expand Down Expand Up @@ -82,7 +84,7 @@ private static boolean floatArraysEqual(double[] x, double[] y) {

@Test
public void hasValues() {
Everything everything = new Everything();
AllTypes everything = new AllTypes();
everything.setABool(false);
everything.setAnInt(1234L);
everything.setADouble(2.0);
Expand All @@ -101,17 +103,18 @@ public void hasValues() {
BinaryMessenger.BinaryReply reply = invocation.getArgument(2);
message.position(0);
ArrayList<Object> args =
(ArrayList<Object>) FlutterEverything.getCodec().decodeMessage(message);
ByteBuffer replyData = FlutterEverything.getCodec().encodeMessage(args.get(0));
(ArrayList<Object>) FlutterIntegrationCoreApi.getCodec().decodeMessage(message);
ByteBuffer replyData =
FlutterIntegrationCoreApi.getCodec().encodeMessage(args.get(0));
replyData.position(0);
reply.reply(replyData);
return null;
})
.when(binaryMessenger)
.send(anyString(), any(), any());
FlutterEverything api = new FlutterEverything(binaryMessenger);
FlutterIntegrationCoreApi api = new FlutterIntegrationCoreApi(binaryMessenger);
boolean[] didCall = {false};
api.echo(
api.echoAllTypes(
everything,
(result) -> {
didCall[0] = true;
Expand All @@ -137,12 +140,12 @@ public void hasValues() {

@Test
public void integerToLong() {
Everything everything = new Everything();
AllTypes everything = new AllTypes();
everything.setAnInt(123L);
Map<String, Object> map = everything.toMap();
assertTrue(map.containsKey("anInt"));
map.put("anInt", 123);
Everything readEverything = Everything.fromMap(map);
AllTypes readEverything = AllTypes.fromMap(map);
assertEquals(readEverything.getAnInt(), everything.getAnInt());
}
}
Expand Up @@ -23,12 +23,10 @@ public void subtract() {
BinaryMessenger.BinaryReply reply = invocation.getArgument(2);
message.position(0);
ArrayList<Object> args =
(ArrayList<Object>)
AllDatatypes.FlutterEverything.getCodec().decodeMessage(message);
(ArrayList<Object>) MultipleArityFlutterApi.getCodec().decodeMessage(message);
Long arg0 = (Long) args.get(0);
Long arg1 = (Long) args.get(1);
ByteBuffer replyData =
AllDatatypes.FlutterEverything.getCodec().encodeMessage(arg0 - arg1);
ByteBuffer replyData = MultipleArityFlutterApi.getCodec().encodeMessage(arg0 - arg1);
replyData.position(0);
reply.reply(replyData);
return null;
Expand Down
Expand Up @@ -6,7 +6,7 @@
@import XCTest;

#ifdef LEGACY_HARNESS
#import "AllDatatypes.gen.h"
#import "CoreTests.gen.h"
#else
@import alternate_language_test_plugin;
#endif
Expand All @@ -21,30 +21,31 @@ @interface AllDatatypesTest : XCTestCase
@implementation AllDatatypesTest

- (void)testAllNull {
Everything *everything = [[Everything alloc] init];
AllTypes *everything = [[AllTypes alloc] init];
EchoBinaryMessenger *binaryMessenger =
[[EchoBinaryMessenger alloc] initWithCodec:FlutterEverythingGetCodec()];
FlutterEverything *api = [[FlutterEverything alloc] initWithBinaryMessenger:binaryMessenger];
[[EchoBinaryMessenger alloc] initWithCodec:FlutterIntegrationCoreApiGetCodec()];
FlutterIntegrationCoreApi *api =
[[FlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
[api echoEverything:everything
completion:^(Everything *_Nonnull result, NSError *_Nullable error) {
XCTAssertNil(result.aBool);
XCTAssertNil(result.anInt);
XCTAssertNil(result.aDouble);
XCTAssertNil(result.aString);
XCTAssertNil(result.aByteArray);
XCTAssertNil(result.a4ByteArray);
XCTAssertNil(result.a8ByteArray);
XCTAssertNil(result.aFloatArray);
XCTAssertNil(result.aList);
XCTAssertNil(result.aMap);
[expectation fulfill];
}];
[api echoAllTypes:everything
completion:^(AllTypes *_Nonnull result, NSError *_Nullable error) {
XCTAssertNil(result.aBool);
XCTAssertNil(result.anInt);
XCTAssertNil(result.aDouble);
XCTAssertNil(result.aString);
XCTAssertNil(result.aByteArray);
XCTAssertNil(result.a4ByteArray);
XCTAssertNil(result.a8ByteArray);
XCTAssertNil(result.aFloatArray);
XCTAssertNil(result.aList);
XCTAssertNil(result.aMap);
[expectation fulfill];
}];
[self waitForExpectations:@[ expectation ] timeout:1.0];
}

- (void)testAllEquals {
Everything *everything = [[Everything alloc] init];
AllTypes *everything = [[AllTypes alloc] init];
everything.aBool = @NO;
everything.anInt = @(1);
everything.aDouble = @(2.0);
Expand All @@ -61,24 +62,25 @@ - (void)testAllEquals {
everything.aMap = @{@"hello" : @(1234)};
everything.mapWithObject = @{@"hello" : @(1234), @"goodbye" : @"world"};
EchoBinaryMessenger *binaryMessenger =
[[EchoBinaryMessenger alloc] initWithCodec:FlutterEverythingGetCodec()];
FlutterEverything *api = [[FlutterEverything alloc] initWithBinaryMessenger:binaryMessenger];
[[EchoBinaryMessenger alloc] initWithCodec:FlutterIntegrationCoreApiGetCodec()];
FlutterIntegrationCoreApi *api =
[[FlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
[api echoEverything:everything
completion:^(Everything *_Nonnull result, NSError *_Nullable error) {
XCTAssertEqual(result.aBool, everything.aBool);
XCTAssertEqual(result.anInt, everything.anInt);
XCTAssertEqual(result.aDouble, everything.aDouble);
XCTAssertEqualObjects(result.aString, everything.aString);
XCTAssertEqualObjects(result.aByteArray.data, everything.aByteArray.data);
XCTAssertEqualObjects(result.a4ByteArray.data, everything.a4ByteArray.data);
XCTAssertEqualObjects(result.a8ByteArray.data, everything.a8ByteArray.data);
XCTAssertEqualObjects(result.aFloatArray.data, everything.aFloatArray.data);
XCTAssertEqualObjects(result.aList, everything.aList);
XCTAssertEqualObjects(result.aMap, everything.aMap);
XCTAssertEqualObjects(result.mapWithObject, everything.mapWithObject);
[expectation fulfill];
}];
[api echoAllTypes:everything
completion:^(AllTypes *_Nonnull result, NSError *_Nullable error) {
XCTAssertEqual(result.aBool, everything.aBool);
XCTAssertEqual(result.anInt, everything.anInt);
XCTAssertEqual(result.aDouble, everything.aDouble);
XCTAssertEqualObjects(result.aString, everything.aString);
XCTAssertEqualObjects(result.aByteArray.data, everything.aByteArray.data);
XCTAssertEqualObjects(result.a4ByteArray.data, everything.a4ByteArray.data);
XCTAssertEqualObjects(result.a8ByteArray.data, everything.a8ByteArray.data);
XCTAssertEqualObjects(result.aFloatArray.data, everything.aFloatArray.data);
XCTAssertEqualObjects(result.aList, everything.aList);
XCTAssertEqualObjects(result.aMap, everything.aMap);
XCTAssertEqualObjects(result.mapWithObject, everything.mapWithObject);
[expectation fulfill];
}];
[self waitForExpectations:@[ expectation ] timeout:1.0];
}

Expand Down
Expand Up @@ -4,8 +4,7 @@

#import <Flutter/Flutter.h>

#import "AllDatatypes.gen.h"
#import "AllVoid.gen.h"
#import "CoreTests.gen.h"

@interface AlternateLanguageTestPlugin : NSObject <FlutterPlugin, AllVoidHostApi, HostEverything>
@interface AlternateLanguageTestPlugin : NSObject <FlutterPlugin, HostIntegrationCoreApi>
@end

0 comments on commit 9f00b52

Please sign in to comment.