blob: cfd37fdb986966a61e6f2ded1901961f412619b0 (
plain)
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
43
44
45
46
47
48
49
50
51
|
#include "qt_tstfrm/test_main_loop.hpp"
#include <QtCore/QTimer>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include "base/scope_guard.hpp"
#include "std/cstring.hpp"
namespace
{
class MyWidget : public QWidget
{
public:
MyWidget(TRednerFn const & fn)
: m_fn(fn)
{
}
protected:
void paintEvent(QPaintEvent * e)
{
m_fn(this);
}
private:
TRednerFn m_fn;
};
} // namespace
void RunTestLoop(char const * testName, TRednerFn const & fn, bool autoExit)
{
char * buf = (char *)malloc(strlen(testName) + 1);
MY_SCOPE_GUARD(argvFreeFun, [&buf](){ free(buf); });
strcpy(buf, testName);
int argc = 1;
QApplication app(argc, &buf);
if (autoExit)
QTimer::singleShot(3000, &app, SLOT(quit()));
MyWidget * widget = new MyWidget(fn);
widget->setWindowTitle(testName);
widget->show();
app.exec();
delete widget;
}
|