2020-09-27 12:40:11 +03:00
|
|
|
/*
|
2022-03-03 19:01:19 +03:00
|
|
|
* Copyright (C) 2018-2022 QuasarApp.
|
2020-09-27 12:40:11 +03:00
|
|
|
* 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 <ping.h>
|
|
|
|
|
2021-04-13 19:33:25 +03:00
|
|
|
#define LOCAL_TEST_PORT TEST_PORT + 1
|
|
|
|
|
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:
|
2021-03-09 16:10:26 +03:00
|
|
|
void incomingData(const QH::PKG::AbstractData *pkg, const QH::AbstractNodeInfo *sender) override {
|
2020-09-15 21:16:35 +03:00
|
|
|
Q_UNUSED(sender);
|
|
|
|
|
2021-03-09 16:10:26 +03:00
|
|
|
auto ping = dynamic_cast<const 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() {
|
2021-02-01 15:10:57 +03:00
|
|
|
_nodeA->softDelete();
|
|
|
|
_nodeB->softDelete();
|
2020-09-15 21:16:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractNodeTest::test() {
|
|
|
|
QVERIFY(connectTest());
|
|
|
|
QVERIFY(sendDataTest());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractNodeTest::connectTest() {
|
|
|
|
|
2021-04-13 19:33:25 +03:00
|
|
|
if (!_nodeA->run(TEST_LOCAL_HOST, LOCAL_TEST_PORT)) {
|
2020-09-15 21:16:35 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-13 19:33:25 +03:00
|
|
|
return connectFunc(_nodeB, TEST_LOCAL_HOST, LOCAL_TEST_PORT);
|
2020-09-15 21:16:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractNodeTest::sendDataTest() {
|
|
|
|
|
|
|
|
auto request = [this](){
|
2021-04-13 19:33:25 +03:00
|
|
|
return _nodeB->ping(QH::HostAddress(TEST_LOCAL_HOST, LOCAL_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);
|
|
|
|
}
|
2021-03-22 19:56:33 +03:00
|
|
|
|