class ServiceDirectoryProvider
Defined at line 38 of file ../../sdk/lib/sys/cpp/testing/service_directory_provider.h
This provides a fake |ServiceDirectory| 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 |ServiceDirectory| 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 ServiceDirectoryProvider (async_dispatcher_t * dispatcher)
Defined at line 14 of file ../../sdk/lib/sys/cpp/testing/service_directory_provider.cc
void ~ServiceDirectoryProvider ()
Defined at line 21 of file ../../sdk/lib/sys/cpp/testing/service_directory_provider.cc
zx_status_t AddService (std::unique_ptr<vfs::Service> service, std::string name)
Injects a service which can be accessed by calling Connect on
|sys::ServiceDirectory| by code under test.
Adds a supported service with the given |service_name|, using the given
|service|. |service| closure should
remain valid for the lifetime of this object.
# Errors
ZX_ERR_ALREADY_EXISTS: This already contains an entry for
this service.
Defined at line 23 of file ../../sdk/lib/sys/cpp/testing/service_directory_provider.cc
template <typename Interface>
zx_status_t AddService (fidl::InterfaceRequestHandler<Interface> handler, std::string name)
Injects a service which can be accessed by calling Connect on
|sys::ServiceDirectory| by code under test.
Adds a supported service with the given |service_name|, using the given
|interface_request_handler|. |interface_request_handler| should
remain valid for the lifetime of this object.
# Errors
ZX_ERR_ALREADY_EXISTS: This already contains an entry for
this service.
# Example
```
fidl::BindingSet
<fuchsia
::foo::Controller> bindings;
svc->AddService(bindings.GetHandler(this));
```
Defined at line 63 of file ../../sdk/lib/sys/cpp/testing/service_directory_provider.h
std::shared_ptr<ServiceDirectory> & service_directory ()
Defined at line 85 of file ../../sdk/lib/sys/cpp/testing/service_directory_provider.h