server: base server code.
This commit is contained in:
@@ -4,5 +4,5 @@ project(frelayTest LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_executable(frelayTest protocolTest.cpp)
|
||||
add_executable(frelayTest protocolTest.cpp infoTest.h infoTest.cpp)
|
||||
target_link_libraries(frelayTest PRIVATE Protocol)
|
||||
83
Test/infoTest.cpp
Normal file
83
Test/infoTest.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "infoTest.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
int infoTest1()
|
||||
{
|
||||
InfoClient ic;
|
||||
ic.id = "1234567890";
|
||||
ic.name = "Test";
|
||||
|
||||
InfoClientVec vec;
|
||||
vec.vec.append(ic);
|
||||
|
||||
QByteArray qa;
|
||||
QBuffer buf(&qa);
|
||||
buf.open(QIODevice::ReadWrite);
|
||||
|
||||
QDataStream qs(&buf);
|
||||
vec.serialize(qs);
|
||||
buf.close();
|
||||
|
||||
qDebug() << "Serialized data size:" << qa.size();
|
||||
qDebug() << "Serialized data:" << qa.toHex();
|
||||
|
||||
QBuffer buf2(&qa);
|
||||
buf2.open(QIODevice::ReadWrite);
|
||||
QDataStream qs2(&buf2);
|
||||
InfoClientVec vec2;
|
||||
vec2.deserialize(qs2);
|
||||
buf2.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int infoTest2()
|
||||
{
|
||||
InfoClient ic;
|
||||
ic.id = "1234567890";
|
||||
ic.name = "Test";
|
||||
|
||||
InfoClientVec vec;
|
||||
vec.vec.append(ic);
|
||||
|
||||
QByteArray qa;
|
||||
QDataStream qs(&qa, QIODevice::ReadWrite);
|
||||
vec.serialize(qs);
|
||||
|
||||
qDebug() << "Serialized data size:" << qa.size();
|
||||
qDebug() << "Serialized data:" << qa.toHex();
|
||||
|
||||
qs.device()->seek(0);
|
||||
InfoClientVec vec2;
|
||||
vec2.deserialize(qs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void performanceTest()
|
||||
{
|
||||
QByteArray data;
|
||||
QElapsedTimer timer;
|
||||
|
||||
timer.start();
|
||||
QDataStream stream(&data, QIODevice::ReadWrite);
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
stream << i;
|
||||
stream.device()->seek(0);
|
||||
int val;
|
||||
stream >> val;
|
||||
}
|
||||
qDebug() << "Reuse stream:" << timer.elapsed() << "ms";
|
||||
|
||||
timer.start();
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
QDataStream out(&data, QIODevice::WriteOnly);
|
||||
out << i;
|
||||
QDataStream in(&data, QIODevice::ReadOnly);
|
||||
int val;
|
||||
in >> val;
|
||||
}
|
||||
qDebug() << "New streams:" << timer.elapsed() << "ms";
|
||||
}
|
||||
10
Test/infoTest.h
Normal file
10
Test/infoTest.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef INFO_TEST_H_
|
||||
#define INFO_TEST_H_
|
||||
|
||||
#include <InfoClient.h>
|
||||
|
||||
int infoTest1();
|
||||
int infoTest2();
|
||||
void performanceTest();
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,8 @@
|
||||
#include <Protocol.h>
|
||||
#include <QDebug>
|
||||
#include "infoTest.h"
|
||||
|
||||
int main()
|
||||
int test1()
|
||||
{
|
||||
auto frame = QSharedPointer<FrameBuffer>::create();
|
||||
frame->type = FBT_CLI_BIN_FILEDATA;
|
||||
@@ -14,6 +15,11 @@ int main()
|
||||
qDebug() << "Packed data hex:" << packet.toHex();
|
||||
|
||||
auto ret = Protocol::ParseBuffer(packet);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
performanceTest();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user