Tests.cpp 2.08 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
/*****************************************************************************
 * 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.
 *****************************************************************************/

23
#include "Tests.h"
24
25
26

#include <memory>

27
28
29
#include "filesystem/IFile.h"
#include "filesystem/IDirectory.h"
#include "Utils.h"
30
#include "discoverer/FsDiscoverer.h"
31
#include "mocks/FileSystem.h"
32
33
34
35
36
37
38
39
40
41
42

class TestEnv : public ::testing::Environment
{
    public:
        virtual void SetUp()
        {
            // Always clean the DB in case a previous test crashed
            unlink("test.db");
        }
};

43
44
45
void Tests::TearDown()
{
    ml.reset();
46
    unlink("test.db");
47
48
49
}


50
void Tests::Reload(std::shared_ptr<factory::IFileSystem> fs /*= nullptr*/, IMediaLibraryCb* metadataCb /*= nullptr*/ )
51
{
52
    ml.reset( new MediaLibrary );
53
    if ( fs == nullptr )
54
55
56
    {
        fs = std::shared_ptr<factory::IFileSystem>( new mock::NoopFsFactory );
    }
57
    ml->setFsFactory( fs );
58
    ml->setVerbosity( LogLevel::Error );
59
    bool res = ml->initialize( "test.db", "/tmp", metadataCb );
60
61
62
63
64
65
66
67
68
    ASSERT_TRUE( res );
}


void Tests::SetUp()
{
    Reload();
}

69
::testing::Environment* const env = ::testing::AddGlobalTestEnvironment(new TestEnv);