blob: 615ec679e02e54bd6c7e2c5ac30d70cb0f9f6883 [file]
{{>copyright comment="//"}}
#include <fuchsia/sys2/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/async-loop/default.h>
#include <lib/diagnostics/reader/cpp/archive_reader.h>
#include <lib/fdio/directory.h>
#include <lib/syslog/cpp/macros.h>
#include <lib/zx/result.h>
#include <zircon/types.h>
#include <gtest/gtest.h>
namespace {{snake_case PROJECT_NAME}} {
class {{pascal_case PROJECT_NAME}}IntegrationTest : public testing::Test {
public:
void SetUp() {
// Code here will be called immediately before each test
}
void TearDown() {
// Code here will be called immediately after each test
}
};
TEST_F({{pascal_case PROJECT_NAME}}IntegrationTest, TestMethod) {
async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
// Connect to the component(s) under test using the Realm protocol, e.g.
// This assumes that the child component exposes the `fuchsia.component.Binder`
// protocol.
// If your component exposes another capability, you connect to it directly.
// ```
// fidl::SynchronousInterfacePtr<fuchsia::component::Realm> realm;
// std::string realm_service = std::string("/svc/") + fuchsia::component::Realm::Name_;
// EXPECT_EQ(ZX_OK,
// fdio_service_connect(realm_service.c_str(), realm.NewRequest().TakeChannel().get()));
// fidl::SynchronousInterfacePtr<fuchsia::io::Directory> exposed_dir;
// fuchsia::component::Realm_OpenExposedDir_Result result;
// realm->OpenExposedDir(fuchsia::component::decl::ChildRef{.name = "hello-world"},
// exposed_dir.NewRequest(), &result);
// zx::channel handle, request;
// EXPECT_EQ(zx::channel::create(0, &handle, &request), ZX_OK);
// EXPECT_EQ(exposed_dir->Open(fuchsia::component::Binder::Name_, fuchsia::io::Flags(),
// fuchsia::io::Options(), std::move(request)),
// ZX_OK);
// ```
// Use the ArchiveReader to access inspect data, e.g.
// ```
// fuchsia::diagnostics::ArchiveAccessorPtr accessor;
// std::string archive_service = std::string("/svc/")
// + fuchsia::diagnostics::ArchiveAccessor::Name_;
// EXPECT_EQ(ZX_OK,
// fdio_service_connect(
// archive_service.c_str(),
// accessor.NewRequest(loop.dispatcher()).TakeChannel().release()));
// diagnostics::reader::ArchiveReader reader(std::move(accessor),
// {"hello-world:root"});
//
// reader.SnapshotInspectUntilPresent({kComponentSelector}).then(...);
// ```
// Add test conditions here, e.g.
// ```
// const std::string expected_string = test_function();
// ```
FX_LOGS(DEBUG) << "Initialized.";
loop.RunUntilIdle();
// Assert conditions here, e.g.
// ```
// ASSERT_EQ!(expected_string, "Hello World!");
// ```
}
} // namespace {{snake_case PROJECT_NAME}}