blob: 527cfff8a9339ef9eb0a03208e1f5c5a01d253c2 [file] [log] [blame]
// Copyright 2018 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.
#ifndef SRC_LIB_TESTING_LOOP_FIXTURE_REAL_LOOP_FIXTURE_H_
#define SRC_LIB_TESTING_LOOP_FIXTURE_REAL_LOOP_FIXTURE_H_
#include <lib/async-loop/testing/cpp/real_loop.h>
#include <gtest/gtest.h>
namespace gtest {
// An extension of Test class which sets up a message loop,
// async::Loop, for the test. This fixture is meant to be used for
// multi-process tests.
//
// This allows, for example, a test to conveniently exercise FIDL, as FIDL
// bindings post waits to the thread-local dispatcher.
//
// Example:
//
// #include "foo.fidl.h"
//
// class TestFoo : public Foo {
// public:
// explicit TestFoo(InterfaceRequest<Foo> request)
// : binding_(this, std::move(request) {}
//
// // Foo implementation here.
//
// private:
// Binding<Foo> binding_;
// };
//
// // Creates a fixture that creates a message loop on this thread.
// class TestBar : public ::gtest::RealLoopFixture { /* ... */ };
//
// TEST_F(TestBar, TestCase) {
// // Do all FIDL-y stuff here and asynchronously quit.
//
// RunLoop();
//
// // Check results from FIDL-y stuff here.
// }
class RealLoopFixture : public ::loop_fixture::RealLoop, public ::testing::Test {};
} // namespace gtest
#endif // SRC_LIB_TESTING_LOOP_FIXTURE_REAL_LOOP_FIXTURE_H_