EnggDiffractionPresenterTest.h 29.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONPRESENTERTEST_H
#define MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONPRESENTERTEST_H

#include "MantidAPI/FrameworkManager.h"
#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h"

#include <cxxtest/TestSuite.h>
#include "EnggDiffractionViewMock.h"

using namespace MantidQt::CustomInterfaces;
using testing::TypedEq;
using testing::Return;

14
15
16
17
18
19
20
21
22
23
24
// Use this mocked presenter for tests that will start the calibration thread.
// Otherwise you'll run into trouble with issues like "QEventLoop: Cannot be
// used without QApplication", as there is not Qt application here and the
// normal Qt thread used by the presenter uses signals/slots.
class EnggDiffPresenterNoThread : public EnggDiffractionPresenter {
public:
  EnggDiffPresenterNoThread(IEnggDiffractionView *view)
      : EnggDiffractionPresenter(view) {}

private:
  // not async at all
25
  void startAsyncCalibWorker(const std::string &outFilename,
26
27
                             const std::string &vanNo,
                             const std::string &ceriaNo) {
28
29
30
    doNewCalibration(outFilename, vanNo, ceriaNo);
    calibrationFinished();
  }
31
32

  void startAsyncFocusWorker(const std::string &dir,
33
34
                             const std::vector<std::string> &outFilenames,
                             const std::string &runNo,
35
36
37
38
                             const std::vector<bool> banks,
                             const std::string &specIDs,
                             const std::string &dgFile) {
    doFocusRun(dir, outFilenames, runNo, banks, specIDs, dgFile);
39
40
    focusingFinished();
  }
41
42
};

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class EnggDiffractionPresenterTest : public CxxTest::TestSuite {

public:
  // This pair of boilerplate methods prevent the suite being created statically
  // This means the constructor isn't called when running other tests
  static EnggDiffractionPresenterTest *createSuite() {
    return new EnggDiffractionPresenterTest();
  }

  static void destroySuite(EnggDiffractionPresenterTest *suite) {
    delete suite;
  }

  EnggDiffractionPresenterTest() {
    Mantid::API::FrameworkManager::Instance(); // make sure framework is
                                               // initialized
  }

  void setUp() {
    m_view.reset(new testing::NiceMock<MockEnggDiffractionView>());
    m_presenter.reset(
        new MantidQt::CustomInterfaces::EnggDiffractionPresenter(m_view.get()));
65
66
67

    m_ex_enginx_banks.push_back(true);
    m_ex_enginx_banks.push_back(false);
68
69
70
71
72
73
  }

  void tearDown() {
    TS_ASSERT(testing::Mock::VerifyAndClearExpectations(m_view.get()));
  }

74
75
76
77
78
  // TODO: There should be a few basic tests on the presenter here, including
  // methods like: parseCalibrateFilename, buildCalibrateSuggestedFilename, etc.
  // Several of these are indirectly tested through some of the GUI-mock-based
  // tests below but should be tested as isolated methods here at the beginning.

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  void test_start() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    std::vector<std::string> sv;
    sv.push_back("dummy msg");
    EXPECT_CALL(mockView, logMsgs()).Times(1).WillOnce(Return(sv));

    // No errors/warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::LogMsg);
  }

94
  void test_loadExistingCalibWithWrongName() {
95
96
97
98
99
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // will need basic calibration settings from the user
    EnggDiffCalibSettings calibSettings;
100
101
102
    EXPECT_CALL(mockView, currentCalibSettings())
        .Times(1)
        .WillOnce(Return(calibSettings));
103

104
    const std::string mockFname = "foo.par";
105
106
107
    EXPECT_CALL(mockView, askExistingCalibFilename())
        .Times(1)
        .WillOnce(Return(mockFname));
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

    // should not get to the point where the calibration is calculated
    EXPECT_CALL(mockView, newCalibLoaded(testing::_, testing::_, mockFname))
        .Times(0);

    // Should show a warning but no errors
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::LoadExistingCalib);
  }

  void test_loadExistingCalibWithAcceptableName() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // will need basic calibration settings from the user
    EnggDiffCalibSettings calibSettings;
126
127
128
    EXPECT_CALL(mockView, currentCalibSettings())
        .Times(1)
        .WillOnce(Return(calibSettings));
