MediaLibraryTester.h 4.05 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*****************************************************************************
 * Media Library
 *****************************************************************************
 * Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
 *
 * Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#pragma once

#include "MediaLibrary.h"
#include "Folder.h"
27
#include "medialibrary/filesystem/IDirectory.h"
28

29
30
31
32
33
34
35
using namespace medialibrary;

namespace medialibrary
{
    class Playlist;
    class AlbumTrack;
}
36
37
38
39
40

class MediaLibraryTester : public MediaLibrary
{
public:
    MediaLibraryTester();
41
    virtual bool startParser() override { return true; }
42
43
    virtual void startDiscoverer() override {}
    virtual void startDeletionNotifier() override {}
44
    std::vector<MediaPtr> files();
45
46
47
    // Use the filename getter
    using MediaLibrary::media;
    // And override the ID getter to return a Media instead of IMedia
48
    std::shared_ptr<Media> media( int64_t id );
49
    std::shared_ptr<Folder> folder( const std::string& path );
50
51
    std::shared_ptr<Playlist> playlist( int64_t playlistId );
    void deleteAlbum( int64_t albumId );
52
    std::shared_ptr<Album> createAlbum( const std::string& title );
53
    std::shared_ptr<Genre> createGenre( const std::string& name );
54
55
    void deleteGenre( int64_t genreId );
    void deleteArtist( int64_t artistId );
56
57
    std::shared_ptr<Device> addDevice( const std::string& uuid, bool isRemovable );
    void setFsFactory( std::shared_ptr<factory::IFileSystem> fsFactory );
58
59
    void deleteTrack( int64_t trackId );
    std::shared_ptr<AlbumTrack> albumTrack( int64_t id );
60
    // Use to run tests that fiddles with file properties (modification dates, size...)
61
    std::shared_ptr<Media> addFile( std::shared_ptr<fs::IFile> file);
62
63
    // Used when we need an actual file instead of an external media
    std::shared_ptr<Media> addFile( const std::string& path );
64
65
66
    std::shared_ptr<Media> addFile( std::shared_ptr<fs::IFile> fileFs,
                                    std::shared_ptr<Folder> parentFolder,
                                    std::shared_ptr<fs::IDirectory> parentFolderFs );
67
    virtual void addLocalFsFactory() override;
68
    std::shared_ptr<Device> device( const std::string& uuid );
69
    std::vector<const char*> getSupportedExtensions() const;
70
71
    virtual void addDiscoveredFile( std::shared_ptr<fs::IFile> fileFs,
                                    std::shared_ptr<Folder> parentFolder,
72
73
                                    std::shared_ptr<fs::IDirectory> parentFolderFs,
                                    std::pair<std::shared_ptr<Playlist>, unsigned int> parentPlaylist ) override;
74
    sqlite::Connection* getDbConn();
75
76

private:
77
    std::shared_ptr<fs::IDirectory> dummyDirectory;
78
    std::shared_ptr<factory::IFileSystem> fsFactory;
79
    std::shared_ptr<Folder> dummyFolder;
80
81
};

82
class MediaLibraryWithDiscoverer : public MediaLibraryTester
83
{
84
85
86
87
88
    virtual void startDiscoverer() override
    {
        // Fall back to the default variant which actually starts the discoverer
        MediaLibrary::startDiscoverer();
    }
89
90
91
92
};

class MediaLibraryWithNotifier : public MediaLibraryTester
{
93
94
95
96
97
    virtual void startDeletionNotifier() override
    {
        // Fall back to the default variant which actually starts the notifier
        MediaLibrary::startDeletionNotifier();
    }
98
};