blob: bd13d86062e0c5c87d76e44964f547c875598e2c [file] [log] [blame]
// Copyright 2019 The Fuchsia 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 <fuchsia/modular/testing/cpp/fidl.h>
#include <fuchsia/sys/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/async-loop/default.h>
#include <lib/sys/cpp/service_directory.h>
namespace modular_testing {
// TestHarnessLauncher launches and manages an instance of the modular test
// harness component. Use this class to acquire an instance of the
// |fuchsia.modular.TestHarness| service.
class TestHarnessLauncher final {
// Launches the modular test harness component.
explicit TestHarnessLauncher(fuchsia::sys::LauncherPtr launcher);
// Blocks the current thread until the modular test harness component is
// destroyed.
// Not copyable.
TestHarnessLauncher(const TestHarnessLauncher&) = delete;
TestHarnessLauncher& operator=(const TestHarnessLauncher&) = delete;
fuchsia::modular::testing::TestHarnessPtr& test_harness() { return test_harness_; }
// This async loop is launched in a separate thread, and hosts |test_harness_ctrl_|. When
// |test_harness_ctrl_| is closed, this loop exits and unblocks the destructor.
async::Loop test_harness_loop_;
std::shared_ptr<sys::ServiceDirectory> test_harness_svc_;
test_harness_ctrl_; // Bound to |test_harness_loop_|'s dispatcher.
fuchsia::modular::testing::TestHarnessPtr test_harness_;
fuchsia::modular::LifecyclePtr lifecycle_;
} // namespace modular_testing