Test that the embedder can be launched and shut down correctly. (flutter/engine#4281)
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("$flutter_root/testing/testing.gni")
|
||||
|
||||
source_set("embedder") {
|
||||
sources = [
|
||||
"embedder.cc",
|
||||
@@ -26,6 +28,10 @@ source_set("embedder") {
|
||||
public_configs = [ "$flutter_root:config" ]
|
||||
}
|
||||
|
||||
test_fixtures("fixtures") {
|
||||
fixtures = [ "fixtures/simple_main.dart" ]
|
||||
}
|
||||
|
||||
executable("embedder_unittests") {
|
||||
testonly = true
|
||||
|
||||
@@ -37,6 +43,7 @@ executable("embedder_unittests") {
|
||||
|
||||
deps = [
|
||||
":embedder",
|
||||
":fixtures",
|
||||
"$flutter_root/testing",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#define FLUTTER_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
|
||||
#include <type_traits>
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/shell/platform/embedder/platform_view_embedder.h"
|
||||
@@ -161,8 +162,6 @@ FlutterResult FlutterEngineShutdown(FlutterEngine engine) {
|
||||
if (engine == nullptr) {
|
||||
return kInvalidArguments;
|
||||
}
|
||||
// TODO(chinmaygarde): This is currently unsupported since none of the mobile
|
||||
// shells need to do this. Add support and patch this call.
|
||||
delete reinterpret_cast<PlatformViewHolder*>(engine);
|
||||
return kSuccess;
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
void main() {}
|
||||
@@ -2,14 +2,42 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <string>
|
||||
#include "embedder.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
|
||||
TEST(EmbedderTest, MustNotRunWithInvalidArgs) {
|
||||
FlutterEngine engine = nullptr;
|
||||
FlutterRendererConfig config = {};
|
||||
FlutterProjectArgs args = {};
|
||||
auto result = FlutterEngineRun(FLUTTER_ENGINE_VERSION + 1, &config, &args,
|
||||
NULL, &engine);
|
||||
ASSERT_NE(result, kSuccess);
|
||||
FlutterResult result = FlutterEngineRun(FLUTTER_ENGINE_VERSION + 1, &config,
|
||||
&args, NULL, &engine);
|
||||
ASSERT_NE(result, FlutterResult::kSuccess);
|
||||
}
|
||||
|
||||
TEST(EmbedderTest, CanLaunchAndShutdownWithValidProjectArgs) {
|
||||
FlutterOpenGLRendererConfig renderer = {
|
||||
.struct_size = sizeof(FlutterOpenGLRendererConfig),
|
||||
.make_current = [](void*) { return false; },
|
||||
.clear_current = [](void*) { return false; },
|
||||
.present = [](void*) { return false; },
|
||||
.fbo_callback = [](void*) -> uint32_t { return 0; },
|
||||
};
|
||||
|
||||
std::string main =
|
||||
std::string(testing::GetFixturesPath()) + "/simple_main.dart";
|
||||
|
||||
FlutterRendererConfig config = {.type = FlutterRendererType::kOpenGL,
|
||||
.open_gl = renderer};
|
||||
FlutterProjectArgs args = {.struct_size = sizeof(FlutterProjectArgs),
|
||||
.assets_path = "",
|
||||
.main_path = main.c_str(),
|
||||
.packages_path = ""};
|
||||
FlutterEngine engine = nullptr;
|
||||
FlutterResult result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config,
|
||||
&args, nullptr, &engine);
|
||||
ASSERT_EQ(result, FlutterResult::kSuccess);
|
||||
|
||||
result = FlutterEngineShutdown(engine);
|
||||
ASSERT_EQ(result, FlutterResult::kSuccess);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user