Commit 9ac9202b authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

tests: Add file refreshing functionnal tests

fix #94
parent 342b3bd2
......@@ -28,6 +28,8 @@
#include "parser/Parser.h"
#include "Thumbnail.h"
#include "File.h"
#include "utils/Filename.h"
#include <algorithm>
......@@ -145,7 +147,6 @@ bool MockResumeCallback::waitForParsingComplete()
});
}
void Tests::SetUp()
{
unlink("test.db");
......@@ -606,3 +607,28 @@ bool ResumeTests::MediaLibraryResumeTest::startParser()
return true;
}
void RefreshTests::forceRefresh()
{
auto files = medialibrary::File::fetchAll( m_ml.get() );
for ( const auto& f : files )
{
auto mrl = f->mrl();
auto fsFactory = m_ml->fsFactoryForMrl( mrl );
auto folderMrl = utils::file::directory( mrl );
auto fileName = utils::file::fileName( mrl );
auto folderFs = fsFactory->createDirectory( folderMrl );
auto filesFs = folderFs->files();
auto fileFsIt = std::find_if( cbegin( filesFs ), cend( filesFs ),
[&fileName]( const std::shared_ptr<fs::IFile> f ) {
return f->name() == fileName;
});
assert( fileFsIt != cend( filesFs ) );
m_ml->onUpdatedFile( f, *fileFsIt );
}
}
void RefreshTests::InitializeCallback()
{
m_cb.reset( new MockResumeCallback );
}
......@@ -117,4 +117,11 @@ public:
virtual void InitializeCallback() override;
};
class RefreshTests : public Tests
{
public:
void forceRefresh();
virtual void InitializeCallback() override;
};
#endif // TESTER_H
......@@ -153,6 +153,44 @@ TEST_P( ResumeTests, Rescan )
runChecks( doc );
}
TEST_P( RefreshTests, Refresh )
{
auto testDir = ForcedTestDirectory.empty() == false ? ForcedTestDirectory : TestDirectory;
auto casePath = testDir + "testcases/" + GetParam() + ".json";
std::unique_ptr<FILE, int(*)(FILE*)> f( fopen( casePath.c_str(), "rb" ), &fclose );
ASSERT_NE( nullptr, f );
char buff[65536]; // That's how ugly I am!
auto ret = fread( buff, sizeof(buff[0]), sizeof(buff), f.get() );
ASSERT_NE( 0u, ret );
buff[ret] = 0;
rapidjson::Document doc;
doc.Parse( buff );
ASSERT_TRUE( doc.HasMember( "input" ) );
const auto& input = doc["input"];
for ( auto i = 0u; i < input.Size(); ++i )
{
// Quick and dirty check to ensure we're discovering something that exists
auto samplesDir = testDir + "samples/" + input[i].GetString();
ASSERT_TRUE( utils::fs::isDirectory( samplesDir ) );
samplesDir = utils::fs::toAbsolute( samplesDir );
m_ml->discover( utils::file::toMrl( samplesDir ) );
}
ASSERT_TRUE( m_cb->waitForDiscoveryComplete() );
ASSERT_TRUE( m_cb->waitForParsingComplete() );
runChecks( doc );
return;
m_cb->reinit();
forceRefresh();
ASSERT_TRUE( m_cb->waitForParsingComplete() );
runChecks( doc );
}
int main(int ac, char** av)
{
::testing::InitGoogleTest(&ac, av);
......@@ -181,3 +219,6 @@ INSTANTIATE_TEST_CASE_P(SamplesTests, Tests,
INSTANTIATE_TEST_CASE_P(SamplesTests, ResumeTests,
::testing::ValuesIn(testCases) );
INSTANTIATE_TEST_CASE_P(SamplesTests, RefreshTests,
::testing::ValuesIn(testCases) );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment