Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
6f3385e4
Commit
6f3385e4
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
rm TestAutosaveController which spies on signals that are needed only for this test
parent
c31c4361
No related branches found
No related tags found
1 merge request
!2412
rm signals that are only used by test; rm TestAutosaveController; mv code between directories
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tests/Unit/GUI/TestAutosaveController.cpp
+0
-166
0 additions, 166 deletions
Tests/Unit/GUI/TestAutosaveController.cpp
with
0 additions
and
166 deletions
Tests/Unit/GUI/TestAutosaveController.cpp
deleted
100644 → 0
+
0
−
166
View file @
c31c4361
#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
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment