[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[651] | 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtTest module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 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 | **
|
---|
[561] | 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.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #ifndef QABSTRACTTESTLOGGER_P_H
|
---|
| 43 | #define QABSTRACTTESTLOGGER_P_H
|
---|
| 44 |
|
---|
| 45 | //
|
---|
| 46 | // W A R N I N G
|
---|
| 47 | // -------------
|
---|
| 48 | //
|
---|
| 49 | // This file is not part of the Qt API. It exists purely as an
|
---|
| 50 | // implementation detail. This header file may change from version to
|
---|
| 51 | // version without notice, or even be removed.
|
---|
| 52 | //
|
---|
| 53 | // We mean it.
|
---|
| 54 | //
|
---|
| 55 |
|
---|
| 56 | #include <qglobal.h>
|
---|
| 57 |
|
---|
| 58 | QT_BEGIN_NAMESPACE
|
---|
| 59 |
|
---|
| 60 | class QBenchmarkResult;
|
---|
| 61 |
|
---|
| 62 | class QAbstractTestLogger
|
---|
| 63 | {
|
---|
| 64 | public:
|
---|
| 65 | enum IncidentTypes {
|
---|
| 66 | Pass,
|
---|
| 67 | XFail,
|
---|
| 68 | Fail,
|
---|
| 69 | XPass
|
---|
| 70 | };
|
---|
| 71 |
|
---|
| 72 | enum MessageTypes {
|
---|
| 73 | Warn,
|
---|
| 74 | QWarning,
|
---|
| 75 | QDebug,
|
---|
| 76 | QSystem,
|
---|
| 77 | QFatal,
|
---|
| 78 | Skip,
|
---|
| 79 | Info
|
---|
| 80 | };
|
---|
| 81 |
|
---|
| 82 | QAbstractTestLogger() {}
|
---|
| 83 | virtual ~QAbstractTestLogger() {}
|
---|
| 84 |
|
---|
| 85 | virtual void startLogging();
|
---|
| 86 | virtual void stopLogging();
|
---|
| 87 |
|
---|
| 88 | virtual void enterTestFunction(const char *function) = 0;
|
---|
| 89 | virtual void leaveTestFunction() = 0;
|
---|
| 90 |
|
---|
| 91 | virtual void addIncident(IncidentTypes type, const char *description,
|
---|
| 92 | const char *file = 0, int line = 0) = 0;
|
---|
| 93 | virtual void addBenchmarkResult(const QBenchmarkResult &result) = 0;
|
---|
| 94 |
|
---|
| 95 | virtual void addMessage(MessageTypes type, const char *message,
|
---|
| 96 | const char *file = 0, int line = 0) = 0;
|
---|
| 97 |
|
---|
| 98 | static void outputString(const char *msg);
|
---|
| 99 | static bool isTtyOutput();
|
---|
| 100 | };
|
---|
| 101 |
|
---|
[561] | 102 | struct QTestCharBuffer
|
---|
| 103 | {
|
---|
| 104 | enum { InitialSize = 512 };
|
---|
| 105 |
|
---|
| 106 | inline QTestCharBuffer()
|
---|
| 107 | : _size(InitialSize), buf(staticBuf)
|
---|
| 108 | {
|
---|
| 109 | staticBuf[0] = '\0';
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | inline ~QTestCharBuffer()
|
---|
| 113 | {
|
---|
| 114 | if (buf != staticBuf)
|
---|
| 115 | qFree(buf);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | inline char *data()
|
---|
| 119 | {
|
---|
| 120 | return buf;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | inline char **buffer()
|
---|
| 124 | {
|
---|
| 125 | return &buf;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | inline const char* constData() const
|
---|
| 129 | {
|
---|
| 130 | return buf;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | inline int size() const
|
---|
| 134 | {
|
---|
| 135 | return _size;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | inline bool reset(int newSize)
|
---|
| 139 | {
|
---|
| 140 | char *newBuf = 0;
|
---|
| 141 | if (buf == staticBuf) {
|
---|
| 142 | // if we point to our internal buffer, we need to malloc first
|
---|
| 143 | newBuf = reinterpret_cast<char *>(qMalloc(newSize));
|
---|
| 144 | } else {
|
---|
| 145 | // if we already malloc'ed, just realloc
|
---|
| 146 | newBuf = reinterpret_cast<char *>(qRealloc(buf, newSize));
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | // if the allocation went wrong (newBuf == 0), we leave the object as is
|
---|
| 150 | if (!newBuf)
|
---|
| 151 | return false;
|
---|
| 152 |
|
---|
| 153 | _size = newSize;
|
---|
| 154 | buf = newBuf;
|
---|
| 155 | return true;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | private:
|
---|
| 159 | int _size;
|
---|
| 160 | char* buf;
|
---|
| 161 | char staticBuf[InitialSize];
|
---|
| 162 | };
|
---|
| 163 |
|
---|
| 164 | namespace QTest
|
---|
| 165 | {
|
---|
| 166 | int qt_asprintf(QTestCharBuffer *buf, const char *format, ...);
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 |
|
---|
[2] | 170 | QT_END_NAMESPACE
|
---|
| 171 |
|
---|
| 172 | #endif
|
---|