AusweisApp2/test/qt/ui/json/test_MsgHandler.cpp

91 lines
1.5 KiB
C++
Raw Normal View History

2017-07-03 09:30:10 +02:00
/*!
* \brief Unit tests for \ref MsgHandler
*
2019-05-22 10:08:38 +02:00
* \copyright Copyright (c) 2016-2019 Governikus GmbH & Co. KG, Germany
2017-07-03 09:30:10 +02:00
*/
#include "messages/MsgHandler.h"
#include <QtTest>
using namespace governikus;
namespace
{
class MsgTest
: public MsgHandler
{
public:
MsgTest(MsgType pType = MsgType::INVALID) : MsgHandler(pType)
{
}
void testVoid(bool pVoid)
{
setVoid(pVoid);
}
};
2019-01-03 15:06:22 +01:00
} // namespace
2017-07-03 09:30:10 +02:00
class test_MsgHandler
: public QObject
{
Q_OBJECT
private Q_SLOTS:
void invalidate()
{
MsgTest msg;
QCOMPARE(msg.isVoid(), false);
QCOMPARE(msg.toJson(), QByteArray("{\"msg\":\"INVALID\"}"));
msg.testVoid(true);
QCOMPARE(msg.isVoid(), true);
QCOMPARE(msg.toJson(), QByteArray("{\"msg\":\"INVALID\"}"));
}
void setRequest()
{
MsgTest msg;
QJsonObject dummy;
dummy["unused"] = "this will be ignored";
msg.setRequest(dummy);
QCOMPARE(msg.toJson(), QByteArray("{\"msg\":\"INVALID\"}"));
dummy["request"] = "hello world";
msg.setRequest(dummy);
QCOMPARE(msg.toJson(), QByteArray("{\"msg\":\"INVALID\",\"request\":\"hello world\"}"));
}
void toJson()
{
MsgTest msg;
QCOMPARE(msg.toJson(), QByteArray("{\"msg\":\"INVALID\"}"));
}
void getOutput()
{
MsgTest msg;
QCOMPARE(msg.getOutput(), QByteArray("{\"msg\":\"INVALID\"}"));
msg.testVoid(true);
QCOMPARE(msg.getOutput(), QByteArray());
msg.testVoid(false);
QCOMPARE(msg.getOutput(), QByteArray("{\"msg\":\"INVALID\"}"));
}
};
QTEST_GUILESS_MAIN(test_MsgHandler)
#include "test_MsgHandler.moc"