Heart/HeartTests/AbstractSpace/abstractnodetest.cpp

76 lines
1.6 KiB
C++
Raw Normal View History

2020-09-27 12:40:11 +03:00
/*
* Copyright (C) 2018-2020 QuasarApp.
* Distributed under the lgplv3 software license, see the accompanying
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
2020-09-15 21:16:35 +03:00
#include "abstractnodetest.h"
#include "testutils.h"
#include <abstractnode.h>
#include <keystorage.h>
#include <ping.h>
2020-09-15 22:07:49 +03:00
class TestingClient: public QH::AbstractNode {
2020-09-15 21:16:35 +03:00
// AbstractNode interface
public:
2020-09-16 15:10:13 +03:00
const QH::PKG::Ping& getPing() const {
2020-09-15 21:16:35 +03:00
return _ping;
}
protected:
2020-09-16 15:10:13 +03:00
void incomingData(QH::PKG::AbstractData *pkg, const QH::HostAddress &sender) {
2020-09-15 21:16:35 +03:00
Q_UNUSED(sender);
2020-09-16 15:10:13 +03:00
auto ping = dynamic_cast<QH::PKG::Ping*>(pkg);
2020-09-15 21:16:35 +03:00
if (ping)
2020-09-21 16:50:31 +03:00
_ping.setAnsver(ping->ansver());
2020-09-15 21:16:35 +03:00
}
private:
2020-09-16 15:10:13 +03:00
QH::PKG::Ping _ping;
2020-09-15 21:16:35 +03:00
};
AbstractNodeTest::AbstractNodeTest() {
2020-09-15 22:07:49 +03:00
_nodeA = new QH::AbstractNode();
2020-09-15 21:16:35 +03:00
_nodeB = new TestingClient();
}
AbstractNodeTest::~AbstractNodeTest() {
delete _nodeA;
delete _nodeB;
}
void AbstractNodeTest::test() {
QVERIFY(connectTest());
QVERIFY(sendDataTest());
}
bool AbstractNodeTest::connectTest() {
if (!_nodeA->run(TEST_LOCAL_HOST, TEST_PORT)) {
return false;
}
return connectFunc(_nodeB, TEST_LOCAL_HOST, TEST_PORT);
}
bool AbstractNodeTest::sendDataTest() {
auto request = [this](){
2020-09-15 22:07:49 +03:00
return _nodeB->ping(QH::HostAddress(TEST_LOCAL_HOST, TEST_PORT));
2020-09-15 21:16:35 +03:00
};
auto client = dynamic_cast<TestingClient*>(_nodeB);
auto check = [client](){
return client->getPing().ansver();
};
return funcPrivateConnect(request, check);
}