Flutter Engine
flutter::testing::FixtureTest Class Reference

#include <fixture_test.h>

Inheritance diagram for flutter::testing::FixtureTest:
flutter::testing::ThreadTest flutter::Fixture flutter::testing::DartIsolateTest flutter::testing::DartSecondaryIsolateTest flutter::testing::ImageDecoderFixtureTest flutter::testing::ShellTest flutter::testing::TypeConversionsTest flutter::testing::FuchsiaShellTest flutter::testing::ImageDisposeTest

Public Member Functions

 FixtureTest ()
 
virtual Settings CreateSettingsForFixture ()
 
void AddNativeCallback (std::string name, Dart_NativeFunction callback)
 
- Public Member Functions inherited from flutter::testing::ThreadTest
 ThreadTest ()
 
fml::RefPtr< fml::TaskRunnerGetCurrentTaskRunner ()
 Get the task runner for the thread that the current unit-test is running on. This creates a message loop as necessary. More...
 
fml::RefPtr< fml::TaskRunnerCreateNewThread (std::string name="")
 Creates a new thread, initializes a message loop on it, and, returns its task runner to the unit-test. The message loop is terminated (and its thread joined) when the test ends. This allows tests to create multiple named threads as necessary. More...
 

Protected Member Functions

void SetSnapshotsAndAssets (Settings &settings)
 

Protected Attributes

std::shared_ptr< TestDartNativeResolvernative_resolver_
 

Detailed Description

Definition at line 20 of file fixture_test.h.

Constructor & Destructor Documentation

◆ FixtureTest()

flutter::testing::FixtureTest::FixtureTest ( )

Definition at line 10 of file fixture_test.cc.

11  : native_resolver_(std::make_shared<TestDartNativeResolver>()),
12  assets_dir_(fml::OpenDirectory(GetFixturesPath(),
13  false,
15  aot_symbols_(LoadELFSymbolFromFixturesIfNeccessary()) {}
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:94
std::shared_ptr< TestDartNativeResolver > native_resolver_
Definition: fixture_test.h:31
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
ELFAOTSymbols LoadELFSymbolFromFixturesIfNeccessary()
Attempts to resolve AOT symbols from the portable ELF loader. This location is automatically resolved...
Definition: elf_loader.cc:15

Member Function Documentation

◆ AddNativeCallback()

void flutter::testing::FixtureTest::AddNativeCallback ( std::string  name,
Dart_NativeFunction  callback 
)

Definition at line 58 of file fixture_test.cc.

References native_resolver_.

Referenced by flutter::testing::TEST_F(), and flutter::testing::TestSimulatedInputEvents().

59  {
60  native_resolver_->AddNativeCallback(std::move(name), callback);
61 }
std::shared_ptr< TestDartNativeResolver > native_resolver_
Definition: fixture_test.h:31
const char * name
Definition: fuchsia.cc:50

◆ CreateSettingsForFixture()

Settings flutter::testing::FixtureTest::CreateSettingsForFixture ( )
virtual

Reimplemented in flutter::testing::ShellTest.

Definition at line 17 of file fixture_test.cc.

References flutter::Settings::enable_observatory, flutter::Settings::isolate_create_callback, flutter::Settings::leak_vm, native_resolver_, SetSnapshotsAndAssets(), flutter::Settings::task_observer_add, and flutter::Settings::task_observer_remove.

Referenced by flutter::BM_PlatformMessageResponseDartComplete(), and flutter::testing::TEST_F().

17  {
18  Settings settings;
19  settings.leak_vm = false;
20  settings.task_observer_add = [](intptr_t, fml::closure) {};
21  settings.task_observer_remove = [](intptr_t) {};
22  settings.isolate_create_callback = [this]() {
23  native_resolver_->SetNativeResolverForIsolate();
24  };
25  settings.enable_observatory = false;
26  SetSnapshotsAndAssets(settings);
27  return settings;
28 }
std::function< void()> closure
Definition: closure.h:14
std::shared_ptr< TestDartNativeResolver > native_resolver_
Definition: fixture_test.h:31
void SetSnapshotsAndAssets(Settings &settings)
Definition: fixture_test.cc:30

◆ SetSnapshotsAndAssets()

void flutter::testing::FixtureTest::SetSnapshotsAndAssets ( Settings settings)
protected

Definition at line 30 of file fixture_test.cc.

References flutter::Settings::application_kernels, flutter::Settings::assets_dir, fml::FileMapping::CreateReadOnly(), FML_CHECK, FML_LOG, fml::UniqueObject< T, Traits >::get(), fml::UniqueObject< T, Traits >::is_valid(), flutter::DartVM::IsRunningPrecompiledCode(), and flutter::testing::PrepareSettingsForAOTWithSymbols().

Referenced by CreateSettingsForFixture(), and flutter::testing::ShellTest::CreateSettingsForFixture().

30  {
31  if (!assets_dir_.is_valid()) {
32  return;
33  }
34 
35  settings.assets_dir = assets_dir_.get();
36 
37  // In JIT execution, all snapshots are present within the binary itself and
38  // don't need to be explicitly supplied by the embedder. In AOT, these
39  // snapshots will be present in the application AOT dylib.
41  FML_CHECK(PrepareSettingsForAOTWithSymbols(settings, aot_symbols_));
42  } else {
43  settings.application_kernels = [this]() -> Mappings {
44  std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
45  auto kernel_mapping =
46  fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin");
47  if (!kernel_mapping || !kernel_mapping->IsValid()) {
48  FML_LOG(ERROR) << "Could not find kernel blob for test fixture not "
49  "running in precompiled mode.";
50  return kernel_mappings;
51  }
52  kernel_mappings.emplace_back(std::move(kernel_mapping));
53  return kernel_mappings;
54  };
55  }
56 }
#define FML_LOG(severity)
Definition: logging.h:65
const T & get() const
Definition: unique_object.h:87
bool is_valid() const
Definition: unique_object.h:89
std::vector< std::unique_ptr< const fml::Mapping > > Mappings
Definition: settings.h:57
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
Definition: dart_vm.cc:199
#define FML_CHECK(condition)
Definition: logging.h:68
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition: mapping.cc:18
bool PrepareSettingsForAOTWithSymbols(Settings &settings, const ELFAOTSymbols &symbols)
Prepare the settings objects various AOT mappings resolvers with the symbols already loaded...
Definition: elf_loader.cc:63

Member Data Documentation

◆ native_resolver_

std::shared_ptr<TestDartNativeResolver> flutter::testing::FixtureTest::native_resolver_
protected

The documentation for this class was generated from the following files: