tagdb: Implement init() and commit()
To save and restore the databases. Signed-off-by: Anna Schumaker <anna@ocarinaproject.net>
This commit is contained in:
parent
2a01ce5159
commit
2a3d4ca2e0
6
TODO
6
TODO
|
@ -86,14 +86,8 @@ Future work:
|
|||
Calculate value after first playback?
|
||||
Store in library :: Track structure
|
||||
|
||||
- Autosave databases
|
||||
Artist, album, genere and library path don't change often so
|
||||
saving on every add / remove won't be a huge performance hit
|
||||
and may actually be more efficient in the long run.
|
||||
|
||||
- Playqueue and database inherit from common class
|
||||
- "About" dialog
|
||||
- Investigate "Bulk insert" callbacks for performance
|
||||
- Initialize PQs with multiple flags
|
||||
- Prefill Song structures in each library :: Track
|
||||
- Use "friend" class for valid and id flags of a DatabaseEntry
|
||||
|
|
|
@ -119,6 +119,9 @@ public:
|
|||
namespace tagdb
|
||||
{
|
||||
|
||||
void init();
|
||||
void commit();
|
||||
|
||||
Track *add_track(const std::string &, Library *);
|
||||
Track *import_track(const std::string &, Library *, const ImportData &);
|
||||
Library *add_library(const std::string &);
|
||||
|
|
14
lib/tags.cpp
14
lib/tags.cpp
|
@ -310,6 +310,20 @@ int Track :: less_than(Track *rhs, sort_t field)
|
|||
*
|
||||
*/
|
||||
|
||||
void tagdb :: init()
|
||||
{
|
||||
artist_db.load();
|
||||
album_db.load();
|
||||
genre_db.load();
|
||||
library_db.load();
|
||||
track_db.load();
|
||||
}
|
||||
|
||||
void tagdb :: commit()
|
||||
{
|
||||
track_db.save();
|
||||
}
|
||||
|
||||
Track *tagdb :: add_track(const std::string &filepath, Library *library)
|
||||
{
|
||||
unsigned int size = track_db.size();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <print.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
unsigned int test_num = 0;
|
||||
|
||||
|
@ -34,28 +35,52 @@ void test_track_size(unsigned int expected, unsigned int line)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char c;
|
||||
bool init_called = false;
|
||||
unsigned int id;
|
||||
|
||||
while ((c = getopt(argc, argv, "i")) != -1) {
|
||||
switch (c) {
|
||||
case 'i':
|
||||
init_called = true;
|
||||
tagdb :: init();
|
||||
test_library_size(1, __LINE__);
|
||||
test_track_size(0, __LINE__);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initial library checks
|
||||
*/
|
||||
Library *library = tagdb :: add_library("Music");
|
||||
Library *library, *library_null;
|
||||
if (init_called == true) {
|
||||
library = *(tagdb :: get_library_db().begin());
|
||||
goto test_tracks;
|
||||
}
|
||||
|
||||
library = tagdb :: add_library("Music");
|
||||
test_results(library->root_path == "Music", __LINE__);
|
||||
test_library_size(1, __LINE__);
|
||||
|
||||
Library *library_null = tagdb :: add_library("Music");
|
||||
library_null = tagdb :: add_library("Music");
|
||||
test_results(library_null == NULL, __LINE__);
|
||||
test_library_size(1, __LINE__);
|
||||
|
||||
unsigned int id = library->id;
|
||||
id = library->id;
|
||||
tagdb :: remove_library(id);
|
||||
test_library_size(0, __LINE__);
|
||||
tagdb :: remove_library(id);
|
||||
test_library_size(0, __LINE__);
|
||||
|
||||
|
||||
library = tagdb :: add_library("Music");
|
||||
test_tracks:
|
||||
/**
|
||||
* Test adding / removing tracks
|
||||
*/
|
||||
library = tagdb :: add_library("Music");
|
||||
Track *track = tagdb :: add_track("Music/1.ogg", library);
|
||||
test_track_size(1, __LINE__);
|
||||
test_results(track->track == 1, __LINE__);
|
||||
|
@ -115,5 +140,8 @@ int main(int argc, char **argv)
|
|||
test_results(track->last_day == 1, __LINE__);
|
||||
test_results(track->play_count == 7, __LINE__);
|
||||
|
||||
if (init_called == true)
|
||||
tagdb :: commit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
35
tests/tag_db
35
tests/tag_db
|
@ -9,6 +9,22 @@ function test_tag
|
|||
./src/tags.run "$2"
|
||||
}
|
||||
|
||||
function test_db_exists
|
||||
{
|
||||
if [ ! -f $DATA_DIR/$1.db ]; then
|
||||
echo "ERROR: $DATA_DIR/$1.db doesn't exist!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function test_db_not_exists
|
||||
{
|
||||
if [ -f $DATA_DIR/$1.db ]; then
|
||||
echo "ERROR: $DATA_DIR/$1.db shouldn't exist!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
test_tag "Artist" "-a"
|
||||
echo
|
||||
test_tag "Album" "-A"
|
||||
|
@ -20,6 +36,25 @@ echo
|
|||
test_tag "Track" "-t"
|
||||
|
||||
|
||||
rm -rf $DATA_DIR/*.db
|
||||
|
||||
echo
|
||||
new_test "Test TagDB"
|
||||
./src/tagdb.run
|
||||
|
||||
test_db_exists artist
|
||||
test_db_exists album
|
||||
test_db_exists genre
|
||||
test_db_exists library
|
||||
test_db_not_exists track
|
||||
|
||||
|
||||
echo
|
||||
new_test "Test TagDB (call init)"
|
||||
./src/tagdb.run -i
|
||||
|
||||
test_db_exists artist
|
||||
test_db_exists album
|
||||
test_db_exists genre
|
||||
test_db_exists library
|
||||
test_db_exists track
|
||||
|
|
Loading…
Reference in New Issue