129
130

    const std::string mockFname = "ENGINX_111111_222222_foo_bar.par";
131
132
133
    EXPECT_CALL(mockView, askExistingCalibFilename())
        .Times(1)
        .WillOnce(Return(mockFname));
134
135
136
    EXPECT_CALL(mockView, newCalibLoaded(testing::_, testing::_, mockFname))
        .Times(1);

137
138
139
140
141
142
143
    // No errors/warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::LoadExistingCalib);
  }

144
145
146
147
  void test_calcCalibWithoutRunNumbers() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

148
149
    // would need basic calibration settings from the user, but it should not
    // get to that point because of early detected errors:
150
    EnggDiffCalibSettings calibSettings;
151
    EXPECT_CALL(mockView, currentCalibSettings()).Times(0);
152

153
    // No errors, 1 warning (no Vanadium, no Ceria run numbers given)
154
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
155
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);
156

157
158
159
160
    // does not update the current calibration as it must have failed
    EXPECT_CALL(mockView, newCalibLoaded(testing::_, testing::_, testing::_))
        .Times(0);

161
162
163
    pres.notify(IEnggDiffractionPresenter::CalcCalib);
  }

164
  // this can start the calibration thread, so watch out
165
  void test_calcCalibWithSettingsMissing() {
166
    testing::NiceMock<MockEnggDiffractionView> mockView;
167
168
169
170

    // this test can start a Qt thread that needs signals/slots
    // Don't do: MantidQt::CustomInterfaces::EnggDiffractionPresenter
    // pres(&mockView);
171
172
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

173
174
175
176
177
178
179
    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!

    // will need basic calibration settings from the user - but I forget to set
    // them
180
    EnggDiffCalibSettings calibSettings;
181

182
183
184
    EXPECT_CALL(mockView, currentCalibSettings())
        .Times(1)
        .WillOnce(Return(calibSettings));
185
186
187

    EXPECT_CALL(mockView, newVanadiumNo()).Times(1).WillOnce(Return(vanNo));

188
189
190
191
192
193
194
195
196
197
198
199
200
    EXPECT_CALL(mockView, newCeriaNo()).Times(1).WillOnce(Return(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);

    // does not update the current calibration as it must have failed
    EXPECT_CALL(mockView, newCalibLoaded(testing::_, testing::_, testing::_))
        .Times(0);

    TS_ASSERT_THROWS_NOTHING(pres.notify(IEnggDiffractionPresenter::CalcCalib));
  }

201
202
  // this test actually starts the calibration process - which implies starting
  // the thread unless you use the mock without thread
203
204
205
206
207
208
209
210
  void test_calcCalibWithRunNumbersButError() {
    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);

211
212
    const std::string instr = "ENGINX";
    const std::string vanNo = "8899999988"; // use a number that won't be found!
213
214
    const std::string ceriaNo =
        "9999999999"; // use a number that won't be found!
215
216
217
218
219
220

    // will need basic calibration settings from the user
    EnggDiffCalibSettings calibSettings;
    calibSettings.m_pixelCalibFilename =
        instr + "_" + vanNo + "_" + ceriaNo + ".prm";
    calibSettings.m_templateGSAS_PRM = "fake.prm";
221
222
223
    EXPECT_CALL(mockView, currentCalibSettings())
        .Times(2)
        .WillRepeatedly(Return(calibSettings));
224
225
226

    EXPECT_CALL(mockView, newVanadiumNo()).Times(1).WillOnce(Return(vanNo));

227
228
229
230
    EXPECT_CALL(mockView, newCeriaNo()).Times(1).WillOnce(Return(ceriaNo));

    EXPECT_CALL(mockView, currentInstrument()).Times(1).WillOnce(Return(instr));

231
232
    const std::string filename =
        "UNKNOWNINST_" + vanNo + "_" + ceriaNo + "_" + "foo.prm";
233
234
235
    EXPECT_CALL(mockView, askNewCalibrationFilename(
                              "UNKNOWNINST_" + vanNo + "_" + ceriaNo +
                              "_both_banks.prm")).Times(0);
236
    //  .WillOnce(Return(filename)); // if enabled ask user output filename
237

238
239
240
241
242
243
244
    // 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);

245
    // should disable actions at the beginning of the calculations
246
    EXPECT_CALL(mockView, enableCalibrateAndFocusActions(false)).Times(1);
247
248
249

    // and should enable them again at the (unsuccessful) end - this happens
    // when a separate thread finished (here the thread is mocked)
250
    EXPECT_CALL(mockView, enableCalibrateAndFocusActions(true)).Times(1);
251
252
253
254

    // 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
255
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);
256
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
257

