From d12a0172f4fe39bda03543dabc630ab1595210e8 Mon Sep 17 00:00:00 2001 From: Matthias <github@mpuchner.de> Date: Tue, 8 Dec 2020 07:35:30 +0100 Subject: [PATCH] add unit test (which fails without the fix) --- Tests/UnitTests/GUI/TestSaveService.cpp | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Tests/UnitTests/GUI/TestSaveService.cpp b/Tests/UnitTests/GUI/TestSaveService.cpp index 31af23b77bd..f7c3668ac14 100644 --- a/Tests/UnitTests/GUI/TestSaveService.cpp +++ b/Tests/UnitTests/GUI/TestSaveService.cpp @@ -118,12 +118,44 @@ TEST_F(TestSaveService, test_saveService) { EXPECT_EQ(spySaveService.count(), 1); EXPECT_TRUE(ProjectUtils::exists(projectFileName)); + EXPECT_FALSE(service.isSaving()); // after save, document should be in non-modified state, project file name should be updated EXPECT_EQ(document->projectFileName(), projectFileName); EXPECT_FALSE(document->isModified()); } +//! Testing SaveService on simple documents (no heavy data). +//! SaveService should be not be able to save project file; state of service has to be !isSaving() +//! Regression test for issue #1136 ("After a failed project saving, no saving takes place any more; +//! crash when changing projects") + +TEST_F(TestSaveService, test_failingSaveService) { + const QString projectDir("test_failingSaveService"); + // do NOT create dir in order to force saving to fail + const QString projectFileName(projectDir + "/document.pro"); + + ApplicationModels models; + std::unique_ptr<ProjectDocument> document(new ProjectDocument); + document->setApplicationModels(&models); + modify_models(&models); + + EXPECT_FALSE(ProjectUtils::exists(projectFileName)); + + SaveService service; + QSignalSpy spySaveService(&service, SIGNAL(projectSaved())); + + service.setDocument(document.get()); + EXPECT_THROW(service.save(projectFileName), GUIHelpers::Error); + + EXPECT_EQ(spySaveService.count(), 0); + EXPECT_FALSE(ProjectUtils::exists(projectFileName)); + EXPECT_FALSE(service.isSaving()); + + // after failed save, document should still be in modified state + EXPECT_TRUE(document->isModified()); +} + //! Testing SaveService on documents having nonXML data. //! SaveService should be able to save project file (in main thread) and project nonXML //! in second thread. -- GitLab