1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Chris Bielow $
25
// $Authors: Chris Bielow $
26
// --------------------------------------------------------------------------
29
#include <QtTest/QtTest>
34
#include <OpenMS/VISUAL/APPLICATIONS/TOPPViewBase.h>
35
#include <OpenMS/SYSTEM/File.h>
36
#include <OpenMS/VISUAL/EnhancedTabBar.h>
45
@todo write a proper GUI base class for the scheduler below (Chris)
47
@todo document schedule for winXP
50
class TestTOPPView: public QObject
55
@brief Store information on timed keyboard input events
57
Store the time offset, the key sequence and the expected window title.
62
ScheduleInfo():delay(0){};
63
ScheduleInfo(QString p_keys, QString p_title, int p_delay)
69
QString keys; //< key sequence
70
QString title;//< expected window title
71
int delay; //< delay in ms when event is fired off
76
@brief Slot that tries to process the current event queue for modal dialogs until its empty.
78
Slot that tries to process the current event queue for modal dialogs until its empty.
79
The function will repeatedly invoke itself until the queue is empty, to allow other
80
incoming events (e.g. loading a file) to be processed in between two scheduled dialogs.
82
void simulateClick_();
89
@brief Schedule a keyboard input using a QTimer signal to direct input to a modal window.
91
Modal windows have their own event queue and once launched will halt the
92
execution of the test script until closed. This implies one cannot simply direct keyboard
93
input to them. To do that we pre-schedule the input in the main event loop
94
using a timer. The keyboard input sequence @p key_sequence and a subsequent 'return' key press
95
is then issued when the time out occurs, given that the current window has the correct
96
@p title! Otherwise the event is rescheduled until the title is correct.
97
The @p delay then the timer pops is relative to the last timed events successfull completion.
99
void scheduleModalWidget_(const QString& key_sequence, const QString& title, const int delay=100);
102
@brief Waits until the scheduled event queue is emtpy
104
Waits until the scheduled event queue is emtpy.
106
void waitForModalWidget(const int max_wait, const String& line);
108
/// event queue for modal/popup dialogs
109
QQueue<ScheduleInfo> modal_key_sequence_;
114
void TestTOPPView::scheduleModalWidget_(const QString& key_sequence, const QString& title, const int delay)
116
modal_key_sequence_.enqueue(ScheduleInfo(key_sequence, title, delay));
117
std::cerr << "scheduled for window " << title.toStdString() << "\n";
118
if (modal_key_sequence_.size()==1) // only schedule if this is the first entry
120
QTimer::singleShot(delay, this, SLOT(simulateClick_()));
124
void TestTOPPView::waitForModalWidget(const int max_wait, const String& line)
126
// test if accumulated scheduled time is less than max_wait
127
int min_required_time = 0;
128
foreach(ScheduleInfo i, modal_key_sequence_)
130
min_required_time+=i.delay;
132
if (min_required_time > max_wait)
134
QFAIL ( String("Test is bound to fail due to a time restriction in line " + line + ". Please rethink!").c_str());
140
while (!modal_key_sequence_.isEmpty () && max_wait > t.elapsed())
145
if (!modal_key_sequence_.isEmpty ())
147
QWARN ( String("Modal dialogs timed out in line " + line + ". The following tests will most likely fail.").c_str());
148
modal_key_sequence_.clear();
153
void TestTOPPView::simulateClick_()
155
if (!modal_key_sequence_.isEmpty ())
157
ScheduleInfo entry = modal_key_sequence_.head();
158
std::cerr << "processing entry: '" << entry.keys.toStdString() << "' with dialog title '" << entry.title.toStdString() << "'\n";
160
// search for a window
161
QWidget * dialog = QApplication::activeModalWidget();
162
if (!dialog) dialog = QApplication::activePopupWidget();
163
if (!dialog) dialog = QApplication::activeWindow();
165
if (!dialog || (dialog->windowTitle() != entry.title))
167
std::cerr << "item not found rescheduling...\n";
168
QTimer::singleShot(100, this, SLOT(simulateClick_()));
171
QTest::keyClicks(0,entry.keys,Qt::NoModifier,20);
172
QTest::keyClick(0,Qt::Key_Return,Qt::NoModifier,20);
173
QApplication::processEvents();
176
modal_key_sequence_.dequeue();
179
if (!modal_key_sequence_.isEmpty ())
181
std::cerr << "Q not empty... rescheduling...\n";
182
QTimer::singleShot(modal_key_sequence_.head().delay, this, SLOT(simulateClick_()));
186
void TestTOPPView::testGui()
190
QApplication::processEvents();
194
#if 1 //def __APPLE__ // MAC OS does not support entering a filename via keyboard in the file-open menu
195
tv.addDataFile(File::getOpenMSDataPath() + "/examples/peakpicker_tutorial_1.mzML", false, false);
196
QCOMPARE(tv.tab_bar_->tabText(tv.tab_bar_->currentIndex()), QString("peakpicker_tutorial_1.mzML"));
198
scheduleModalWidget_("peakpicker_tutorial_1.mzML", "Open file(s)",1000); // Open File dialog
199
scheduleModalWidget_("", "Open data options for peakpicker_tutorial_1.mzML",1000); // layer data options dialog
201
QTest::keyClicks(&tv,"f", Qt::AltModifier);
202
QApplication::processEvents();
203
// before we open the File-Open Dialog, we need to schedule the planned keyboard input
204
// as this dialog is modal and won't return.
205
// launch the modal widget
206
QTest::keyClicks(0,"e");
207
QApplication::processEvents();
208
waitForModalWidget(15000, __LINE__);
211
// compare the name of the opened tab
212
QCOMPARE(tv.tab_bar_->tabText(tv.tab_bar_->currentIndex()), QString("peakpicker_tutorial_1.mzML"));
216
} // Namespace OpenMS
218
using namespace OpenMS; // this is required to avoid linker errors on Windows
220
QTEST_MAIN(TestTOPPView) // expands to a simple main() method that runs all the test functions
221
#include <../source/TEST/GUI/moc_TOPPView_test.cxx> // for Qt's introspection