Debugger: Improve output of autotests
[profile/ivi/qtdeclarative.git] / tests / auto / qml / debugger / shared / debugutil_p.h
1
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef DEBUGUTIL_H
44 #define DEBUGUTIL_H
45
46 #include <QEventLoop>
47 #include <QTimer>
48 #include <QThread>
49 #include <QTest>
50 #include <QProcess>
51 #include <QMutex>
52
53 #include <QtQml/qqmlengine.h>
54
55 #include "qqmldebugclient.h"
56
57 class QQmlDebugTest
58 {
59 public:
60     static bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000);
61 };
62
63 class QQmlDebugTestClient : public QQmlDebugClient
64 {
65     Q_OBJECT
66 public:
67     QQmlDebugTestClient(const QString &s, QQmlDebugConnection *c);
68
69     QByteArray waitForResponse();
70
71 signals:
72     void stateHasChanged();
73     void serverMessage(const QByteArray &);
74
75 protected:
76     virtual void stateChanged(State state);
77     virtual void messageReceived(const QByteArray &ba);
78
79 private:
80     QByteArray lastMsg;
81 };
82
83 class QQmlDebugProcess : public QObject
84 {
85     Q_OBJECT
86 public:
87     QQmlDebugProcess(const QString &executable);
88     ~QQmlDebugProcess();
89
90     QString state();
91
92     void setEnvironment(const QStringList &environment);
93
94     void start(const QStringList &arguments);
95     bool waitForSessionStart();
96
97     QString output() const;
98     void stop();
99
100 private slots:
101     void timeout();
102     void processAppOutput();
103
104 private:
105     QString m_executable;
106     QProcess m_process;
107     QString m_outputBuffer;
108     QString m_output;
109     QTimer m_timer;
110     QEventLoop m_eventLoop;
111     QMutex m_mutex;
112     bool m_started;
113     QStringList m_environment;
114 };
115
116 #endif // DEBUGUTIL_H