tags: Fix when library->count is modified
Whenever a Track is destructed, library->count is decremented. This means that even if tagging fails we need to increment library->count to keep this value consistent. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a74eaaffa6
commit
e274d6399b
|
@ -165,7 +165,8 @@ Track :: Track(const std::string &f, Library *l)
|
|||
|
||||
Track :: ~Track()
|
||||
{
|
||||
library->count--;
|
||||
if (library)
|
||||
library->count--;
|
||||
}
|
||||
|
||||
const std::string Track :: primary_key() const
|
||||
|
@ -238,6 +239,7 @@ bool Track :: tag()
|
|||
TagLib :: AudioProperties *audio;
|
||||
TagLib :: FileRef ref(path().c_str(), true, TagLib::AudioProperties::Fast);
|
||||
|
||||
library->count++;
|
||||
if (ref.isNull()) {
|
||||
print("WARNING: Could not read tags for file %s\n", path().c_str());
|
||||
return false;
|
||||
|
@ -259,7 +261,6 @@ bool Track :: tag()
|
|||
filter :: add(artist->name, id);
|
||||
filter :: add(album->name, id);
|
||||
|
||||
library->count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,12 +51,6 @@ static void test_library()
|
|||
test_equal(tagdb :: get_library_db().size(), (unsigned)0);
|
||||
}
|
||||
|
||||
static void test_invalid_track(Library *lib)
|
||||
{
|
||||
Track *track = tagdb :: add_track("tests/Music/invalid_track", lib);
|
||||
test_equal(track, TRACK_NULL);
|
||||
}
|
||||
|
||||
static void test_track(struct TagArgs *args)
|
||||
{
|
||||
Track *track = tagdb :: add_track(args->full_path, args->library);
|
||||
|
@ -102,13 +96,19 @@ static void test_track(struct TagArgs *args)
|
|||
test_not_equal(track->last_day, args->last_day);
|
||||
}
|
||||
|
||||
static void test_invalid_track(Library *lib)
|
||||
{
|
||||
unsigned int library_size = lib->count;
|
||||
Track *track = tagdb :: add_track("tests/Music/invalid_track", lib);
|
||||
test_equal(track, TRACK_NULL);
|
||||
test_equal(lib->count, library_size);
|
||||
}
|
||||
|
||||
static void test_all_tracks()
|
||||
{
|
||||
struct TagArgs expected;
|
||||
Library *library = tagdb :: add_library("tests/Music");
|
||||
|
||||
run_test("Tags Track Test (Invalid)", test_invalid_track, library);
|
||||
|
||||
expected.library = library;
|
||||
expected.full_path = "tests/Music/1.ogg";
|
||||
expected.artist = "Artist";
|
||||
|
@ -185,6 +185,8 @@ static void test_all_tracks()
|
|||
expected.filepath = "666.ogg";
|
||||
expected.length_str = "11:06";
|
||||
run_test("Tags Track Test (666.ogg)", test_track, &expected);
|
||||
|
||||
run_test("Tags Track Test (Invalid)", test_invalid_track, library);
|
||||
}
|
||||
|
||||
static void test_comparison()
|
||||
|
|
Loading…
Reference in New Issue