CMake BUILD_TESTS variable added

TRUE and FALSE renamed to MTRUE and MFALSE
stream.h[cpp] renamed to msgpackstream.h[cpp]
QMap and QHash added to MsgPackStream + test
This commit is contained in:
Roman
2015-06-29 14:32:35 +03:00
parent 318aa870cd
commit ce6ddab5e4
11 changed files with 260 additions and 27 deletions

View File

@ -216,7 +216,7 @@ void PackTest::test_float()
void PackTest::test_str()
{
QString str = QStringLiteral("msgpack rocks");
QString str = QString("msgpack rocks");
QByteArray arr = MsgPack::pack(str);
QVERIFY(arr.size() == 14);
quint8 *p = (quint8 *)arr.data();

View File

@ -1,7 +1,6 @@
#include <QString>
#include <QtTest>
#include <QDebug>
#include <stream.h>
#include <msgpackstream.h>
#include <msgpack.h>
#include <limits>
@ -18,6 +17,7 @@ private Q_SLOTS:
void test_double();
void test_bin();
void test_array();
void test_map();
};
void StreamTest::test_unpack_integers()
@ -142,7 +142,7 @@ void StreamTest::test_pack_integers()
void StreamTest::test_unpack_string()
{
QString str = QStringLiteral("msgpack rocks");
QString str = QString("msgpack rocks");
QByteArray packed = MsgPack::pack(str);
QString str2;
@ -367,5 +367,47 @@ void StreamTest::test_array()
}
}
void StreamTest::test_map()
{
QMap<QString, int> map, map2;
QByteArray ba;
map.insert("m0", 0);
{
MsgPackStream stream(&ba, QIODevice::WriteOnly);
stream << map;
MsgPackStream stream2(ba);
stream2 >> map2;
}
QVERIFY(ba.length() == 5);
quint8 *p = (quint8 *)ba.data();
QVERIFY(p[0] == 0x80 | 1);
QVERIFY(map == map2);
for (int i = 1; i < 16; ++i)
map.insert(QString("m%1").QString::arg(i), i);
{
MsgPackStream stream(&ba, QIODevice::WriteOnly);
stream << map;
MsgPackStream stream2(ba);
stream2 >> map2;
}
p = (quint8 *)ba.data();
QVERIFY(p[0] == 0xde);
QVERIFY(map == map2);
for (int i = 16; i < 65536; ++i)
map.insert(QString("m%1").QString::arg(i), i);
{
MsgPackStream stream(&ba, QIODevice::WriteOnly);
stream << map;
MsgPackStream stream2(ba);
stream2 >> map2;
}
p = (quint8 *)ba.data();
QVERIFY(p[0] == 0xdf);
QVERIFY(map == map2);
}
QTEST_APPLESS_MAIN(StreamTest)
#include "stream_test.moc"