blob: 0f2c45418c12b1c90da77e69229d567edf37d918 [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 "src/ui/a11y/bin/a11y_manager/tests/util/util.h"
namespace accessibility_test {
char *ReadFile(vfs::internal::Node *node, int length, char *buffer) {
EXPECT_LE(length, kMaxLogBufferSize);
async::Loop loop(&kAsyncLoopConfigNoAttachToThread);
int fd = OpenAsFD(node, loop.dispatcher());
EXPECT_LE(0, fd);
memset(buffer, 0, kMaxLogBufferSize);
EXPECT_EQ(length, pread(fd, buffer, length, 0));
return buffer;
int OpenAsFD(vfs::internal::Node *node, async_dispatcher_t *dispatcher) {
zx::channel local, remote;
EXPECT_EQ(ZX_OK, zx::channel::create(0, &local, &remote));
EXPECT_EQ(ZX_OK, node->Serve(fuchsia::io::OPEN_RIGHT_READABLE, std::move(remote), dispatcher));
int fd = -1;
EXPECT_EQ(ZX_OK, fdio_fd_create(local.release(), &fd));
return fd;
} // namespace accessibility_test