Skip to content
Snippets Groups Projects
Commit 5c9954fd authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

restore autosaveEnabled test

parent e7c51e7d
No related branches found
No related tags found
1 merge request!1293GUI: simplify save/load machinery
......@@ -176,6 +176,7 @@ void ProjectDocument::saveProjectFileWithData(const QString& projectPullPath)
setProjectFullPath(projectPullPath);
clearModified();
}
emit projectSaved();
}
ProjectDocument::ReadResult ProjectDocument::loadProjectFileWithData(const QString& projectPullPath,
......
......@@ -112,16 +112,10 @@ public:
void setFunctionalities(const Functionalities& f);
signals:
//! Emitted for _any_ modifications in the document
void projectSaved();
void modifiedStateChanged();
//! Emitted when functionality has changed
void functionalitiesChanged();
//! Emitted when single instrument mode has changed
void singleInstrumentModeChanged();
//! Emitted when single sample mode has changed
void singleSampleModeChanged();
private:
......
......@@ -186,6 +186,11 @@ bool ProjectManager::isAutosaveEnabled() const
return static_cast<bool>(m_autosave);
}
AutosaveController *ProjectManager::autosaveController() const
{
return m_autosave.get();
}
void ProjectManager::setAutosaveEnabled(bool value)
{
if (value)
......
......@@ -43,6 +43,7 @@ public:
void setRecentlyUsedImportFilter2D(const QString& filter);
bool isAutosaveEnabled() const;
AutosaveController* autosaveController() const;
signals:
void aboutToCloseDocument();
......
......@@ -3,7 +3,7 @@
#include "GUI/Model/Data/RealItem.h"
#include "GUI/Model/Device/InstrumentItems.h"
#include "GUI/Model/Model/RealModel.h"
#include "GUI/Model/Project/ProjectDocument.h"
#include "GUI/View/Project/ProjectManager.h"
#include "GUI/Support/IO/ProjectUtils.h"
#include "GUI/Util/Error.h"
#include "GUI/Util/Path.h"
......@@ -97,8 +97,8 @@ TEST_F(TestSaveService, autoSaveControllerNewDocument)
EXPECT_EQ(spyAutosave.count(), 0);
}
//! Testing SaveService on simple documents (no heavy data).
//! SaveService should not be able to save project file; state of service has to be !isSaving()
//! Testing ProjectDocument on simple documents (no heavy data).
//! ProjectDocument should not be able to save project file.
//! Regression test for issue #1136 ("After a failed project saving, no saving takes place any more;
//! crash when changing projects")
......@@ -126,56 +126,61 @@ TEST_F(TestSaveService, failingSaveService)
EXPECT_TRUE(document->isModified());
}
//! Testing SaveService when autosave is enabled.
//! Testing autosave after changing document.
TEST_F(TestSaveService, autosaveEnabled)
{
// const QString projectDir("test_autosaveEnabled");
// UTest::GUI::create_dir(projectDir);
// const QString projectFileName(projectDir + "/document.pro");
// std::unique_ptr<ProjectDocument> document(new ProjectDocument());
// document->setProjectFullPath(projectFileName);
// auto* instrument = document->instrumentModel()->addInstrumentItem<GISASInstrumentItem>();
// instrument->setInstrumentName("GISAS");
// RealItem* realData = UTest::GUI::createRealData("TestData", *document->realModel());
// DataItem* intensityItem = realData->dataItem();
// GUI::Model::JobItemUtils::createDefaultDetectorMap(
// intensityItem, document->instrumentModel()->instrument2DItems().front());
// document->clearModified();
// EXPECT_FALSE(document->isModified());
// SaveService service;
// service.setAutosaveEnabled(true);
// const int autosave_time(200);
// service.setAutosaveTime(autosave_time);
// service.setDocument(document.get());
// QSignalSpy spySaveService(&service, SIGNAL(projectSaved()));
// service.save(projectFileName);
// spySaveService.wait(m_save_wait); // waiting saving in a thread is complete
// EXPECT_EQ(spySaveService.count(), 1);
// EXPECT_FALSE(document->isModified());
// EXPECT_TRUE(QFile::exists(projectDir + "/document.pro"));
// EXPECT_TRUE(QFile::exists(projectDir + "/realdata_TestData_0.int.gz"));
// spySaveService.clear();
// // modify several times and check SaveService signals
// for (size_t i = 0; i < 10; ++i)
// modify_models(*document);
// EXPECT_TRUE(document->isModified());
// spySaveService.wait(m_save_wait); // waiting saving in a thread is complete
// EXPECT_EQ(spySaveService.count(), 1);
// EXPECT_TRUE(QFile::exists(projectDir + "/autosave/document.pro"));
// EXPECT_TRUE(QFile::exists(projectDir + "/autosave/realdata_TestData_0.int.gz"));
// // after autosave the project has to be still in modified state
// EXPECT_TRUE(document->isModified());
// // after autosave, project file name should remain the same
// EXPECT_EQ(document->projectFullPath(), projectFileName);
const QString projectDir("test_autosaveEnabled");
UTest::GUI::create_dir(projectDir);
const QString projectFileName(projectDir + "/document.pro");
std::unique_ptr<ProjectManager> manager(new ProjectManager(nullptr));
manager->newProject();
EXPECT_TRUE(gProjectDocument.has_value());
ProjectDocument* document = gProjectDocument.value();
EXPECT_TRUE(document != nullptr);
document->setProjectFullPath(projectFileName);
auto* instrument = document->instrumentModel()->addInstrumentItem<GISASInstrumentItem>();
instrument->setInstrumentName("GISAS");
RealItem* realData = UTest::GUI::createRealData("TestData", *document->realModel());
DataItem* intensityItem = realData->dataItem();
GUI::Model::JobItemUtils::createDefaultDetectorMap(
intensityItem, document->instrumentModel()->instrument2DItems().front());
document->clearModified();
EXPECT_FALSE(document->isModified());
manager->setAutosaveEnabled(true);
const int autosave_time(200);
manager->autosaveController()->setAutosaveTime(autosave_time);
manager->autosaveController()->setDocument(document);
QSignalSpy spyDocument(document, SIGNAL(projectSaved()));
document->saveProjectFileWithData(projectFileName);
spyDocument.wait(m_save_wait); // waiting saving in a thread is complete
EXPECT_EQ(spyDocument.count(), 1);
EXPECT_FALSE(document->isModified());
EXPECT_TRUE(QFile::exists(projectDir + "/document.pro"));
EXPECT_TRUE(QFile::exists(projectDir + "/realdata_TestData_0.int.gz"));
spyDocument.clear();
// modify several times and check SaveService signals
for (size_t i = 0; i < 10; ++i)
modify_models(*document);
EXPECT_TRUE(document->isModified());
spyDocument.wait(m_save_wait); // waiting saving in a thread is complete
EXPECT_EQ(spyDocument.count(), 1);
EXPECT_TRUE(QFile::exists(projectDir + "/autosave/document.pro"));
EXPECT_TRUE(QFile::exists(projectDir + "/autosave/realdata_TestData_0.int.gz"));
// after autosave the project has to be still in modified state
EXPECT_TRUE(document->isModified());
// after autosave, project file name should remain the same
EXPECT_EQ(document->projectFullPath(), projectFileName);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment