tests/auto/declarative/qdeclarativedebugservice/tst_qdeclarativedebugservice.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
       
     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 
       
    59 class tst_QDeclarativeDebugService : public QObject
       
    60 {
       
    61     Q_OBJECT
       
    62 private:
       
    63     QDeclarativeDebugConnection *m_conn;
       
    64 
       
    65 private slots:
       
    66     void initTestCase();
       
    67 
       
    68     void name();
       
    69     void isEnabled();
       
    70     void enabledChanged();
       
    71     void sendMessage();
       
    72     void idForObject();
       
    73     void objectForId();
       
    74     void objectToString();
       
    75 };
       
    76 
       
    77 void tst_QDeclarativeDebugService::initTestCase()
       
    78 {
       
    79     QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 3769...");
       
    80     qputenv("QML_DEBUG_SERVER_PORT", "3769");
       
    81     new QDeclarativeEngine(this);
       
    82 
       
    83     m_conn = new QDeclarativeDebugConnection(this);
       
    84     m_conn->connectToHost("127.0.0.1", 3769);
       
    85 
       
    86     QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
       
    87     bool ok = m_conn->waitForConnected();
       
    88     Q_ASSERT(ok);
       
    89 
       
    90     QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());
       
    91 }
       
    92 
       
    93 void tst_QDeclarativeDebugService::name()
       
    94 {
       
    95     QString name = "tst_QDeclarativeDebugService::name()";
       
    96 
       
    97     QDeclarativeDebugService service(name);
       
    98     QCOMPARE(service.name(), name);
       
    99 }
       
   100 
       
   101 void tst_QDeclarativeDebugService::isEnabled()
       
   102 {
       
   103     QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::isEnabled()", m_conn);
       
   104     QCOMPARE(service.isEnabled(), false);
       
   105 
       
   106     QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::isEnabled()", m_conn);
       
   107     client.setEnabled(true);
       
   108     QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged()));
       
   109     QCOMPARE(service.isEnabled(), true);
       
   110 
       
   111     QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::isEnabled()\" ");
       
   112     QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::isEnabled()", m_conn);
       
   113     QCOMPARE(duplicate.isEnabled(), false);
       
   114 }
       
   115 
       
   116 void tst_QDeclarativeDebugService::enabledChanged()
       
   117 {
       
   118     QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::enabledChanged()");
       
   119     QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::enabledChanged()", m_conn);
       
   120 
       
   121     QCOMPARE(service.enabled, false);
       
   122 
       
   123     client.setEnabled(true);
       
   124     QDeclarativeDebugTest::waitForSignal(&service, SIGNAL(enabledStateChanged()));
       
   125     QCOMPARE(service.enabled, true);
       
   126 }
       
   127 
       
   128 void tst_QDeclarativeDebugService::sendMessage()
       
   129 {
       
   130     QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::sendMessage()");
       
   131     QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::sendMessage()", m_conn);
       
   132 
       
   133     QByteArray msg = "hello!";
       
   134 
       
   135     client.sendMessage(msg);
       
   136     QByteArray resp = client.waitForResponse();
       
   137     QCOMPARE(resp, msg);
       
   138 }
       
   139 
       
   140 void tst_QDeclarativeDebugService::idForObject()
       
   141 {
       
   142     QCOMPARE(QDeclarativeDebugService::idForObject(0), -1);
       
   143 
       
   144     QObject *objA = new QObject;
       
   145 
       
   146     int idA = QDeclarativeDebugService::idForObject(objA);
       
   147     QVERIFY(idA >= 0);
       
   148     QCOMPARE(QDeclarativeDebugService::objectForId(idA), objA);
       
   149 
       
   150     int idAA = QDeclarativeDebugService::idForObject(objA);
       
   151     QCOMPARE(idAA, idA);
       
   152 
       
   153     QObject *objB = new QObject;
       
   154     int idB = QDeclarativeDebugService::idForObject(objB);
       
   155     QVERIFY(idB != idA);
       
   156     QCOMPARE(QDeclarativeDebugService::objectForId(idB), objB);
       
   157 
       
   158     delete objA;
       
   159     delete objB;
       
   160 }
       
   161 
       
   162 void tst_QDeclarativeDebugService::objectForId()
       
   163 {
       
   164     QCOMPARE(QDeclarativeDebugService::objectForId(-1), static_cast<QObject*>(0));
       
   165     QCOMPARE(QDeclarativeDebugService::objectForId(1), static_cast<QObject*>(0));
       
   166 
       
   167     QObject *obj = new QObject;
       
   168     int id = QDeclarativeDebugService::idForObject(obj);
       
   169     QCOMPARE(QDeclarativeDebugService::objectForId(id), obj);
       
   170 
       
   171     delete obj;
       
   172     QCOMPARE(QDeclarativeDebugService::objectForId(id), static_cast<QObject*>(0));
       
   173 }
       
   174 
       
   175 void tst_QDeclarativeDebugService::objectToString()
       
   176 {
       
   177     QCOMPARE(QDeclarativeDebugService::objectToString(0), QString("NULL"));
       
   178 
       
   179     QObject *obj = new QObject;
       
   180     QCOMPARE(QDeclarativeDebugService::objectToString(obj), QString("QObject: <unnamed>"));
       
   181 
       
   182     obj->setObjectName("Hello");
       
   183     QCOMPARE(QDeclarativeDebugService::objectToString(obj), QString("QObject: Hello"));
       
   184     delete obj;
       
   185 }
       
   186 
       
   187 QTEST_MAIN(tst_QDeclarativeDebugService)
       
   188 
       
   189 #include "tst_qdeclarativedebugservice.moc"