258
259
260
261
    // does not update the current calibration as it must have failed
    EXPECT_CALL(mockView, newCalibLoaded(testing::_, testing::_, testing::_))
        .Times(0);

262
    // TS_ASSERT_THROWS_NOTHING(pres.notify(IEnggDiffractionPresenter::CalcCalib));
263
    pres.notify(IEnggDiffractionPresenter::CalcCalib);
264
265
  }

266
267
  // TODO: disabled for now, as this one would need to load files
  void disabled_test_calcCalibOK() {
268
269
270
271
272
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // will need basic calibration settings from the user
    EnggDiffCalibSettings calibSettings;
273
274
275
    EXPECT_CALL(mockView, currentCalibSettings())
        .Times(2)
        .WillOnce(Return(calibSettings));
276
277
278
279
280
281
282
283

    // No errors/warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::CalcCalib);
  }

284
285
286
287
288
289
  void test_focusWithoutRunNumber() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // empty run number!
    EXPECT_CALL(mockView, focusingRunNo()).Times(1).WillOnce(Return(""));
290
291
292
    EXPECT_CALL(mockView, focusingBanks())
        .Times(1)
        .WillOnce(Return(m_ex_enginx_banks));
293

294
295
296
297
    // should not try to use these ones
    EXPECT_CALL(mockView, focusingCroppedRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingCroppedSpectrumIDs()).Times(0);
    EXPECT_CALL(mockView, focusingTextureGroupingFile()).Times(0);
298
299
    EXPECT_CALL(mockView, focusedOutWorkspace()).Times(0);
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0);
300

301
302
303
304
305
306
307
308
309
310
311
    // should not get that far that it tries to get these parameters
    EXPECT_CALL(mockView, currentInstrument()).Times(0);
    EXPECT_CALL(mockView, currentCalibSettings()).Times(0);

    // 1 warning pop-up to user, 0 errors
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::FocusRun);
  }

312
  void test_focusWithRunNumberButWrongBanks() {
313
314
315
316
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    EXPECT_CALL(mockView, focusingRunNo()).Times(1).WillOnce(Return("999999"));
317
    // missing bank on/off vector!
318
319
320
321
    std::vector<bool> banks;
    banks.push_back(false);
    banks.push_back(false);
    EXPECT_CALL(mockView, focusingBanks()).Times(1).WillOnce(Return(banks));
322

323
324
325
    // would needs basic calibration settings, but only if there was at least
    // one bank selected
    EXPECT_CALL(mockView, currentCalibSettings()).Times(0);
326
327
328

    // should not get that far that it tries to get these parameters
    EXPECT_CALL(mockView, currentInstrument()).Times(0);
329
330
    EXPECT_CALL(mockView, focusedOutWorkspace()).Times(0);
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0);
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348

    // 1 warning pop-up to user, 0 errors
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::FocusRun);
  }

  // the focusing process starts but the input run number cannot be found
  void test_focusWithNumbersButError() {
    testing::NiceMock<MockEnggDiffractionView> mockView;

    // this test starts the focusing process which would start a Qt
    // thread that needs signals/slots Don't do:
    // MantidQt::CustomInterfaces::EnggDiffractionPresenter
    // pres(&mockView);
    EnggDiffPresenterNoThread pres(&mockView);

349
    // wrong run number!
350
    EXPECT_CALL(mockView, focusingRunNo()).Times(1).WillOnce(Return("999999"));
351
352
353
    EXPECT_CALL(mockView, focusingBanks())
        .Times(1)
        .WillOnce(Return(m_ex_enginx_banks));
354
355
356

    // needs basic calibration settings from the user to start focusing
    EnggDiffCalibSettings calibSettings;
357
358
359
    EXPECT_CALL(mockView, currentCalibSettings())
        .Times(1)
        .WillOnce(Return(calibSettings));
360

361
362
363
364
365
    // Should not try to use options for other types of focusing
    EXPECT_CALL(mockView, focusingCroppedRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingTextureRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingCroppedSpectrumIDs()).Times(0);
    EXPECT_CALL(mockView, focusingTextureGroupingFile()).Times(0);
366
367
    EXPECT_CALL(mockView, focusedOutWorkspace()).Times(0);
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0);
368

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
    // it should not get there
    EXPECT_CALL(mockView, enableCalibrateAndFocusActions(false)).Times(0);
    EXPECT_CALL(mockView, enableCalibrateAndFocusActions(true)).Times(0);

    // 0 errors, 1 warning error pop-up to user
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::FocusRun);
  }

  // TODO: disabled for now, as this one would need to load files
  void disabled_test_focusOK() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // an example run available in unit test data:
    EXPECT_CALL(mockView, focusingRunNo()).Times(1).WillOnce(Return("228061"));
