1 /* This file is part of Clementine.
2    Copyright 2014, David Sansome <me@davidsansome.com>
3 
4    Clementine is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8 
9    Clementine is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include "gtest/gtest.h"
19 #include "test_utils.h"
20 
21 #include "core/song.h"
22 #include "core/organiseformat.h"
23 #include "ui/organisedialog.h"
24 
25 
TEST(OrganiseDialogTest,ComputeNewSongsFilenamesTest)26 TEST(OrganiseDialogTest, ComputeNewSongsFilenamesTest) {
27   // Create some songs, with multiple similar songs
28   SongList songs;
29   {
30     Song song;
31     song.set_title("Test1");
32     song.set_album("Album");
33     songs << song;
34   }
35   // Empty song
36   {
37     Song song;
38     song.set_basefilename("filename.mp3");
39     songs << song;
40   }
41   // Without extension
42   for (int i = 0; i < 2; i++) {
43     Song song;
44     song.set_title("Test2");
45     song.set_url(QUrl("file://test" + QString::number(i)));
46     songs << song;
47   }
48 
49   // With file extension
50   for (int i = 0; i < 3; i++) {
51     Song song;
52     song.set_artist("Foo");
53     song.set_title("Bar");
54     song.set_url(QUrl("file://foobar" + QString::number(i) + ".mp3"));
55     songs << song;
56   }
57 
58   // Generate new filenames
59   OrganiseFormat format;
60   format.set_format(OrganiseDialog::kDefaultFormat);
61   Organise::NewSongInfoList new_songs_info = OrganiseDialog::ComputeNewSongsFilenames(songs, format);
62 
63   EXPECT_EQ("/Album/Test1.", new_songs_info[0].new_filename_);
64   EXPECT_EQ("//filename.mp3", new_songs_info[1].new_filename_);
65   EXPECT_EQ("//Test2.", new_songs_info[2].new_filename_);
66   EXPECT_EQ("//Test2(2).", new_songs_info[3].new_filename_);
67   EXPECT_EQ("Foo//Bar.mp3", new_songs_info[4].new_filename_);
68   EXPECT_EQ("Foo//Bar(2).mp3", new_songs_info[5].new_filename_);
69   EXPECT_EQ("Foo//Bar(3).mp3", new_songs_info[6].new_filename_);
70 }
71 
72