blob: a62ce2fecbae85beb4d0ce19996ceb10c6b58ad4 [file] [log] [blame]
// Copyright 2017 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/ledger/cloud/cpp/fidl.h>
#include <fuchsia/ledger/internal/cpp/fidl.h>
#include <functional>
#include <memory>
#include "peridot/lib/rng/random.h"
#include "peridot/lib/scoped_tmpfs/scoped_tmpfs.h"
#include "src/ledger/bin/testing/loop_controller.h"
#include "src/lib/fxl/macros.h"
namespace ledger {
class LedgerAppInstanceFactory;
// Class that creates instances of |LedgerAppInstanceFactory|.
class LedgerAppInstanceFactoryBuilder {
virtual ~LedgerAppInstanceFactoryBuilder(){};
// Returns a new LedgerAppInstanceFactory.
virtual std::unique_ptr<LedgerAppInstanceFactory> NewFactory() const = 0;
// Base class for client tests.
// Client tests are tests that act as clients to the Ledger as a whole. These
// are integration tests or end-to-end tests (apptests).
class LedgerAppInstanceFactory {
// A Ledger app instance
class LedgerAppInstance {
LoopController* loop_controller, std::vector<uint8_t> test_ledger_name,
ledger_internal::LedgerRepositoryFactoryPtr ledger_repository_factory);
virtual ~LedgerAppInstance();
// Returns the LedgerRepositoryFactory associated with this application
// instance.
ledger_internal::LedgerRepositoryFactory* ledger_repository_factory();
// Builds and returns a new connection to the default LedgerRepository
// object.
ledger_internal::LedgerRepositoryPtr GetTestLedgerRepository();
// Builds and returns a new connection to the default Ledger object.
LedgerPtr GetTestLedger();
// Builds and returns a new connection to a new random page on the default
// Ledger object.
PagePtr GetTestPage();
// Returns a connection to the given page on the default Ledger object.
PagePtr GetPage(const PageIdPtr& page_id);
virtual cloud_provider::CloudProviderPtr MakeCloudProvider() = 0;
virtual std::string GetUserId() = 0;
LoopController* loop_controller_;
std::vector<uint8_t> test_ledger_name_;
ledger_internal::LedgerRepositoryFactoryPtr ledger_repository_factory_;
scoped_tmpfs::ScopedTmpFS tmpfs_;
virtual ~LedgerAppInstanceFactory() {}
// Starts a new instance of the Ledger. The |loop_controller| must allow to
// control the loop that is used to access the LedgerAppInstance.
virtual std::unique_ptr<LedgerAppInstance> NewLedgerAppInstance() = 0;
// Returns the Loop controller controlling the loops of the LedgerAppInstances
// created by this.
virtual LoopController* GetLoopController() = 0;
// Returns a random instance to control the randomness of the test.
virtual rng::Random* GetRandom() = 0;
// Returns the list of LedgerAppInstanceFactoryBuilder to be passed as
// parameters to the tests. The implementation of this function changes
// depending on whether the tests are ran as integration tests, or end to end
// tests.
std::vector<const LedgerAppInstanceFactoryBuilder*>
} // namespace ledger