mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Add COMPARE_DATA to QTestExtensions
This commit is contained in:
parent
ad61c3db41
commit
07e3cf1348
2 changed files with 25 additions and 1 deletions
|
@ -116,7 +116,6 @@ protected:
|
|||
HifiSockAddr _senderSockAddr; // sender address for packet (only used on receiving end)
|
||||
};
|
||||
|
||||
|
||||
template<typename T> qint64 Packet::peekPrimitive(T* data) {
|
||||
return QIODevice::peek(reinterpret_cast<char*>(data), sizeof(T));
|
||||
}
|
||||
|
|
|
@ -251,6 +251,31 @@ do { \
|
|||
|
||||
#endif
|
||||
|
||||
#define QCOMPARE_WITH_EXPR(actual, expected, testExpr) \
|
||||
do { \
|
||||
if (!(testExpr)) { \
|
||||
QTest_failWithMessage("Compared values are not the same", (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
struct ByteData {
|
||||
ByteData (const char* data, size_t length)
|
||||
: data(data), length(length) {}
|
||||
const char* data;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
QTextStream & operator << (QTextStream& stream, const ByteData & wrapper) {
|
||||
// Print bytes as hex
|
||||
stream << QByteArray::fromRawData(wrapper.data, wrapper.length).toHex();
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
bool compareData (const char* data, const char* expectedData, size_t length) {
|
||||
return memcmp(data, expectedData, length) == 0;
|
||||
}
|
||||
|
||||
#define COMPARE_DATA(actual, expected, length) \
|
||||
QCOMPARE_WITH_EXPR((ByteData ( actual, length )), (ByteData ( expected, length )), compareData(actual, expected, length))
|
||||
|
|
Loading…
Reference in a new issue