Flutter Engine
The Flutter Engine
shell
platform
embedder
test_utils
proc_table_replacement.h
Go to the documentation of this file.
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_TEST_UTILS_PROC_TABLE_REPLACEMENT_H_
6
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_TEST_UTILS_PROC_TABLE_REPLACEMENT_H_
7
8
#include "flutter/shell/platform/embedder/embedder.h"
9
10
// Wraps capturing lambas with non-capturing version that can be assigned to
11
// FlutterEngineProcTable entries (by using statics) to facilitate mocking in
12
// tests of code built on top of the embedder API.
13
//
14
// This should *ONLY* be used in unit tests as it is leaky by design.
15
//
16
// |proc| should be the name of an entry in FlutterEngineProcTable, such as
17
// "Initialize". |mock_impl| should be a lamba that replaces its implementation,
18
// taking the same arguments and returning the same type.
19
#define MOCK_ENGINE_PROC(proc, mock_impl) \
20
([&]() { \
21
static std::function< \
22
std::remove_pointer_t<decltype(FlutterEngineProcTable::proc)>> \
23
closure; \
24
closure = mock_impl; \
25
static auto non_capturing = [](auto... args) { return closure(args...); }; \
26
return non_capturing; \
27
})()
28
29
#endif
// FLUTTER_SHELL_PLATFORM_EMBEDDER_TEST_UTILS_PROC_TABLE_REPLACEMENT_H_
Generated on Sun Jun 23 2024 21:55:14 for Flutter Engine by
1.9.4