summaryrefslogtreecommitdiffstats
path: root/src/testlib/qabstracttestlogger_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/testlib/qabstracttestlogger_p.h')
-rw-r--r--src/testlib/qabstracttestlogger_p.h52
1 files changed, 42 insertions, 10 deletions
diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h
index 588184e..1834086 100644
--- a/src/testlib/qabstracttestlogger_p.h
+++ b/src/testlib/qabstracttestlogger_p.h
@@ -101,27 +101,26 @@ public:
struct QTestCharBuffer
{
- inline QTestCharBuffer()
- : buf(0)
- {}
+ enum { InitialSize = 512 };
- inline ~QTestCharBuffer()
+ inline QTestCharBuffer()
+ : _size(InitialSize), buf(staticBuf)
{
- delete[] buf;
- buf = 0;
+ staticBuf[0] = '\0';
}
- inline operator void*()
+ inline ~QTestCharBuffer()
{
- return buf;
+ if (buf != staticBuf)
+ qFree(buf);
}
- inline operator char*()
+ inline char *data()
{
return buf;
}
- inline operator char**()
+ inline char **buffer()
{
return &buf;
}
@@ -131,10 +130,43 @@ struct QTestCharBuffer
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