mirror of
https://github.com/romixlab/qmsgpack.git
synced 2025-07-30 02:17:15 +02:00
MsgPackStream missing dev() added. Some little improvements.
This commit is contained in:
@ -8,7 +8,7 @@ if (Qt5Core_FOUND)
|
||||
set(TEST_LIBRARIES ${Qt5Test_LIBRARIES})
|
||||
endif ()
|
||||
|
||||
set(TEST_SUBDIRS pack unpack mixed qttypes stream)
|
||||
set(TEST_SUBDIRS pack unpack mixed stream)
|
||||
|
||||
foreach(subdir ${TEST_SUBDIRS})
|
||||
add_subdirectory(${subdir})
|
||||
|
24
tests/big/CMakeLists.txt
Normal file
24
tests/big/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
set(QT_USE_QTTEST TRUE)
|
||||
|
||||
if (NOT Qt5Core_FOUND)
|
||||
include( ${QT_USE_FILE} )
|
||||
endif()
|
||||
|
||||
include(AddFileDependencies)
|
||||
|
||||
include_directories(../../src ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(UNIT_TESTS big)
|
||||
|
||||
foreach(test ${UNIT_TESTS})
|
||||
message(status "Building ${test}")
|
||||
add_executable(${test} ${test}.cpp)
|
||||
|
||||
target_link_libraries(${test}
|
||||
${QT_LIBRARIES}
|
||||
${TEST_LIBRARIES}
|
||||
qmsgpack
|
||||
)
|
||||
|
||||
add_test(${test} ${test})
|
||||
endforeach()
|
39
tests/big/big.cpp
Normal file
39
tests/big/big.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <QString>
|
||||
#include <QtTest>
|
||||
#include <QDebug>
|
||||
#include <msgpack.h>
|
||||
#include <limits>
|
||||
#include <msgpack_ext.h>
|
||||
|
||||
class Big : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void test_big_list();
|
||||
};
|
||||
|
||||
void Big::test_big_list()
|
||||
{
|
||||
QVariantList list;
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
list << i;
|
||||
QByteArray packed;
|
||||
QVariantList unpacked;
|
||||
QBENCHMARK {
|
||||
packed = MsgPack::pack(list);
|
||||
unpacked = MsgPack::unpack(packed).toList();
|
||||
}
|
||||
bool listOk = true;
|
||||
for (int i = 0; i < unpacked.size(); ++i) {
|
||||
if (unpacked[i].toInt() != i) {
|
||||
listOk = false;
|
||||
}
|
||||
}
|
||||
QVERIFY(listOk);
|
||||
}
|
||||
|
||||
|
||||
QTEST_APPLESS_MAIN(Big)
|
||||
|
||||
#include "big.moc"
|
@ -9,7 +9,6 @@ class PackTest : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void test_nil();
|
||||
void test_bool();
|
||||
void test_fixint();
|
||||
void test_integer8();
|
||||
@ -22,14 +21,6 @@ private Q_SLOTS:
|
||||
void test_array();
|
||||
};
|
||||
|
||||
void PackTest::test_nil()
|
||||
{
|
||||
QByteArray arr = MsgPack::pack(QVariant());
|
||||
quint8 *p = (quint8 *)arr.data();
|
||||
QVERIFY(arr.size() == 1);
|
||||
QVERIFY(p[0] == 0xc0);
|
||||
}
|
||||
|
||||
void PackTest::test_bool()
|
||||
{
|
||||
QByteArray arr = MsgPack::pack(false);
|
||||
@ -225,7 +216,7 @@ void PackTest::test_float()
|
||||
|
||||
void PackTest::test_str()
|
||||
{
|
||||
QString str = QString("msgpack rocks");
|
||||
QString str = QStringLiteral("msgpack rocks");
|
||||
QByteArray arr = MsgPack::pack(str);
|
||||
QVERIFY(arr.size() == 14);
|
||||
quint8 *p = (quint8 *)arr.data();
|
||||
|
@ -74,11 +74,11 @@ void QtTypesTest::test_qpoint()
|
||||
QPoint pt2 = MsgPack::unpack(packed).toPoint();
|
||||
QVERIFY(pt == pt2);
|
||||
|
||||
pt = QPoint(1, 2);
|
||||
packed = MsgPack::pack(pt);
|
||||
QVERIFY(packed.size() == 4);
|
||||
pt2 = MsgPack::unpack(packed).toPoint();
|
||||
QVERIFY(pt == pt2);
|
||||
pt = QPoint(1, 2);
|
||||
packed = MsgPack::pack(pt);
|
||||
QVERIFY(packed.size() == 4);
|
||||
pt2 = MsgPack::unpack(packed).toPoint();
|
||||
QVERIFY(pt == pt2);
|
||||
|
||||
pt = QPoint(1234, 5678);
|
||||
packed = MsgPack::pack(pt);
|
||||
@ -141,4 +141,4 @@ void QtTypesTest::test_qrect()
|
||||
|
||||
QTEST_APPLESS_MAIN(QtTypesTest)
|
||||
|
||||
#include "qttypes_test.moc"
|
||||
#include "qttypes_test.moc"
|
@ -1,5 +1,6 @@
|
||||
#include <QString>
|
||||
#include <QtTest>
|
||||
#include <QDebug>
|
||||
#include <msgpackstream.h>
|
||||
#include <msgpack.h>
|
||||
#include <limits>
|
||||
@ -17,7 +18,6 @@ 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 = QString("msgpack rocks");
|
||||
QString str = QStringLiteral("msgpack rocks");
|
||||
QByteArray packed = MsgPack::pack(str);
|
||||
QString str2;
|
||||
|
||||
@ -367,47 +367,5 @@ 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"
|
||||
|
@ -9,7 +9,6 @@ class UnpackTest : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void test_nil();
|
||||
void test_booleans();
|
||||
void test_integers();
|
||||
void test_floats();
|
||||
@ -18,13 +17,6 @@ private Q_SLOTS:
|
||||
void test_array();
|
||||
};
|
||||
|
||||
void UnpackTest::test_nil()
|
||||
{
|
||||
QByteArray pack = MsgPack::pack(QVariantList() << true << QVariant());
|
||||
QVariantList u = MsgPack::unpack(pack).toList();
|
||||
QVERIFY(u[0] == true);
|
||||
QVERIFY(u[1].isNull());
|
||||
}
|
||||
|
||||
void UnpackTest::test_booleans()
|
||||
{
|
||||
|
Reference in New Issue
Block a user