387
388
389
    EXPECT_CALL(mockView, focusingBanks())
        .Times(1)
        .WillOnce(Return(m_ex_enginx_banks));
390
391
392

    // will need basic calibration settings from the user
    EnggDiffCalibSettings calibSettings;
393
394
395
    EXPECT_CALL(mockView, currentCalibSettings())
        .Times(1)
        .WillOnce(Return(calibSettings));
396

397
    // check automatic plotting
398
399
400
    EXPECT_CALL(mockView, focusedOutWorkspace())
        .Times(1)
        .WillOnce(Return(true));
401
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(1);
402
403
    // There are two/three other tests that have the disabled_ prefix so they
    // normally run
404

405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
    // Should not try to use options for other types of focusing
    EXPECT_CALL(mockView, focusingCroppedRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingTextureRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingCroppedSpectrumIDs()).Times(0);
    EXPECT_CALL(mockView, focusingTextureGroupingFile()).Times(0);

    // No errors/warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::FocusRun);
  }

  void disabled_test_focusOK_allBanksOff() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // an example run available in unit test data:
    EXPECT_CALL(mockView, focusingRunNo()).Times(1).WillOnce(Return("228061"));
    std::vector<bool> banks;
    banks.push_back(false);
    banks.push_back(false);
427
    EXPECT_CALL(mockView, focusingBanks()).Times(1).WillOnce(Return(banks));
428
429
430

    // will need basic calibration settings from the user
    EnggDiffCalibSettings calibSettings;
431
432
433
    EXPECT_CALL(mockView, currentCalibSettings())
        .Times(1)
        .WillOnce(Return(calibSettings));
434

435
436
437
    EXPECT_CALL(mockView, focusedOutWorkspace()).Times(0);
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0);

438
439
440
441
442
443
444
    // No errors/warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::FocusRun);
  }

445
446
447
448
449
450
  void test_focusCropped_withoutRunNo() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // empty run number!
    EXPECT_CALL(mockView, focusingCroppedRunNo()).Times(1).WillOnce(Return(""));
451
452
453
454
455
456
    EXPECT_CALL(mockView, focusingBanks())
        .Times(1)
        .WillOnce(Return(m_ex_enginx_banks));
    EXPECT_CALL(mockView, focusingCroppedSpectrumIDs())
        .Times(1)
        .WillOnce(Return("1"));
457
458
459
460
461
462
463
464
465

    // should not try to use these ones
    EXPECT_CALL(mockView, focusingRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingTextureRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingTextureGroupingFile()).Times(0);

    // should not get that far that it tries to get these parameters
    EXPECT_CALL(mockView, currentInstrument()).Times(0);
    EXPECT_CALL(mockView, currentCalibSettings()).Times(0);
466
467
    EXPECT_CALL(mockView, focusedOutWorkspace()).Times(0);
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0);
468
469
470
471
472
473
474
475
476
477
478
479
480

    // 1 warning pop-up to user, 0 errors
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::FocusCropped);
  }

  void test_focusCropped_withoutBanks() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // ok run number
481
482
483
484
485
486
487
488
489
    EXPECT_CALL(mockView, focusingCroppedRunNo())
        .Times(1)
        .WillOnce(Return("228061"));
    EXPECT_CALL(mockView, focusingBanks())
        .Times(1)
        .WillOnce(Return(std::vector<bool>()));
    EXPECT_CALL(mockView, focusingCroppedSpectrumIDs())
        .Times(1)
        .WillOnce(Return("1,5"));
