Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativeconsole / tst_qdeclarativeconsole.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include <qtest.h>
42 #include <QDebug>
43 #include <QDeclarativeEngine>
44 #include <QDeclarativeComponent>
45 #include "../../shared/util.h"
46
47 class tst_qdeclarativeconsole : public QDeclarativeDataTest
48 {
49     Q_OBJECT
50 public:
51     tst_qdeclarativeconsole() {}
52
53 private slots:
54     void logging();
55     void tracing();
56     void profiling();
57     void assert();
58     void exception();
59
60 private:
61     QDeclarativeEngine engine;
62 };
63
64 void tst_qdeclarativeconsole::logging()
65 {
66     QUrl testUrl = testFileUrl("logging.qml");
67
68     QTest::ignoreMessage(QtDebugMsg, "console.debug");
69     QTest::ignoreMessage(QtDebugMsg, "console.log");
70     QTest::ignoreMessage(QtDebugMsg, "console.info");
71     QTest::ignoreMessage(QtWarningMsg, "console.warn");
72     QTest::ignoreMessage(QtCriticalMsg, "console.error");
73
74     QTest::ignoreMessage(QtDebugMsg, "console.count: 1");
75     QTest::ignoreMessage(QtDebugMsg, ": 1");
76     QTest::ignoreMessage(QtDebugMsg, "console.count: 2");
77     QTest::ignoreMessage(QtDebugMsg, ": 2");
78
79     QTest::ignoreMessage(QtDebugMsg, "[1,2]");
80     QTest::ignoreMessage(QtDebugMsg, "Object");
81     QTest::ignoreMessage(QtDebugMsg, "undefined");
82     QTest::ignoreMessage(QtDebugMsg, "12");
83     QTest::ignoreMessage(QtDebugMsg, "function () { return 5;}");
84     QTest::ignoreMessage(QtDebugMsg, "true");
85     QTest::ignoreMessage(QtDebugMsg, "Object");
86     QTest::ignoreMessage(QtDebugMsg, "Object");
87     QTest::ignoreMessage(QtDebugMsg, "1 pong! Object");
88     QTest::ignoreMessage(QtDebugMsg, "1 [ping,pong] Object 2");
89
90     QDeclarativeComponent component(&engine, testUrl);
91     QObject *object = component.create();
92     QVERIFY(object != 0);
93     delete object;
94 }
95
96 void tst_qdeclarativeconsole::tracing()
97 {
98     QUrl testUrl = testFileUrl("tracing.qml");
99
100     QString trace1 = QString::fromLatin1("tracing (%1:%2:%3)\n").arg(testUrl.toString()).arg(50).arg(17);
101     QString trace2 = QString::fromLatin1("onCompleted (%1:%2:%3)\n").arg(testUrl.toString()).arg(54).arg(9);
102     QTest::ignoreMessage(QtDebugMsg, qPrintable(trace1));
103     QTest::ignoreMessage(QtDebugMsg, qPrintable(trace2));
104
105     QDeclarativeComponent component(&engine, testUrl);
106     QObject *object = component.create();
107     QVERIFY(object != 0);
108     delete object;
109 }
110
111 void tst_qdeclarativeconsole::profiling()
112 {
113     QUrl testUrl = testFileUrl("profiling.qml");
114
115     // profiling()
116     QTest::ignoreMessage(QtDebugMsg, "Profiling started.");
117     QTest::ignoreMessage(QtDebugMsg, "Profiling ended.");
118
119     QDeclarativeComponent component(&engine, testUrl);
120     QObject *object = component.create();
121     QVERIFY(object != 0);
122     delete object;
123 }
124
125 void tst_qdeclarativeconsole::assert()
126 {
127     QUrl testUrl = testFileUrl("assert.qml");
128
129     // assert()
130     QTest::ignoreMessage(QtCriticalMsg, "This will fail");
131     QTest::ignoreMessage(QtCriticalMsg, "This will fail too");
132     QString trace1 = QString::fromLatin1("onCompleted (%1:%2:%3)\n").arg(testUrl.toString()).arg(54).arg(17);
133     QString trace2 = QString::fromLatin1("onCompleted (%1:%2:%3)\n").arg(testUrl.toString()).arg(59).arg(9);
134     QString trace3 = QString::fromLatin1("assertFail (%1:%2:%3)\n").arg(testUrl.toString()).arg(47).arg(17);
135     QTest::ignoreMessage(QtDebugMsg, qPrintable(trace1));
136     QTest::ignoreMessage(QtDebugMsg, qPrintable(trace2));
137     QTest::ignoreMessage(QtDebugMsg, qPrintable(trace3));
138
139     QDeclarativeComponent component(&engine, testUrl);
140     QObject *object = component.create();
141     QVERIFY(object != 0);
142     delete object;
143 }
144
145 void tst_qdeclarativeconsole::exception()
146 {
147     QUrl testUrl = testFileUrl("exception.qml");
148
149     // exception()
150     QTest::ignoreMessage(QtCriticalMsg, "Exception 1");
151     QTest::ignoreMessage(QtCriticalMsg, "Exception 2");
152     QString trace1 = QString::fromLatin1("onCompleted (%1:%2:%3)\n").arg(testUrl.toString()).arg(51).arg(21);
153     QString trace2 = QString::fromLatin1("onCompleted (%1:%2:%3)\n").arg(testUrl.toString()).arg(56).arg(9);
154     QString trace3 = QString::fromLatin1("exceptionFail (%1:%2:%3)\n").arg(testUrl.toString()).arg(46).arg(17);
155     QTest::ignoreMessage(QtDebugMsg, qPrintable(trace1));
156     QTest::ignoreMessage(QtDebugMsg, qPrintable(trace2));
157     QTest::ignoreMessage(QtDebugMsg, qPrintable(trace3));
158
159     QDeclarativeComponent component(&engine, testUrl);
160     QObject *object = component.create();
161     QVERIFY(object != 0);
162     delete object;
163 }
164
165 QTEST_MAIN(tst_qdeclarativeconsole)
166
167 #include "tst_qdeclarativeconsole.moc"