From 6f3385e479886348dc7ece8eb1025b8e59234f16 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Tue, 5 Mar 2024 12:16:17 +0100
Subject: [PATCH] rm TestAutosaveController which spies on signals that are
 needed only for this test

---
 Tests/Unit/GUI/TestAutosaveController.cpp | 166 ----------------------
 1 file changed, 166 deletions(-)
 delete mode 100644 Tests/Unit/GUI/TestAutosaveController.cpp

diff --git a/Tests/Unit/GUI/TestAutosaveController.cpp b/Tests/Unit/GUI/TestAutosaveController.cpp
deleted file mode 100644
index f2405d61f9b..00000000000
--- a/Tests/Unit/GUI/TestAutosaveController.cpp
+++ /dev/null
@@ -1,166 +0,0 @@
-#include "Base/Axis/Frame.h"
-#include "Device/Data/Datafield.h"
-#include "GUI/Model/Data/Data2DItem.h"
-#include "GUI/Model/Device/DatafileItem.h"
-#include "GUI/Model/Device/InstrumentItems.h"
-#include "GUI/Model/Device/InstrumentsSet.h"
-#include "GUI/Model/Project/ProjectDocument.h"
-#include "GUI/Model/Project/ProjectUtil.h"
-#include "GUI/Support/Util/Path.h"
-#include "GUI/View/Manager/AutosaveController.h"
-#include "GUI/View/Manager/ProjectManager.h"
-#include "Tests/GTestWrapper/google_test.h"
-#include "Tests/Unit/GUI/Utils.h"
-#include <QApplication>
-#include <QSignalSpy>
-#include <QUuid>
-
-class TestAutosaveController : public ::testing::Test {
-protected:
-    // helper method to modify something in a model
-    void modelsModifier(ProjectDocument& doc)
-    {
-        auto* instrument = doc.instrumentsRW()->at(0);
-        instrument->setName(QUuid::createUuid().toString());
-        emit gDoc->instruments()->currentModified();
-    }
-    const int m_save_wait = 3000;
-};
-
-//! Testing AutosaveController. It watches ProjectDocument and sends autosaveRequest() when
-//! number of document changes has been accumulated.
-
-TEST_F(TestAutosaveController, autoSaveController)
-{
-    const QString projectDir("autoSaveController");
-    UTest::GUI::create_dir(projectDir);
-    const QString ext = QString(GUI::Util::Project::projectFileExtension);
-    const QString projectFileName(projectDir + "/document" + ext);
-
-    const int autosave_time(100);
-
-    gDoc = std::make_unique<ProjectDocument>();
-    auto* instrument = new Scatter2DInstrumentItem;
-    gDoc->instrumentsRW()->add_item(instrument);
-    instrument->setName("GISAS");
-    gDoc->saveProjectFileWithData(projectFileName);
-
-    // setting up autosave
-    AutosaveController autosave;
-    autosave.setAutosaveTime(autosave_time);
-    autosave.setDocument(gDoc.get());
-
-    // checking proposed autosave directory
-    EXPECT_EQ(autosave.autosaveDir(), QString(projectDir + "/autosave"));
-    EXPECT_EQ(autosave.autosaveFullPath(), QString(projectDir + "/autosave/document" + ext));
-
-    QSignalSpy spyAutosave(&autosave, SIGNAL(autosaveRequest()));
-
-    // modify document once and check that autosave directory was created
-    modelsModifier(*gDoc);
-    EXPECT_TRUE(gDoc->isModified());
-    EXPECT_TRUE(spyAutosave.wait(m_save_wait));
-    EXPECT_EQ(spyAutosave.count(), 1);
-    EXPECT_TRUE(QFile::exists(autosave.autosaveDir()));
-
-    // saving document and checking that autosave is not triggered
-    gDoc->saveProjectFileWithData(projectFileName);
-    EXPECT_FALSE(gDoc->isModified());
-    EXPECT_EQ(spyAutosave.count(), 1);
-
-    // modify several times and check that autosave was triggered only once
-    for (size_t i = 0; i < 10; ++i)
-        modelsModifier(*gDoc);
-
-    EXPECT_TRUE(spyAutosave.wait(m_save_wait));
-    EXPECT_EQ(spyAutosave.count(), 2);
-
-    // remove autosave dir
-    autosave.removeAutosaveDir();
-    EXPECT_FALSE(QFile::exists(autosave.autosaveDir()));
-}
-
-//! AutosaveController shouldn't trigger autosaveRequest() if document has no name.
-
-TEST_F(TestAutosaveController, autoSaveControllerNewDocument)
-{
-    gDoc = std::make_unique<ProjectDocument>();
-    auto* instrument = new Scatter2DInstrumentItem;
-    gDoc->instrumentsRW()->add_item(instrument);
-    instrument->setName("GISAS");
-
-    const int autosave_time(100);
-
-    AutosaveController autosave;
-    autosave.setAutosaveTime(autosave_time);
-    autosave.setDocument(gDoc.get());
-
-    QSignalSpy spyAutosave(&autosave, SIGNAL(autosaveRequest()));
-
-    modelsModifier(*gDoc);
-    EXPECT_FALSE(spyAutosave.wait(autosave_time * 2));
-    EXPECT_EQ(spyAutosave.count(), 0);
-}
-
-//! Testing autosave after changing document.
-
-TEST_F(TestAutosaveController, autosaveEnabled)
-{
-    QApplication::setOrganizationName(
-        "BornAgainTests"); // autosave to directory ~/.config/BornAgainTests
-    const QString projectDir("autosaveEnabled");
-    UTest::GUI::create_dir(projectDir);
-    const QString ext = QString(GUI::Util::Project::projectFileExtension);
-    const QString projectFileName(projectDir + "/document" + ext);
-
-    gDoc = std::make_unique<ProjectDocument>();
-    auto manager = std::make_unique<ProjectManager>(nullptr);
-    EXPECT_TRUE(manager);
-    manager->newProject();
-    EXPECT_TRUE(gDoc);
-
-    gDoc->setProjectFullPath(projectFileName);
-    auto* instrument = new Scatter2DInstrumentItem;
-    gDoc->instrumentsRW()->add_item(instrument);
-    instrument->setName("GISAS");
-
-    DatafileItem* realData = UTest::GUI::createRealData2D("TestData", *gDoc->datafilesRW(), 0.);
-    DataItem* data_item = realData->dataItem();
-    auto frame = gDoc->instruments()->at(0)->createFrame();
-    Datafield df(frame.release());
-    data_item->setDatafield(df);
-    gDoc->clearModified();
-    EXPECT_FALSE(gDoc->isModified());
-
-    manager->setAutosaveEnabled(true);
-    const int autosave_time(200);
-    manager->autosaveController()->setAutosaveTime(autosave_time);
-    manager->autosaveController()->setDocument(gDoc.get());
-
-    QSignalSpy spyDocument(gDoc.get(), SIGNAL(projectSaved()));
-    gDoc->saveProjectFileWithData(projectFileName);
-
-    spyDocument.wait(m_save_wait); // waiting saving in a thread is complete
-    EXPECT_EQ(spyDocument.count(), 1);
-    EXPECT_FALSE(gDoc->isModified());
-    EXPECT_TRUE(QFile::exists(projectDir + "/document" + ext));
-    EXPECT_TRUE(QFile::exists(projectDir + "/realdata_TestData.int"));
-    spyDocument.clear();
-
-    // modify several times and check SaveService signals
-    for (size_t i = 0; i < 10; ++i)
-        modelsModifier(*gDoc);
-
-    EXPECT_TRUE(gDoc->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" + ext));
-    EXPECT_TRUE(QFile::exists(projectDir + "/autosave/realdata_TestData.int"));
-
-    // after autosave the project has to be still in modified state
-    EXPECT_TRUE(gDoc->isModified());
-    // after autosave, project file name should remain the same
-    EXPECT_EQ(gDoc->projectFullPath(), projectFileName);
-}
-- 
GitLab