From f2228de5c9911e3477427a91528a2c8d731a6206 Mon Sep 17 00:00:00 2001 From: Arnaud Bienner Date: Sun, 17 Apr 2016 19:33:52 -0700 Subject: [PATCH] Add some tests for MergeUserSetData --- tests/song_test.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/song_test.cpp b/tests/song_test.cpp index 4571ab84c..c8453989e 100644 --- a/tests/song_test.cpp +++ b/tests/song_test.cpp @@ -394,4 +394,33 @@ TEST_F(SongTest, StatisticsMP4) { EXPECT_EQ(87, new_song.score()); } +TEST_F(SongTest, MergeUserSetDataTest) { + // Suppose we have songs from files and from the DB + // Songs from files are the ones that will be imported in the DB after being merged with the + // former DB song values + Song song_db_with_rating; + Song song_db_with_no_rating; + Song song_file_with_rating; + Song song_file_with_no_rating; + + song_db_with_rating.set_rating(0.42); + song_file_with_rating.set_rating(0.43); + + // Merging a DB song with no rating should not update the rating that is in the file song + float old_rating_value = song_file_with_rating.rating(); + song_file_with_rating.MergeUserSetData(song_db_with_no_rating); + EXPECT_NE(song_db_with_no_rating.rating(), song_file_with_rating.rating()); + EXPECT_EQ(song_file_with_rating.rating(), old_rating_value); + + // Merging a DB song with rating should not update the rating that is in the file song... + old_rating_value = song_file_with_rating.rating(); + song_file_with_rating.MergeUserSetData(song_db_with_rating); + EXPECT_NE(song_db_with_rating.rating(), song_file_with_rating.rating()); + EXPECT_EQ(song_file_with_rating.rating(), old_rating_value); + + // ...but DB song's rating shouldn't be erased if the file song has no rating + song_file_with_no_rating.MergeUserSetData(song_db_with_rating); + EXPECT_EQ(song_file_with_no_rating.rating(), song_db_with_rating.rating()); +} + } // namespace