Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
c165c386
Commit
c165c386
authored
Jan 21, 2016
by
Federico Montesino Pouzols
Browse files
Merge pull request #15037 from mantidproject/14923_unit_tests_for_cropped_calib_engg_gui
Engg GUI::Unit Tests For Cropped Calibration
parents
1cfc6dfc
3932a112
Changes
2
Hide whitespace changes
Inline
Side-by-side
MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp
View file @
c165c386
...
...
@@ -197,13 +197,12 @@ void EnggDiffractionPresenter::ProcessCropCalib() {
enum
BankMode
{
SPECIDS
=
0
,
NORTH
=
1
,
SOUTH
=
2
};
try
{
inputChecksBeforeCalibrate
(
vanNo
,
ceriaNo
);
if
(
m_view
->
currentCalibSpecNos
().
empty
()
&&
specIdNum
==
BankMode
::
SPECIDS
)
{
throw
std
::
invalid_argument
(
"The Spectrum IDs cannot be empty, must be a"
"valid range or a Bank Name can be selected instead"
);
inputChecksBeforeCalibrate
(
vanNo
,
ceriaNo
);
}
}
catch
(
std
::
invalid_argument
&
ia
)
{
m_view
->
userWarning
(
"Error in the inputs required for calibrate"
,
...
...
MantidQt/CustomInterfaces/test/EnggDiffractionPresenterTest.h
View file @
c165c386
...
...
@@ -336,6 +336,267 @@ public:
pres
.
notify
(
IEnggDiffractionPresenter
::
CalcCalib
);
}
// This would test the cropped calibration with no cerial number
// which should produce a warning
void
test_calcCroppedCalibWithoutRunNumbers
()
{
testing
::
NiceMock
<
MockEnggDiffractionView
>
mockView
;
MantidQt
::
CustomInterfaces
::
EnggDiffractionPresenter
pres
(
&
mockView
);
// would need basic calibration settings from the user, but it should not
// get to that point because of early detected errors:
EXPECT_CALL
(
mockView
,
currentCalibSettings
()).
Times
(
0
);
EXPECT_CALL
(
mockView
,
newVanadiumNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_vanNo
));
EXPECT_CALL
(
mockView
,
newCeriaNo
())
.
Times
(
1
)
.
WillOnce
(
Return
(
m_ex_empty_run_num
));
// No errors, 1 warning (no Vanadium, no Ceria run numbers given)
EXPECT_CALL
(
mockView
,
userError
(
testing
::
_
,
testing
::
_
)).
Times
(
0
);
EXPECT_CALL
(
mockView
,
userWarning
(
testing
::
_
,
testing
::
_
)).
Times
(
1
);
pres
.
notify
(
IEnggDiffractionPresenter
::
CropCalib
);
}
// this can start the cropped calibration thread, so watch out
// the test provide gui with missing calib settings
// which should return a single error
void
test_calcCroppedCalibWithSettingsMissing
()
{
testing
::
NiceMock
<
MockEnggDiffractionView
>
mockView
;
// this test can start a Qt thread that needs signals/slots
// Don't do: MantidQt::CustomInterfaces::EnggDiffractionPresenter
// pres(&mockView);
MantidQt
::
CustomInterfaces
::
EnggDiffractionPresenter
pres
(
&
mockView
);
const
std
::
string
instr
=
"FAKEINSTR"
;
const
std
::
string
vanNo
=
"9999999999"
;
// use a number that won't be found!
const
std
::
string
ceriaNo
=
"9999999999"
;
// use a number that won't be found!
EnggDiffCalibSettings
calibSettings
;
EXPECT_CALL
(
mockView
,
currentCalibSettings
())
.
Times
(
1
)
.
WillOnce
(
Return
(
calibSettings
));
EXPECT_CALL
(
mockView
,
newVanadiumNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_vanNo
));
EXPECT_CALL
(
mockView
,
newCeriaNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_ceriaNo
));
// 1 warning because some required settings are missing/empty
EXPECT_CALL
(
mockView
,
userWarning
(
testing
::
_
,
testing
::
_
)).
Times
(
1
);
EXPECT_CALL
(
mockView
,
userError
(
testing
::
_
,
testing
::
_
)).
Times
(
0
);
TS_ASSERT_THROWS_NOTHING
(
pres
.
notify
(
IEnggDiffractionPresenter
::
CropCalib
));
}
// This should not start the process, tests with an empty spec number which
// should generate a user warning that spec number is missing
void
test_calcCroppedCalibWithEmptySpec
()
{
testing
::
NiceMock
<
MockEnggDiffractionView
>
mockView
;
// this test would start a Qt thread that needs signals/slots
// Don't do: MantidQt::CustomInterfaces::EnggDiffractionPresenter
// pres(&mockView);
EnggDiffPresenterNoThread
pres
(
&
mockView
);
const
std
::
string
instr
=
"ENGINX"
;
const
std
::
string
vanNo
=
"8899999988"
;
// use a number that won't be found!
const
std
::
string
ceriaNo
=
"9999999999"
;
// use a number that won't be found!
// will need basic calibration settings from the user
EnggDiffCalibSettings
calibSettings
;
calibSettings
.
m_pixelCalibFilename
=
instr
+
"_"
+
vanNo
+
"_"
+
ceriaNo
+
".prm"
;
calibSettings
.
m_templateGSAS_PRM
=
"fake.prm"
;
EXPECT_CALL
(
mockView
,
currentCalibSettings
())
.
Times
(
1
)
.
WillOnce
(
Return
(
calibSettings
));
EXPECT_CALL
(
mockView
,
newVanadiumNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_vanNo
));
EXPECT_CALL
(
mockView
,
newCeriaNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_ceriaNo
));
std
::
string
specid
=
""
;
EXPECT_CALL
(
mockView
,
currentCalibSpecNos
())
.
Times
(
1
)
.
WillOnce
(
Return
(
specid
));
// No warnings/error pop-ups: some exception(s) are thrown (because there
// are missing settings and/or files) but these must be caught
// and error messages logged
EXPECT_CALL
(
mockView
,
userWarning
(
testing
::
_
,
testing
::
_
)).
Times
(
1
);
EXPECT_CALL
(
mockView
,
userError
(
testing
::
_
,
testing
::
_
)).
Times
(
0
);
pres
.
notify
(
IEnggDiffractionPresenter
::
CropCalib
);
}
// this test actually starts the cropped calibration process - which implies
// starting
// the thread unless you use the mock without thread
// this will utlise the bank name north and not still carry out the cropped
// calibration process normal
void
test_calcCroppedCalibWithBankName
()
{
testing
::
NiceMock
<
MockEnggDiffractionView
>
mockView
;
// this test would start a Qt thread that needs signals/slots
// Don't do: MantidQt::CustomInterfaces::EnggDiffractionPresenter
// pres(&mockView);
EnggDiffPresenterNoThread
pres
(
&
mockView
);
const
std
::
string
instr
=
"ENGINX"
;
const
std
::
string
vanNo
=
"8899999988"
;
// use a number that won't be found!
const
std
::
string
ceriaNo
=
"9999999999"
;
// use a number that won't be found!
// will need basic calibration settings from the user
EnggDiffCalibSettings
calibSettings
;
calibSettings
.
m_pixelCalibFilename
=
instr
+
"_"
+
vanNo
+
"_"
+
ceriaNo
+
".prm"
;
calibSettings
.
m_templateGSAS_PRM
=
"fake.prm"
;
EXPECT_CALL
(
mockView
,
currentCalibSettings
())
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
calibSettings
));
EXPECT_CALL
(
mockView
,
newVanadiumNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_vanNo
));
EXPECT_CALL
(
mockView
,
newCeriaNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_ceriaNo
));
// North bank selected so the spectrum ID will not be called and
// process should carry on without spec id input
EXPECT_CALL
(
mockView
,
currentCropCalibBankName
())
.
Times
(
1
)
.
WillOnce
(
Return
(
1
));
const
std
::
string
filename
=
"UNKNOWNINST_"
+
vanNo
+
"_"
+
ceriaNo
+
"_"
+
"foo.prm"
;
EXPECT_CALL
(
mockView
,
askNewCalibrationFilename
(
"UNKNOWNINST_"
+
vanNo
+
"_"
+
ceriaNo
+
"_both_banks.prm"
))
.
Times
(
0
);
// .WillOnce(Return(filename)); // if enabled ask user output filename
// should disable actions at the beginning of the calculations
EXPECT_CALL
(
mockView
,
enableCalibrateAndFocusActions
(
false
)).
Times
(
1
);
// and should enable them again at the (unsuccessful) end - this happens
// when a separate thread finished (here the thread is mocked)
EXPECT_CALL
(
mockView
,
enableCalibrateAndFocusActions
(
true
)).
Times
(
1
);
// No warnings/error pop-ups: some exception(s) are thrown (because there
// are missing settings and/or files) but these must be caught
// and error messages logged
EXPECT_CALL
(
mockView
,
userWarning
(
testing
::
_
,
testing
::
_
)).
Times
(
0
);
EXPECT_CALL
(
mockView
,
userError
(
testing
::
_
,
testing
::
_
)).
Times
(
0
);
pres
.
notify
(
IEnggDiffractionPresenter
::
CropCalib
);
}
// this test actually starts the cropped calibration process - which implies
// starting the thread unless you use the mock without thread
// this test case includes all valid settings, run numbers, spectrum id
// selected
// & valid spectrum id provided
void
test_calcCroppedCalibWithRunNumbers
()
{
testing
::
NiceMock
<
MockEnggDiffractionView
>
mockView
;
// this test would start a Qt thread that needs signals/slots
// Don't do: MantidQt::CustomInterfaces::EnggDiffractionPresenter
// pres(&mockView);
EnggDiffPresenterNoThread
pres
(
&
mockView
);
const
std
::
string
instr
=
"ENGINX"
;
const
std
::
string
vanNo
=
"8899999988"
;
// use a number that won't be found!
const
std
::
string
ceriaNo
=
"9999999999"
;
// use a number that won't be found!
// will need basic calibration settings from the user
EnggDiffCalibSettings
calibSettings
;
calibSettings
.
m_pixelCalibFilename
=
instr
+
"_"
+
vanNo
+
"_"
+
ceriaNo
+
".prm"
;
calibSettings
.
m_templateGSAS_PRM
=
"fake.prm"
;
EXPECT_CALL
(
mockView
,
currentCalibSettings
())
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
calibSettings
));
EXPECT_CALL
(
mockView
,
newVanadiumNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_vanNo
));
EXPECT_CALL
(
mockView
,
newCeriaNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_ceriaNo
));
EXPECT_CALL
(
mockView
,
currentCropCalibBankName
())
.
Times
(
1
)
.
WillOnce
(
Return
(
0
));
std
::
string
specid
=
"100-200"
;
EXPECT_CALL
(
mockView
,
currentCalibSpecNos
())
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
specid
));
const
std
::
string
filename
=
"UNKNOWNINST_"
+
vanNo
+
"_"
+
ceriaNo
+
"_"
+
"foo.prm"
;
EXPECT_CALL
(
mockView
,
askNewCalibrationFilename
(
"UNKNOWNINST_"
+
vanNo
+
"_"
+
ceriaNo
+
"_both_banks.prm"
))
.
Times
(
0
);
// .WillOnce(Return(filename)); // if enabled ask user output filename
// Should not try to use options for focusing
EXPECT_CALL
(
mockView
,
focusingRunNo
()).
Times
(
0
);
EXPECT_CALL
(
mockView
,
focusingCroppedRunNo
()).
Times
(
0
);
EXPECT_CALL
(
mockView
,
focusingTextureRunNo
()).
Times
(
0
);
EXPECT_CALL
(
mockView
,
focusingCroppedSpectrumIDs
()).
Times
(
0
);
EXPECT_CALL
(
mockView
,
focusingTextureGroupingFile
()).
Times
(
0
);
// should disable actions at the beginning of the calculations
EXPECT_CALL
(
mockView
,
enableCalibrateAndFocusActions
(
false
)).
Times
(
1
);
// and should enable them again at the (unsuccessful) end - this happens
// when a separate thread finished (here the thread is mocked)
EXPECT_CALL
(
mockView
,
enableCalibrateAndFocusActions
(
true
)).
Times
(
1
);
// No warnings/error pop-ups: some exception(s) are thrown (because there
// are missing settings and/or files) but these must be caught
// and error messages logged
EXPECT_CALL
(
mockView
,
userWarning
(
testing
::
_
,
testing
::
_
)).
Times
(
0
);
EXPECT_CALL
(
mockView
,
userError
(
testing
::
_
,
testing
::
_
)).
Times
(
0
);
pres
.
notify
(
IEnggDiffractionPresenter
::
CropCalib
);
}
// TODO: disabled for now, as this one would need to load files
void
disable_test_calcCropCalibOK
()
{
testing
::
NiceMock
<
MockEnggDiffractionView
>
mockView
;
MantidQt
::
CustomInterfaces
::
EnggDiffractionPresenter
pres
(
&
mockView
);
// will need basic calibration settings from the user
EXPECT_CALL
(
mockView
,
currentCalibSettings
())
.
Times
(
1
)
.
WillOnce
(
Return
(
m_basicCalibSettings
));
// As this is a positive test, personal directory/files should be
// provided here instead
EXPECT_CALL
(
mockView
,
newVanadiumNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_vanNo
));
EXPECT_CALL
(
mockView
,
newCeriaNo
()).
Times
(
1
).
WillOnce
(
Return
(
g_ceriaNo
));
EXPECT_CALL
(
mockView
,
currentCropCalibBankName
())
.
Times
(
1
)
.
WillOnce
(
Return
(
0
));
std
::
string
specid
=
"100-200"
;
EXPECT_CALL
(
mockView
,
currentCalibSpecNos
())
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
specid
));
// No errors/warnings
EXPECT_CALL
(
mockView
,
userError
(
testing
::
_
,
testing
::
_
)).
Times
(
0
);
EXPECT_CALL
(
mockView
,
userWarning
(
testing
::
_
,
testing
::
_
)).
Times
(
0
);
pres
.
notify
(
IEnggDiffractionPresenter
::
CropCalib
);
}
void
test_focusWithoutRunNumber
()
{
testing
::
NiceMock
<
MockEnggDiffractionView
>
mockView
;
MantidQt
::
CustomInterfaces
::
EnggDiffractionPresenter
pres
(
&
mockView
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment