Tests.cpp 1.11 KB
Newer Older
1
#include "Tests.h"
2 3 4

#include <memory>

5 6 7
#include "filesystem/IFile.h"
#include "filesystem/IDirectory.h"
#include "Utils.h"
8
#include "discoverer/FsDiscoverer.h"
9
#include "mocks/FileSystem.h"
10 11 12 13 14 15 16 17 18 19 20

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

21 22 23 24 25 26 27 28 29 30
void Tests::TearDown()
{
    ml.reset();
    unlink("test.db");
}


void Tests::Reload(std::shared_ptr<factory::IFileSystem> fs /* = nullptr */ )
{
    ml.reset( MediaLibraryFactory::create() );
31 32 33 34 35
    if ( fs != nullptr )
    {
        std::unique_ptr<IDiscoverer> discoverer( new FsDiscoverer( fs, ml.get() ) );
        ml->addDiscoverer( std::move( discoverer ) );
    }
36 37 38 39
    else
    {
        fs = std::shared_ptr<factory::IFileSystem>( new mock::NoopFsFactory );
    }
40
    bool res = ml->initialize( "test.db", "/tmp", fs );
41 42 43 44 45 46
    ASSERT_TRUE( res );
}


void Tests::SetUp()
{
47
    defaultFs = std::make_shared<mock::NoopFsFactory>();
48 49 50
    Reload();
}

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