490
491
492
493
494

    // should not try to use these ones
    EXPECT_CALL(mockView, focusingRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingTextureRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingTextureGroupingFile()).Times(0);
495
496
    EXPECT_CALL(mockView, focusedOutWorkspace()).Times(0);
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0);
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513

    // should not get that far that it tries to get these parameters
    EXPECT_CALL(mockView, currentInstrument()).Times(0);
    EXPECT_CALL(mockView, currentCalibSettings()).Times(0);

    // 1 warning pop-up to user, 0 errors
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::FocusCropped);
  }

  void test_focusCropped_withoutSpectrumIDs() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // ok run number
514
515
516
517
518
519
520
521
522
    EXPECT_CALL(mockView, focusingCroppedRunNo())
        .Times(1)
        .WillOnce(Return("228061"));
    EXPECT_CALL(mockView, focusingBanks())
        .Times(1)
        .WillOnce(Return(m_ex_enginx_banks));
    EXPECT_CALL(mockView, focusingCroppedSpectrumIDs())
        .Times(1)
        .WillOnce(Return(""));
523
524
525
526
527

    // should not try to use these ones
    EXPECT_CALL(mockView, focusingRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingTextureRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingTextureGroupingFile()).Times(0);
528
529
    EXPECT_CALL(mockView, focusedOutWorkspace()).Times(0);
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0);
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546

    // should not get that far that it tries to get these parameters
    EXPECT_CALL(mockView, currentInstrument()).Times(0);
    EXPECT_CALL(mockView, currentCalibSettings()).Times(0);

    // 1 warning pop-up to user, 0 errors
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::FocusCropped);
  }

  void test_focusTexture_withoutRunNo() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // empty run number!
547
    EXPECT_CALL(mockView, focusingTextureRunNo()).Times(1).WillOnce(Return(""));
548
549
550
    EXPECT_CALL(mockView, focusingTextureGroupingFile())
        .Times(1)
        .WillOnce(Return(""));
551
552
553
554

    // should not try to use these ones
    EXPECT_CALL(mockView, focusingRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingBanks()).Times(0);
555
556
557
558

    EXPECT_CALL(mockView, focusingCroppedRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingCroppedSpectrumIDs()).Times(0);

559
560
561
    EXPECT_CALL(mockView, focusedOutWorkspace()).Times(0);
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0);

562
563
564
565
566
567
568
569
570
571
572
573
    // 1 warning pop-up to user, 0 errors
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::FocusTexture);
  }

  void test_focusTexture_withoutFilename() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // goo run number
574
575
576
    EXPECT_CALL(mockView, focusingTextureRunNo())
        .Times(1)
        .WillOnce(Return("228061"));
577
    EXPECT_CALL(mockView, focusingBanks()).Times(0);
578
579
580
    EXPECT_CALL(mockView, focusingTextureGroupingFile())
        .Times(1)
        .WillOnce(Return(""));
581
582
583
584
585
586
587

    // should not try to use these ones
    EXPECT_CALL(mockView, focusingRunNo()).Times(0);

    EXPECT_CALL(mockView, focusingCroppedRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingCroppedSpectrumIDs()).Times(0);

588
589
590
    EXPECT_CALL(mockView, focusedOutWorkspace()).Times(0);
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0);

591
592
593
594
595
596
597
598
599
600
601
602
    // 1 warning pop-up to user, 0 errors
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::FocusTexture);
  }

  void test_focusTexture_withInexistentTextureFile() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // goo run number
603
604
605
    EXPECT_CALL(mockView, focusingTextureRunNo())
        .Times(1)
        .WillOnce(Return("228061"));
606
    // non empty but absurd csv file of detector groups
607
608
609
    EXPECT_CALL(mockView, focusingTextureGroupingFile())
        .Times(1)
        .WillOnce(Return("i_dont_exist_dont_look_for_me.csv"));
610
611
612
613

    // should not try to use these ones
    EXPECT_CALL(mockView, focusingRunNo()).Times(0);

