You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

284 lines
6.2 KiB

#include <QtTest>
#include "TestDataSender.h"
#include "model/Console.h"
#include "TestLogger.h"
#include <QSignalSpy>
class ConsoleTest : public QObject
{
Q_OBJECT
private:
Console c;
TestDataSender t;
TestLogger log;
public:
ConsoleTest();
~ConsoleTest();
//uncrustify off
private slots:
//uncrustify on
void pressDual_test_case();
void releaseDual_test_case();
void dualLedChange_test_case();
void pressQuad_test_case();
void releaseQuad_test_case();
void rotateJs1_test_case();
void rotatFocus_test_case();
void echo_test_case();
void wrongProtocol_test_case();
void wrongMessageDirection_test_case();
void ledWrongColor_test_case();
};
/*************************************************************************************************/
ConsoleTest::ConsoleTest()
{
c.injectDataSender(&t);
c.injectLogger(&log);
}
/*************************************************************************************************/
ConsoleTest::~ConsoleTest()
{
}
/*************************************************************************************************/
void ConsoleTest::pressDual_test_case()
{
c.pressDual();
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x01;
arr[2] = 0x04;
arr[3] = 0x1D;
arr[4] = 0x01;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t.consoleData, arr);
}
/*************************************************************************************************/
void ConsoleTest::releaseDual_test_case()
{
c.releaseDual();
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x01;
arr[2] = 0x04;
arr[3] = 0x1D;
arr[4] = 0x00;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t.consoleData, arr);
}
/*************************************************************************************************/
void ConsoleTest::dualLedChange_test_case()
{
QSignalSpy spy(&c, SIGNAL(dualLedChanged(char)));
char ledValue = 0x01;
QByteArray arr;
arr.resize(8);
arr[0] = 0x01;
arr[1] = 0x01;
arr[2] = 0x03;
arr[3] = static_cast<char>(0x82);
arr[4] = ledValue;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
c.newData(arr);
auto result = spy.takeFirst()[0].value<QByteArray>();
QCOMPARE(result[0], ledValue);
}
/*************************************************************************************************/
void ConsoleTest::pressQuad_test_case()
{
c.pressQuad();
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x01;
arr[2] = 0x04;
arr[3] = 0x1C;
arr[4] = 0x01;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t.consoleData, arr);
}
/*************************************************************************************************/
void ConsoleTest::releaseQuad_test_case()
{
c.releaseQuad();
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x01;
arr[2] = 0x04;
arr[3] = 0x1C;
arr[4] = 0x00;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t.consoleData, arr);
}
/*************************************************************************************************/
void ConsoleTest::rotateJs1_test_case()
{
auto value = 0;
c.rotateJs1(value);
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x02;
arr[2] = 0x05;
arr[3] = 0x56;
arr[4] = static_cast<char>(value >> 8);
arr[5] = static_cast<char>(value);
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t.consoleData, arr);
}
/*************************************************************************************************/
void ConsoleTest::rotatFocus_test_case()
{
auto value = 40000;
c.rotateFocus(value);
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x02;
arr[2] = 0x05;
arr[3] = 0x51;
arr[4] = static_cast<char>(value >> 8);
arr[5] = static_cast<char>(value);
arr[6] = 0x00;
arr[7] = 0x00;
QCOMPARE(t.consoleData, arr);
}
/*************************************************************************************************/
void ConsoleTest::echo_test_case()
{
QByteArray arr;
arr.resize(8);
arr[0] = 0x01;
arr[1] = 0x02;
arr[2] = 0x06;
arr[3] = static_cast<char>(0xA4);
arr[4] = 0x00;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
c.newData(arr);
QCOMPARE(t.consoleData, arr);
}
/*************************************************************************************************/
void ConsoleTest::wrongProtocol_test_case()
{
char ledValue = 0x01;
QByteArray arr;
arr.resize(5);
arr[0] = 0x01;
arr[1] = 0x01;
arr[2] = 0x03;
arr[3] = static_cast<char>(0x82);
arr[4] = ledValue;
QSignalSpy spy(&log, SIGNAL(isCalled()));
c.newData(arr);
QCOMPARE(spy.count(), 1);
}
/*************************************************************************************************/
void ConsoleTest::wrongMessageDirection_test_case()
{
char ledValue = 0x01;
QByteArray arr;
arr.resize(8);
arr[0] = 0x00;
arr[1] = 0x01;
arr[2] = 0x03;
arr[3] = static_cast<char>(0x82);
arr[4] = ledValue;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
QSignalSpy spy(&log, SIGNAL(isCalled()));
c.newData(arr);
QCOMPARE(spy.count(), 1);
}
/*************************************************************************************************/
void ConsoleTest::ledWrongColor_test_case()
{
QByteArray arr;
char ledValue = 0x05;
arr.resize(8);
arr[0] = 0x01;
arr[1] = 0x01;
arr[2] = 0x04;
arr[3] = static_cast<char>(0x82);
arr[4] = ledValue;
arr[5] = 0x00;
arr[6] = 0x00;
arr[7] = 0x00;
QSignalSpy spy(&log, SIGNAL(isCalled()));
c.newData(arr);
QCOMPARE(spy.count(), 1);
}
/*************************************************************************************************/
QTEST_APPLESS_MAIN(ConsoleTest)
#include "tst_console.moc"