diff options
Diffstat (limited to 'src/testlib/qabstracttestlogger_p.h')
-rw-r--r-- | src/testlib/qabstracttestlogger_p.h | 76 |
1 files changed, 72 insertions, 4 deletions
diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h index 93b4b18..cc4e509 100644 --- a/src/testlib/qabstracttestlogger_p.h +++ b/src/testlib/qabstracttestlogger_p.h @@ -1,7 +1,6 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtTest module of the Qt Toolkit. @@ -21,9 +20,10 @@ ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this +** package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. @@ -99,6 +99,74 @@ public: static bool isTtyOutput(); }; +struct QTestCharBuffer +{ + enum { InitialSize = 512 }; + + inline QTestCharBuffer() + : _size(InitialSize), buf(staticBuf) + { + staticBuf[0] = '\0'; + } + + inline ~QTestCharBuffer() + { + if (buf != staticBuf) + qFree(buf); + } + + inline char *data() + { + return buf; + } + + inline char **buffer() + { + return &buf; + } + + inline const char* constData() const + { + return buf; + } + + inline int size() const + { + return _size; + } + + inline bool reset(int newSize) + { + char *newBuf = 0; + if (buf == staticBuf) { + // if we point to our internal buffer, we need to malloc first + newBuf = reinterpret_cast<char *>(qMalloc(newSize)); + } else { + // if we already malloc'ed, just realloc + newBuf = reinterpret_cast<char *>(qRealloc(buf, newSize)); + } + + // if the allocation went wrong (newBuf == 0), we leave the object as is + if (!newBuf) + return false; + + _size = newSize; + buf = newBuf; + return true; + } + +private: + int _size; + char* buf; + char staticBuf[InitialSize]; +}; + +namespace QTest +{ + int qt_asprintf(QTestCharBuffer *buf, const char *format, ...); +} + + QT_END_NAMESPACE #endif |