0b3b8ec2a638c9c51b0f16bca0d176063b7f3bd9
[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     void setEnvironment(const QStringList &environment);
91
92     void start(const QStringList &arguments);
93     bool waitForSessionStart();
94
95     QString output() const;
96     void stop();
97
98 private slots:
99     void timeout();
100     void processAppOutput();
101
102 private:
103     QString m_executable;
104     QProcess m_process;
105     QString m_outputBuffer;
106     QString m_output;
107     QTimer m_timer;
108     QEventLoop m_eventLoop;
109     QMutex m_mutex;
110     bool m_started;
111     QStringList m_environment;
112 };
113
114 #endif // DEBUGUTIL_H