MsgPackStream QString and const char * added

Qt types: QPoint, QSize, QRect implemented using MsgPackStream
MsgPackStream QString tests added
This commit is contained in:
Roman
2015-05-19 22:41:22 +03:00
parent b7fbf6413e
commit f978fb0d78
11 changed files with 190 additions and 141 deletions

View File

@@ -216,14 +216,14 @@ void PackTest::test_float()
void PackTest::test_str()
{
QString str = QString::fromUtf8("msgpack rocks");
QString str = QStringLiteral("msgpack rocks");
QByteArray arr = MsgPack::pack(str);
QVERIFY(arr.size() == 14);
quint8 *p = (quint8 *)arr.data();
QVERIFY(p[0] == (0xa0 | str.length()));
QVERIFY(memcmp(p + 1, str.toUtf8().data(), str.size()) == 0);
str = QString::fromUtf8(QByteArray(32, 'm'));
str = QString(QByteArray(32, 'm'));
arr = MsgPack::pack(str);
QVERIFY(arr.size() == 32 + 2);
p = (quint8 *)arr.data();
@@ -231,7 +231,7 @@ void PackTest::test_str()
QVERIFY(p[1] == 32);
QVERIFY(memcmp(p + 2, str.toUtf8().data(), str.size()) == 0);
str = QString::fromUtf8(QByteArray(256, 's'));
str = QString(QByteArray(256, 's'));
arr = MsgPack::pack(str);
QVERIFY(arr.size() == 256 + 3);
p = (quint8 *)arr.data();
@@ -240,7 +240,7 @@ void PackTest::test_str()
QVERIFY(p[2] == 0x00);
QVERIFY(memcmp(p + 3, str.toUtf8().data(), str.size()) == 0);
str = QString::fromUtf8(QByteArray(65536, 'g'));
str = QString(QByteArray(65536, 'g'));
arr = MsgPack::pack(str);
QVERIFY(arr.size() == 65536 + 5);
p = (quint8 *)arr.data();

View File

@@ -77,6 +77,8 @@ void QtTypesTest::test_qpoint()
packed = MsgPack::pack(pt);
QVERIFY(packed.size() == 9);
pt2 = MsgPack::unpack(packed).toPoint();
qDebug() << pt << pt2;
qDebug() << packed.toHex() << packed.size();
QVERIFY(pt == pt2);
pt = QPoint(std::numeric_limits<qint32>::max(), std::numeric_limits<qint32>::max());

View File

@@ -12,6 +12,8 @@ class StreamTest : public QObject
private Q_SLOTS:
void test_unpack_integers();
void test_pack_integers();
void test_unpack_string();
void test_pack_string();
};
@@ -135,6 +137,72 @@ void StreamTest::test_pack_integers()
QVERIFY(l[19].toLongLong() == std::numeric_limits<qint64>::min());
}
void StreamTest::test_unpack_string()
{
QString str = QStringLiteral("msgpack rocks");
QByteArray packed = MsgPack::pack(str);
QString str2;
{
MsgPackStream stream(packed);
stream >> str2;
QVERIFY(str == str2);
}
{
str = QString(QByteArray(32, 'm'));
packed = MsgPack::pack(str);
MsgPackStream stream(packed);
stream >> str2;
QVERIFY(str == str2);
}
{
str = QString::fromUtf8(QByteArray(256, 's'));
packed = MsgPack::pack(str);
MsgPackStream stream(packed);
stream >> str2;
QVERIFY(str == str2);
}
{
str = QString(QByteArray(65536, 'g'));
packed = MsgPack::pack(str);
MsgPackStream stream(packed);
stream >> str2;
QVERIFY(str == str2);
}
}
void StreamTest::test_pack_string()
{
QByteArray packed;
MsgPackStream stream(&packed, QIODevice::WriteOnly);
QStringList strs;
stream << "abc";
strs << "abc";
QString s;
for (int i = 0; i < 8; ++i)
s += "xy";
stream << s;
strs << s;
s = QString();
for (int i = 0; i < 64; ++i)
s += "msgp";
stream << s;
strs << s;
s = QString();
for (int i = 0; i < 4096; ++i)
s += "messagepack test";
stream << s;
strs << s;
stream << "";
QStringList l = MsgPack::unpack(packed).toStringList();
QVERIFY(l[0] == strs[0]);
QVERIFY(l[1] == strs[1]);
QVERIFY(l[2] == strs[2]);
QVERIFY(l[3] == strs[3]);
QVERIFY(l[4].isEmpty());
}
QTEST_APPLESS_MAIN(StreamTest)