2020-05-06 23:23:46 +03:00
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2020-05-07 16:08:56 +03:00
|
|
|
#include "defaultcontroller.h"
|
|
|
|
#include "defaultservice.h"
|
2020-05-06 23:23:46 +03:00
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#define TEST_LOCAL_HOST "127.0.0.1"
|
|
|
|
#define TEST_PORT 27777
|
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
class testPatronum : public QObject
|
2020-05-06 23:23:46 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2020-05-08 13:22:17 +03:00
|
|
|
testPatronum();
|
2020-05-06 23:23:46 +03:00
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
void testPing();
|
2020-05-08 21:06:57 +03:00
|
|
|
void testRandomCommad();
|
2020-05-06 23:23:46 +03:00
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
~testPatronum();
|
2020-05-06 23:23:46 +03:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
2020-05-07 16:08:56 +03:00
|
|
|
void connectTest();
|
|
|
|
|
2020-05-06 23:23:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
testPatronum::testPatronum() {
|
2020-05-06 23:23:46 +03:00
|
|
|
QuasarAppUtils::Params::setArg("verbose", 3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
void testPatronum::testPing() {
|
|
|
|
const char* arg[] = {
|
|
|
|
"/",
|
2020-05-08 21:06:57 +03:00
|
|
|
"ping"
|
2020-05-08 13:22:17 +03:00
|
|
|
};
|
|
|
|
DefaultController cli;
|
2020-05-07 16:08:56 +03:00
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
QVERIFY(cli.send(2 , arg));
|
|
|
|
QVERIFY(cli.waitForResponce(1000));
|
|
|
|
QVERIFY(cli.getResponce().value("Result") == "pong");
|
|
|
|
}
|
2020-05-07 16:08:56 +03:00
|
|
|
|
2020-05-08 21:06:57 +03:00
|
|
|
void testPatronum::testRandomCommad() {
|
|
|
|
const char* arg[] = {
|
|
|
|
"/",
|
|
|
|
"fd"
|
|
|
|
};
|
|
|
|
DefaultController cli;
|
|
|
|
|
|
|
|
QVERIFY(cli.send(2 , arg));
|
|
|
|
QVERIFY(cli.waitForResponce(1000));
|
|
|
|
QVERIFY(cli.getResponce().contains("Error"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
void testPatronum::connectTest() {
|
|
|
|
DefaultService serv;
|
2020-05-07 16:08:56 +03:00
|
|
|
|
2020-05-08 21:06:57 +03:00
|
|
|
QTimer::singleShot(0, [this]() {
|
|
|
|
testRandomCommad();
|
2020-05-08 13:22:17 +03:00
|
|
|
testPing();
|
2020-05-08 21:06:57 +03:00
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
QCoreApplication::exit(0);
|
|
|
|
});
|
2020-05-07 16:08:56 +03:00
|
|
|
|
|
|
|
QVERIFY(serv.exec() == 0);
|
|
|
|
|
2020-05-06 23:23:46 +03:00
|
|
|
}
|
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
testPatronum::~testPatronum() {
|
2020-05-06 23:23:46 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
void testPatronum::initTestCase() {
|
2020-05-06 23:23:46 +03:00
|
|
|
}
|
|
|
|
|
2020-05-08 13:22:17 +03:00
|
|
|
QTEST_APPLESS_MAIN(testPatronum)
|
2020-05-06 23:23:46 +03:00
|
|
|
|
2020-05-07 16:08:56 +03:00
|
|
|
#include "tst_unittests.moc"
|