|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include <qtest.h> |
|
42 #include <QSignalSpy> |
|
43 #include <QTimer> |
|
44 #include <QHostAddress> |
|
45 #include <QDebug> |
|
46 #include <QThread> |
|
47 |
|
48 #include <QtDeclarative/qdeclarativeengine.h> |
|
49 |
|
50 #include <private/qdeclarativedebug_p.h> |
|
51 #include <private/qdeclarativeenginedebug_p.h> |
|
52 #include <private/qdeclarativedebugclient_p.h> |
|
53 #include <private/qdeclarativedebugservice_p.h> |
|
54 |
|
55 #include "../../../shared/util.h" |
|
56 #include "../shared/debugutil_p.h" |
|
57 |
|
58 class tst_QDeclarativeDebugClient : public QObject |
|
59 { |
|
60 Q_OBJECT |
|
61 |
|
62 private: |
|
63 QDeclarativeDebugConnection *m_conn; |
|
64 |
|
65 private slots: |
|
66 void initTestCase(); |
|
67 |
|
68 void name(); |
|
69 void isEnabled(); |
|
70 void setEnabled(); |
|
71 void isConnected(); |
|
72 void sendMessage(); |
|
73 }; |
|
74 |
|
75 void tst_QDeclarativeDebugClient::initTestCase() |
|
76 { |
|
77 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 3770..."); |
|
78 |
|
79 qputenv("QML_DEBUG_SERVER_PORT", "3770"); |
|
80 new QDeclarativeEngine(this); |
|
81 |
|
82 m_conn = new QDeclarativeDebugConnection(this); |
|
83 m_conn->connectToHost("127.0.0.1", 3770); |
|
84 |
|
85 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established"); |
|
86 bool ok = m_conn->waitForConnected(); |
|
87 Q_ASSERT(ok); |
|
88 |
|
89 QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient()); |
|
90 } |
|
91 |
|
92 void tst_QDeclarativeDebugClient::name() |
|
93 { |
|
94 QString name = "tst_QDeclarativeDebugClient::name()"; |
|
95 |
|
96 QDeclarativeDebugClient client(name, m_conn); |
|
97 QCOMPARE(client.name(), name); |
|
98 } |
|
99 |
|
100 void tst_QDeclarativeDebugClient::isEnabled() |
|
101 { |
|
102 QDeclarativeDebugClient client("tst_QDeclarativeDebugClient::isEnabled()", m_conn); |
|
103 QCOMPARE(client.isEnabled(), false); |
|
104 } |
|
105 |
|
106 void tst_QDeclarativeDebugClient::setEnabled() |
|
107 { |
|
108 QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::setEnabled()"); |
|
109 QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::setEnabled()", m_conn); |
|
110 |
|
111 QCOMPARE(service.isEnabled(), false); |
|
112 |
|
113 client.setEnabled(true); |
|
114 QCOMPARE(client.isEnabled(), true); |
|
115 QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); |
|
116 QCOMPARE(service.isEnabled(), true); |
|
117 |
|
118 client.setEnabled(false); |
|
119 QCOMPARE(client.isEnabled(), false); |
|
120 QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged())); |
|
121 QCOMPARE(service.isEnabled(), false); |
|
122 } |
|
123 |
|
124 void tst_QDeclarativeDebugClient::isConnected() |
|
125 { |
|
126 QDeclarativeDebugClient client1("tst_QDeclarativeDebugClient::isConnected() A", m_conn); |
|
127 QCOMPARE(client1.isConnected(), true); |
|
128 |
|
129 QDeclarativeDebugConnection conn; |
|
130 QDeclarativeDebugClient client2("tst_QDeclarativeDebugClient::isConnected() B", &conn); |
|
131 QCOMPARE(client2.isConnected(), false); |
|
132 |
|
133 QDeclarativeDebugClient client3("tst_QDeclarativeDebugClient::isConnected() C", 0); |
|
134 QCOMPARE(client3.isConnected(), false); |
|
135 |
|
136 // duplicate plugin name |
|
137 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugClient: Conflicting plugin name \"tst_QDeclarativeDebugClient::isConnected() A\" "); |
|
138 QDeclarativeDebugClient client4("tst_QDeclarativeDebugClient::isConnected() A", m_conn); |
|
139 QCOMPARE(client4.isConnected(), false); |
|
140 } |
|
141 |
|
142 void tst_QDeclarativeDebugClient::sendMessage() |
|
143 { |
|
144 QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::sendMessage()"); |
|
145 QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::sendMessage()", m_conn); |
|
146 |
|
147 QByteArray msg = "hello!"; |
|
148 |
|
149 client.sendMessage(msg); |
|
150 QByteArray resp = client.waitForResponse(); |
|
151 QCOMPARE(resp, msg); |
|
152 } |
|
153 |
|
154 QTEST_MAIN(tst_QDeclarativeDebugClient) |
|
155 |
|
156 #include "tst_qdeclarativedebugclient.moc" |
|
157 |