#ifndef COMPONENTS_LEVELDB_PROTO_TESTING_FAKE_DB_H_
#define COMPONENTS_LEVELDB_PROTO_TESTING_FAKE_DB_H_
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/test_simple_task_runner.h"
#include "components/leveldb_proto/internal/proto_database_impl.h"
#include "components/leveldb_proto/public/proto_database.h"
#include "components/leveldb_proto/public/shared_proto_database_client_list.h"
namespace leveldb_proto {
namespace test {
template <typename P, typename T = P>
class FakeDB : public ProtoDatabaseImpl<P, T> { … };
namespace {
template <typename P,
typename T,
std::enable_if_t<std::is_base_of<google::protobuf::MessageLite,
T>::value>* = nullptr>
void DataToProtoWrap(T* data, P* proto) { … }
template <typename P,
typename T,
std::enable_if_t<!std::is_base_of<google::protobuf::MessageLite,
T>::value>* = nullptr>
void DataToProtoWrap(T* data, P* proto) { … }
template <typename P,
typename T,
std::enable_if_t<std::is_base_of<google::protobuf::MessageLite,
T>::value>* = nullptr>
void ProtoToDataWrap(const P& proto, T* data) { … }
template <typename P,
typename T,
std::enable_if_t<!std::is_base_of<google::protobuf::MessageLite,
T>::value>* = nullptr>
void ProtoToDataWrap(const P& proto, T* data) { … }
}
template <typename P, typename T>
FakeDB<P, T>::FakeDB(EntryMap* db)
: … { … }
template <typename P, typename T>
void FakeDB<P, T>::Init(Callbacks::InitStatusCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::Init(const leveldb_env::Options& unique_db_options,
Callbacks::InitStatusCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::UpdateEntries(
std::unique_ptr<typename ProtoDatabase<T>::KeyEntryVector> entries_to_save,
std::unique_ptr<std::vector<std::string>> keys_to_remove,
Callbacks::UpdateCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::UpdateEntriesWithRemoveFilter(
std::unique_ptr<typename Util::Internal<T>::KeyEntryVector> entries_to_save,
const KeyFilter& delete_key_filter,
Callbacks::UpdateCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadEntries(
typename Callbacks::Internal<T>::LoadCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadEntriesWithFilter(
const KeyFilter& key_filter,
typename Callbacks::Internal<T>::LoadCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadEntriesWithFilter(
const KeyFilter& key_filter,
const leveldb::ReadOptions& options,
const std::string& target_prefix,
typename Callbacks::Internal<T>::LoadCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadKeysAndEntries(
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadKeysAndEntriesWithFilter(
const KeyFilter& key_filter,
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadKeysAndEntriesWithFilter(
const KeyFilter& key_filter,
const leveldb::ReadOptions& options,
const std::string& target_prefix,
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadKeysAndEntriesInRange(
const std::string& start,
const std::string& end,
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadKeysAndEntriesWhile(
const std::string& start,
const leveldb_proto::KeyIteratorController& controller,
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadKeys(Callbacks::LoadKeysCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::GetEntry(
const std::string& key,
typename Callbacks::Internal<T>::GetCallback callback) { … }
template <typename P, typename T>
void FakeDB<P, T>::Destroy(Callbacks::DestroyCallback callback) { … }
template <typename P, typename T>
base::FilePath& FakeDB<P, T>::GetDirectory() { … }
template <typename P, typename T>
void FakeDB<P, T>::InitCallback(bool success) { … }
template <typename P, typename T>
void FakeDB<P, T>::InitStatusCallback(Enums::InitStatus status) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadCallback(bool success) { … }
template <typename P, typename T>
void FakeDB<P, T>::LoadKeysCallback(bool success) { … }
template <typename P, typename T>
void FakeDB<P, T>::GetCallback(bool success) { … }
template <typename P, typename T>
void FakeDB<P, T>::UpdateCallback(bool success) { … }
template <typename P, typename T>
void FakeDB<P, T>::DestroyCallback(bool success) { … }
template <typename P, typename T>
void FakeDB<P, T>::InvokingInvalidCallback(const std::string& callback_name) { … }
template <typename P, typename T>
void FakeDB<P, T>::RunLoadCallback(
typename Callbacks::Internal<T>::LoadCallback callback,
std::unique_ptr<typename std::vector<T>> entries,
bool success) { … }
template <typename P, typename T>
void FakeDB<P, T>::RunLoadKeysAndEntriesCallback(
typename Callbacks::Internal<T>::LoadKeysAndEntriesCallback callback,
std::unique_ptr<typename std::map<std::string, T>> keys_entries,
bool success) { … }
template <typename P, typename T>
void FakeDB<P, T>::RunLoadKeysCallback(
Callbacks::LoadKeysCallback callback,
std::unique_ptr<std::vector<std::string>> keys,
bool success) { … }
template <typename P, typename T>
void FakeDB<P, T>::RunGetCallback(
typename Callbacks::Internal<T>::GetCallback callback,
std::unique_ptr<T> entry,
bool success) { … }
template <typename P, typename T>
base::FilePath FakeDB<P, T>::DirectoryForTestDB() { … }
}
}
#endif