File: testutil.cpp

package info (click to toggle)
texstudio 2.8.4%2Bdebian-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 39,108 kB
  • ctags: 13,390
  • sloc: cpp: 84,770; xml: 10,109; ansic: 6,865; sh: 150; makefile: 82
file content (42 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef QT_NO_DEBUG
#include "testutil.h"
namespace QTest{
MessageBoxCloser* curCloser=0;
MessageBoxCloser::MessageBoxCloser(bool mustExists, QMessageBox::StandardButton button):QObject(0), m_mustExists(mustExists), m_button(button){
	if (button!=QMessageBox::Ok && button!=QMessageBox::Cancel && button!=QMessageBox::NoButton && button!=QMessageBox::Yes)
		QVERIFY2(false, "invalid button for messagebox closing");
	QTimer::singleShot(1, this, SLOT(closeNow()));
}

void MessageBoxCloser::closeNow(){
	deleteLater();
	QWidget* messageWindow = QApplication::activeModalWidget();
	if (!messageWindow) 
		foreach (QWidget *widget, QApplication::topLevelWidgets()) 
			if (widget->isModal())
				messageWindow=widget;
	if (!messageWindow) {
		QVERIFY2(!m_mustExists, "messagebox doesn't exists");
		return; //keyClick crashes (assert false)  if it can't find a window
	}
	switch (m_button) {
		case QMessageBox::Ok: case QMessageBox::Yes:
			QTest::keyClick(messageWindow, Qt::Key_Return);
			break;
		default:
			QTest::keyClick(messageWindow, Qt::Key_Escape);
			break;
	}	
	curCloser=0;
}
void closeMessageBoxLater(bool mustExists, QMessageBox::StandardButton button){
	if (curCloser) QWARN("multiple closing calls");
	curCloser=new MessageBoxCloser(mustExists, button);
}
void messageBoxShouldBeClose(){
	QVERIFY2(!curCloser, "MessageBox couldn't be closed");
}
}
#endif