blob: c7d4a41bdb2cbdd35bc7f79fd1d6664ef4aece5b [file] [log] [blame]
// Copyright 2016 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/ledger/bin/tests/integration/test_utils.h"
#include <fuchsia/ledger/internal/cpp/fidl.h>
#include <lib/fidl/cpp/binding.h>
#include <lib/fsl/vmo/strings.h>
#include <lib/zx/time.h>
#include <string>
#include <utility>
#include <vector>
#include "garnet/public/lib/callback/capture.h"
#include "gtest/gtest.h"
#include "peridot/lib/convert/convert.h"
#include "src/ledger/bin/fidl/include/types.h"
#include "src/lib/files/scoped_temp_dir.h"
#include "src/lib/fxl/macros.h"
#include "src/lib/fxl/time/time_delta.h"
namespace ledger {
std::vector<uint8_t> RandomArray(rng::Random* random, size_t size,
const std::vector<uint8_t>& prefix) {
EXPECT_TRUE(size >= prefix.size());
std::vector<uint8_t> array(size);
for (size_t i = 0; i < prefix.size(); ++i) { = prefix[i];
random->Draw(&array[prefix.size()], size - prefix.size());
return array;
std::string ToString(const fuchsia::mem::BufferPtr& vmo) {
std::string value;
bool status = fsl::StringFromVmo(*vmo, &value);
return value;
std::vector<uint8_t> ToArray(const fuchsia::mem::BufferPtr& vmo) {
return convert::ToArray(ToString(vmo));
std::vector<Entry> SnapshotGetEntries(LoopController* loop_controller,
PageSnapshotPtr* snapshot,
fidl::VectorPtr<uint8_t> start,
int* num_queries) {
std::vector<Entry> result;
std::unique_ptr<Token> token;
if (num_queries) {
*num_queries = 0;
do {
IterationStatus status;
std::vector<Entry> entries;
auto waiter = loop_controller->NewWaiter();
start.Clone(), std::move(token),
callback::Capture(waiter->GetCallback(), &status, &entries, &token));
if (!waiter->RunUntilCalled()) {
ADD_FAILURE() << "|GetEntries| failed to call back.";
return {};
if (num_queries) {
for (auto& entry : entries) {
} while (token);
return result;
} // namespace ledger