Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Macros | Typedefs | Functions
hooks_unittests.cc File Reference
#include <memory>
#include "flutter/common/task_runners.h"
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/shell/common/shell_test.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/testing/testing.h"
#include "third_party/dart/runtime/include/dart_api.h"

Go to the source code of this file.

Namespaces

namespace  flutter
 
namespace  flutter::testing
 

Macros

#define CHECK_DART_ERROR(name)    EXPECT_FALSE(Dart_IsError(name)) << Dart_GetError(name)
 

Typedefs

using flutter::testing::HooksTest = ShellTest
 

Functions

 flutter::testing::TEST_F (HooksTest, HooksUnitTests)
 

Macro Definition Documentation

◆ CHECK_DART_ERROR

#define CHECK_DART_ERROR (   name)     EXPECT_FALSE(Dart_IsError(name)) << Dart_GetError(name)

Definition at line 23 of file hooks_unittests.cc.

25 {
26 auto settings = CreateSettingsForFixture();
27
28 TaskRunners task_runners(GetCurrentTestName(), // label
29 GetCurrentTaskRunner(), // platform
30 CreateNewThread("raster"), // raster
31 CreateNewThread("ui"), // ui
32 CreateNewThread("io") // io
33 );
34
35 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
36
37 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
38 ASSERT_TRUE(shell->IsSetup());
39
40 auto call_hook = [](Dart_NativeArguments args) {
42 CHECK_DART_ERROR(hook_name);
43
44 Dart_Handle ui_library = Dart_LookupLibrary(tonic::ToDart("dart:ui"));
45 CHECK_DART_ERROR(ui_library);
46
47 Dart_Handle hook = Dart_GetField(ui_library, hook_name);
48 CHECK_DART_ERROR(hook);
49
50 Dart_Handle arg_count_handle = Dart_GetNativeArgument(args, 1);
51 CHECK_DART_ERROR(arg_count_handle);
52
53 int64_t arg_count;
54 Dart_IntegerToInt64(arg_count_handle, &arg_count);
55
56 std::vector<Dart_Handle> hook_args;
57 for (int i = 0; i < static_cast<int>(arg_count); i++) {
58 hook_args.push_back(Dart_GetNativeArgument(args, 2 + i));
59 CHECK_DART_ERROR(hook_args.back());
60 }
61
62 Dart_Handle hook_result =
63 Dart_InvokeClosure(hook, hook_args.size(), hook_args.data());
64 CHECK_DART_ERROR(hook_result);
65 };
66
67 auto finished = [&message_latch](Dart_NativeArguments args) {
68 message_latch->Signal();
69 };
70 AddNativeCallback("CallHook", CREATE_NATIVE_ENTRY(call_hook));
71 AddNativeCallback("Finish", CREATE_NATIVE_ENTRY(finished));
72
73 auto configuration = RunConfiguration::InferFromSettings(settings);
74 configuration.SetEntrypoint("hooksTests");
75
76 shell->RunEngine(std::move(configuration), [](auto result) {
77 ASSERT_EQ(result, Engine::RunStatus::Success);
78 });
79
80 message_latch->Wait();
81 DestroyShell(std::move(shell), task_runners);
82}
83
84} // namespace testing
85} // namespace flutter
86
87// NOLINTEND(clang-analyzer-core.StackAddressEscape)
DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, int64_t *value)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
#define CHECK_DART_ERROR(name)
fml::RefPtr< fml::TaskRunner > CreateNewThread(const std::string &name)
fml::RefPtr< fml::TaskRunner > GetCurrentTaskRunner()
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition testing.cc:15
Dart_Handle ToDart(const T &object)
#define CREATE_NATIVE_ENTRY(native_entry)