class MockLoaderServiceForTest

Defined at line 94 of file ../../sdk/lib/ld/testing/include/lib/ld/testing/mock-loader-service.h

MockLoaderForTest is used by tests to manage an instance of the

MockLoaderService. This class provides the public test API to prime the mock

loader with FIDL request expectations and the responses the mock loader

should return when receiving the request.

MockLoaderForTest lazily initializes its mock_loader_ member, so tests must

call Init() before interacting with the mock loader service:

```

MockLoaderServiceForTest mock_;

ASSERT_NO_FATAL_FAILURE(mock_.Init());

mock_.ExpectLoadObject("foo.so", zx::ok(zx::vmo()));

...

```

Public Methods

void MockLoaderServiceForTest ()

Defined at line 96 of file ../../sdk/lib/ld/testing/include/lib/ld/testing/mock-loader-service.h

void MockLoaderServiceForTest (const MockLoaderServiceForTest & )

Defined at line 97 of file ../../sdk/lib/ld/testing/include/lib/ld/testing/mock-loader-service.h

void MockLoaderServiceForTest (MockLoaderServiceForTest && )

Defined at line 98 of file ../../sdk/lib/ld/testing/include/lib/ld/testing/mock-loader-service.h

template <typename T>
void set_path_prefix (T && path)

Set the prefix used on names to look up using the ambient loader service.

Defined at line 102 of file ../../sdk/lib/ld/testing/include/lib/ld/testing/mock-loader-service.h

template <typename T>
void set_path_prefix (std::optional<T> path)

Defined at line 107 of file ../../sdk/lib/ld/testing/include/lib/ld/testing/mock-loader-service.h

template <auto& source>
void path_prefix_append (const auto & source)

Do std::filesystem::path::append to that prefix unless source is empty.

Defined at line 116 of file ../../sdk/lib/ld/testing/include/lib/ld/testing/mock-loader-service.h

const std::filesystem::path & path_prefix ()

Defined at line 122 of file ../../sdk/lib/ld/testing/include/lib/ld/testing/mock-loader-service.h

zx::vmo GetVmo (std::string_view name)

Fetch a VMO from the ambient loader service using the prefix set by

set_path_prefix().

Defined at line 192 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

void Needed (std::initializer_list<std::string_view> names)

Prime the mock loader with the VMOs for the list of dependency names, and

add the expectation on the mock loader that it will receive a LoadObject

request for each of these dependencies in the order that they are listed.

Defined at line 105 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

void Needed (std::initializer_list<std::pair<std::string_view, bool>> name_found_pairs)

Similar to above, except that a boolean `found` is paired with the

dependency name to potentially prime the mock loader to return a 'not

found' error when it receives the LoadObject request for that dependency.

Defined at line 111 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

void ExpectLoadObject (std::string_view name, zx::result<zx::vmo> expected_result)

A generic interface to prime the mock loader with the `expected_result`

for when it receives a LoadObject request for the given `name`.

Defined at line 122 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

void ExpectLoadObject (std::string_view name, zx::vmo vmo)

This is an overload that will check the validity of the VMO before priming

the mock loader with a zx::ok result.

Defined at line 128 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

void ExpectDependency (std::string_view name)

Prime the mock loader with a dependency VMO and add the expectation on the

mock loader that it will receive a LoadObject request for that dependency.

Defined at line 133 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

void ExpectRootModule (std::string_view name)

Prime the mock loader with a root module VMO and add the expectation on

the mock loader that it will receive a LoadObject request for that root

module.

Defined at line 137 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

void ExpectMissing (std::string_view name)

Prime the mock loader with a "not found" error for `name` and add the

expectation that it will receive a LoadObject request for a VMO with the

given `name`.

Defined at line 141 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

void ExpectConfig (std::string_view config)

Prime the mock loader with config and add the expectation on the mock

loader that it will receive a Config request.

Defined at line 145 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

fidl::ClientEnd<fuchsia_ldsvc::Loader> & client ()

Return a reference to the client end to the MockLoader's FIDL server. This

will start the server if it hasn't been initialized yet.

Defined at line 150 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

zx::channel TakeLdsvc ()

Take ownership of the client end to the MockLoader's FIDL server.

Defined at line 155 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

zx::unowned_channel BorrowLdsvc ()

Borrow the client end to the MockLoader's FIDL server.

Defined at line 163 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

void CallWithLdsvcInstalled (fit::function<void ()> func)

Call `func` with the mock loader installed as the system loader so it will

handle fuchsia.ldsvc.Loader requests made during the duration of `func()`.

Defined at line 171 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

void VerifyAndClearExpectations ()

Check that all the registered expectations on the mock_loader_ have been

satisfied and then clear its expectations list.

Defined at line 188 of file ../../sdk/lib/ld/testing/mock-loader-service.cc

zx::result<zx::vmo> LoadObject (std::string_view name)

Short-circuit the FIDL protocol and just do what the protocol call would.

Defined at line 204 of file ../../sdk/lib/ld/testing/mock-loader-service.cc