I have been developing a client-server library using C++/Qt and I have written separate programs that run properly. Now I want to test this using Qt's unit test framework. So far I have written the client code, but it doesn't work properly. sometimes it doesn't connect to server and when it connects the data it sends is null.
class JsonRPCServerTest : public QObject {
Q_OBJECT
public:
JsonRPCServerTest(QObject* parent = nullptr);
~JsonRPCServerTest();
private Q_SLOTS:
void initTestCase();
void client();
void cleanupTestCase();
private :
JsonRPCClient m_client;
};
JsonRPCServerTest::JsonRPCServerTest(QObject* parent):
QObject(parent) {
}
void JsonRPCServerTest::client() {
m_client.setUrl(QUrl("http://127.0.0.1:8383"));
int i = 1;
QJsonObject jobj;
jobj["x"] = i;
jobj["y"] = i;
JsonRPCRequest req(1, "sum", jobj);
qDebug() << "Dispatching " << req.data();
m_client.dispatch(req);
qApp->processEvents();
}
QTEST_GUILESS_MAIN(JsonRPCServerTest)
#include "tst_jsonrpcserver.moc"