class ComponentContextProvider

Defined at line 31 of file ../../sdk/lib/sys/cpp/testing/component_context_provider.h

Provides fake |ComponentContext| for unit testing.

Provides access to services that have been added to this object.

The object of this class should be kept alive for fake |ComponentContext| to

work.

This class is thread-hostile.

# Simple usage

Instances of this class should be owned and managed on the same thread.

# Advanced usage

You can use a background thread to service this class provided:

async_dispatcher_t for the background thread is stopped or suspended

prior to destroying the class object.

Public Methods

void ComponentContextProvider (async_dispatcher_t * dispatcher)

Defined at line 16 of file ../../sdk/lib/sys/cpp/testing/component_context_provider.cc

void ~ComponentContextProvider ()

Defined at line 31 of file ../../sdk/lib/sys/cpp/testing/component_context_provider.cc

fuchsia::io::DirectoryPtr & outgoing_directory_ptr ()

Points to outgoing root directory of outgoing directory, test can get it

and try to connect to internal directories/objects/files/services to test

code which published them.

Defined at line 40 of file ../../sdk/lib/sys/cpp/testing/component_context_provider.h

template <typename Interface>
fidl::InterfacePtr<Interface> ConnectToPublicService (const std::string & name, async_dispatcher_t * dispatcher)

Connects to public service which was published in "svc" directory by

code under test.

Defined at line 45 of file ../../sdk/lib/sys/cpp/testing/component_context_provider.h

template <typename Interface>
void ConnectToPublicService (fidl::InterfaceRequest<Interface> request, const std::string & name)

Connects to public service which was published in "svc" directory by code

under test.

Defined at line 55 of file ../../sdk/lib/sys/cpp/testing/component_context_provider.h

std::shared_ptr<sys::ServiceDirectory> public_service_directory ()

Returns a service directory which can be useful to test services published to out/svc.

For example,

context_provider.context()->AddPublicService("my service", ...);

...

auto mock = MyMock(context_provider.public_service_directory());

...

...

Code inside mock

MyMock::MyMock(std::shared_ptr

<sys

::ServiceDirectory> svc) {

svc->Connect("my service", channel);

}

Defined at line 71 of file ../../sdk/lib/sys/cpp/testing/component_context_provider.h

const std::shared_ptr<ServiceDirectoryProvider> & service_directory_provider ()

Gets a fake service directory that can be used to inject services

which can be accessed by code under test.

# Example

```

fidl::BindingSet

<fuchsia

::foo::Controller> bindings;

context_provider->service_directory_provider()->AddService(bindings.GetHandler(this));

auto context = context_provider->context();

...

...

...

context->svc()->Connect(...);

```

Defined at line 89 of file ../../sdk/lib/sys/cpp/testing/component_context_provider.h

std::unique_ptr<sys::ComponentContext> TakeContext ()

Relinquishes the ownership of fake context. This object should be alive

for lifetime of returned context.

Defined at line 95 of file ../../sdk/lib/sys/cpp/testing/component_context_provider.h

sys::ComponentContext * context ()

Defined at line 97 of file ../../sdk/lib/sys/cpp/testing/component_context_provider.h