614
615
616
    EXPECT_CALL(mockView, focusingCroppedRunNo()).Times(0);
    EXPECT_CALL(mockView, focusingCroppedSpectrumIDs()).Times(0);

617
618
619
    EXPECT_CALL(mockView, focusedOutWorkspace()).Times(0);
    EXPECT_CALL(mockView, plotFocusedSpectrum(testing::_)).Times(0);

620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
    // 1 warning pop-up to user, 0 errors
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::FocusTexture);
  }

  void test_resetFocus() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    EXPECT_CALL(mockView, resetFocus()).Times(1);

    // No errors/warnings when resetting options
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::ResetFocus);
  }

  void test_resetFocus_thenFocus() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // No errors/warnings when resetting options
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::ResetFocus);

    // empty run number!
    EXPECT_CALL(mockView, focusingRunNo()).Times(1).WillOnce(Return(""));
652
653
654
    EXPECT_CALL(mockView, focusingBanks())
        .Times(1)
        .WillOnce(Return(m_ex_enginx_banks));
655
656
657
658
659
660
661
662
663
664
665
666

    // should not get that far that it tries to get these parameters
    EXPECT_CALL(mockView, currentInstrument()).Times(0);
    EXPECT_CALL(mockView, currentCalibSettings()).Times(0);

    // Now one error shown as a warning-pop-up cause inputs and options are
    // empty
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(1);

    pres.notify(IEnggDiffractionPresenter::FocusRun);
  }

667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
  void test_preproc_event_time_bin_tmp() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // inputs from user
    EXPECT_CALL(mockView, currentPreprocRunNo()).Times(1).WillOnce(Return(""));
    EXPECT_CALL(mockView, rebinningTimeBin()).Times(1).WillOnce(Return(0));

    // No errors/warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::RebinTime);
  }

  void test_preproc_event_multiperiod_tmp() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // inputs from user
    EXPECT_CALL(mockView, currentPreprocRunNo()).Times(1).WillOnce(Return(""));
    EXPECT_CALL(mockView, rebinningNumberPeriods()).Times(1).WillOnce(Return(0));
    EXPECT_CALL(mockView, rebinningPulsesPerPeriod()).Times(1).WillOnce(Return(0));

    // No errors/warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::RebinMultiperiod);
  }
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
  void test_logMsg() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    std::vector<std::string> sv;
    sv.push_back("dummy log");
    EXPECT_CALL(mockView, logMsgs()).Times(1).WillOnce(Return(sv));

    // No errors/warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::LogMsg);
  }

712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
  void test_RBNumberChange_ok() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // as if the user has set an empty RB Number that looks correct
    EXPECT_CALL(mockView, getRBNumber()).Times(1).WillOnce(Return("RB000xxxx"));
    EXPECT_CALL(mockView, enableTabs(true)).Times(1);

    // no errors/ warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::RBNumberChange);
  }

  void test_RBNumberChange_empty() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // as if the user has set an empty RB Number
    EXPECT_CALL(mockView, getRBNumber()).Times(1).WillOnce(Return(""));
    EXPECT_CALL(mockView, enableTabs(false)).Times(1);

    // no errors/ warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::RBNumberChange);
  }

742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
  void test_instChange() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    // 1 error, no warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(1);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::InstrumentChange);
  }

  void test_shutDown() {
    testing::NiceMock<MockEnggDiffractionView> mockView;
    MantidQt::CustomInterfaces::EnggDiffractionPresenter pres(&mockView);

    EXPECT_CALL(mockView, saveSettings()).Times(1);
    // No errors, no warnings
    EXPECT_CALL(mockView, userError(testing::_, testing::_)).Times(0);
    EXPECT_CALL(mockView, userWarning(testing::_, testing::_)).Times(0);

    pres.notify(IEnggDiffractionPresenter::ShutDown);
  }

private:
  boost::scoped_ptr<testing::NiceMock<MockEnggDiffractionView>> m_view;
  boost::scoped_ptr<MantidQt::CustomInterfaces::EnggDiffractionPresenter>
      m_presenter;
769
770

  std::vector<bool> m_ex_enginx_banks;
771
772
773
};

#endif // MANTID_CUSTOMINTERFACES_ENGGDIFFRACTIONPRESENTERTEST_H