Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Windows unit tests to plugin template (#118638)
* Add Windows unit tests to plugin template Adds an example native unit test to the plugin template for Windows, matching the format we use for our 1P plugin example app unit tests. Once these have been added for all platforms+languages, they will be documented on a new plugin development page to explain their use. Since we don't appear to be running our current plugin e2e tests for Windows, this adds a new configuration to run them. I haven't `led`-tested this, so it may not work, but this will give a starting point for getting them running. Part of #82458 * Minor fix * Add test owner * Fix typo * Fix test feature flag
- Loading branch information
1 parent
4d25030
commit e3c51a2
Showing
10 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2014 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_devicelab/framework/framework.dart'; | ||
import 'package:flutter_devicelab/tasks/plugin_tests.dart'; | ||
|
||
Future<void> main() async { | ||
await task(combine(<TaskFunction>[ | ||
PluginTest('windows', <String>['--platforms=windows']).call, | ||
// Test that Dart-only plugins are supported. | ||
PluginTest('windows', <String>['--platforms=windows'], dartOnlyPlugin: true).call, | ||
// Test that FFI plugins are supported. | ||
PluginTest('windows', <String>['--platforms=windows'], template: 'plugin_ffi').call, | ||
])); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/flutter_tools/templates/plugin/windows.tmpl/test/pluginClassSnakeCase_test.cpp.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <flutter/method_call.h> | ||
#include <flutter/method_result_functions.h> | ||
#include <flutter/standard_method_codec.h> | ||
#include <gtest/gtest.h> | ||
#include <windows.h> | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <variant> | ||
|
||
#include "{{pluginClassSnakeCase}}.h" | ||
|
||
namespace {{projectName}} { | ||
namespace test { | ||
|
||
namespace { | ||
|
||
using flutter::EncodableMap; | ||
using flutter::EncodableValue; | ||
using flutter::MethodCall; | ||
using flutter::MethodResultFunctions; | ||
|
||
} // namespace | ||
|
||
TEST({{pluginClass}}, GetPlatformVersion) { | ||
{{pluginClass}} plugin; | ||
// Save the reply value from the success callback. | ||
std::string result_string; | ||
plugin.HandleMethodCall( | ||
MethodCall("getPlatformVersion", std::make_unique<EncodableValue>()), | ||
std::make_unique<MethodResultFunctions<>>( | ||
[&result_string](const EncodableValue* result) { | ||
result_string = std::get<std::string>(*result); | ||
}, | ||
nullptr, nullptr)); | ||
|
||
// Since the exact string varies by host, just ensure that it's a string | ||
// with the expected format. | ||
EXPECT_TRUE(result_string.rfind("Windows ", 0) == 0); | ||
} | ||
|
||
} // namespace test | ||
} // namespace {{projectName}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters