From 961c8014ada037712e8c72f23430362e9f14c1ec Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 12 May 2023 10:30:07 +1000 Subject: Add some basic tests for the database --- src/database/include/database.hpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/database/include/database.hpp') diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp index 6cdaaca6..29872e8d 100644 --- a/src/database/include/database.hpp +++ b/src/database/include/database.hpp @@ -9,6 +9,7 @@ #include #include +#include "file_gatherer.hpp" #include "leveldb/cache.h" #include "leveldb/db.h" #include "leveldb/iterator.h" @@ -17,6 +18,7 @@ #include "records.hpp" #include "result.hpp" #include "song.hpp" +#include "tag_parser.hpp" namespace database { @@ -61,12 +63,15 @@ class Database { ALREADY_OPEN, FAILED_TO_OPEN, }; + static auto Open(IFileGatherer* file_gatherer, ITagParser* tag_parser) + -> cpp::result; static auto Open() -> cpp::result; + static auto Destroy() -> void; + ~Database(); auto Update() -> std::future; - auto Destroy() -> std::future; auto GetSongs(std::size_t page_size) -> std::future>; auto GetMoreSongs(std::size_t page_size, Continuation c) @@ -80,10 +85,19 @@ class Database { Database& operator=(const Database&) = delete; private: - std::unique_ptr db_; - std::unique_ptr cache_; - - Database(leveldb::DB* db, leveldb::Cache* cache); + // Owned. Dumb pointers because destruction needs to be done in an explicit + // order. + leveldb::DB* db_; + leveldb::Cache* cache_; + + // Not owned. + IFileGatherer* file_gatherer_; + ITagParser* tag_parser_; + + Database(leveldb::DB* db, + leveldb::Cache* cache, + IFileGatherer* file_gatherer, + ITagParser* tag_parser); auto dbMintNewSongId() -> SongId; auto dbEntomb(SongId song, uint64_t hash) -> void; -- cgit v1.2.3