Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add supporting macro for writing tests
  • Loading branch information
stuartmorgan-g committed Oct 13, 2020
commit 0528b665fb6d11039f2d9acf43a9dbc4e4bdcf49
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ FILE: ../../../flutter/shell/platform/embedder/fixtures/verifyb143464703.png
FILE: ../../../flutter/shell/platform/embedder/fixtures/verifyb143464703_soft_noxform.png
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.cc
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.h
FILE: ../../../flutter/shell/platform/embedder/test_utils/proc_table_replacement.h
FILE: ../../../flutter/shell/platform/embedder/vsync_waiter_embedder.cc
FILE: ../../../flutter/shell/platform/embedder/vsync_waiter_embedder.h
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart
Expand Down
8 changes: 8 additions & 0 deletions shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ source_set("embedder_headers") {
public_configs = [ "//flutter:config" ]
}

source_set("embedder_test_utils") {
public = [ "test_utils/proc_table_replacement.h" ]

deps = [ ":embedder_headers" ]

public_configs = [ "//flutter:config" ]
}

# For using the embedder API as internal implementation detail of an
# embedding.
config("embedder_internal_library_config") {
Expand Down
23 changes: 23 additions & 0 deletions shell/platform/embedder/test_utils/proc_table_replacement.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

#include "flutter/shell/platform/embedder/embedder.h"

// Wraps capturing lambas with non-capturing version that can be assigned to
// FlutterEngineProcTable entries (by using statics) to facilitate mocking in
// tests of code built on top of the embedder API.
//
// This should *ONLY* be used in unit tests as it is leaky by design.
//
// |proc| should be the name of an entry in FlutterEngineProcTable, such as
// "initialize". |mock_impl| should be a lamba that replaces its implementation,
// taking the same arguments and returning the same type.
#define MOCK_ENGINE_PROC(proc, mock_impl) \
([&]() { \
static std::function< \
std::remove_pointer_t<decltype(FlutterEngineProcTable::proc)>> \
closure = mock_impl; \
static auto non_capturing = [](auto... args) { return closure(args...); }; \
return non_capturing; \
})()