Index: denali.pro =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- denali.pro (.../denali.pro) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ denali.pro (.../denali.pro) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -1,5 +1,5 @@ -QT += quick serialbus -CONFIG += c++17 -Wall +QT += widgets qml quick serialbus +CONFIG += c++17 warn_on # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings @@ -61,7 +61,31 @@ VER_REVIS="\\\"${buildNumber}\\\"" \ VER_DEVEL="999" +CodeCoverage { + message(Building with Squish Coco) + COVERAGE_OPTIONS += --cs-qt4 + COVERAGE_OPTIONS += --cs-exclude-path=build=testunits + COVERAGE_OPTIONS += --cs-exclude-file-regex=ui_.* + COVERAGE_OPTIONS += --cs-exclude-file-regex=moc_.* + COVERAGE_OPTIONS += --cs-exclude-file-regex=main.cpp + COVERAGE_OPTIONS += --cs-exclude-file-regex=unittests.* + COVERAGE_OPTIONS += --cs-exclude-file-regex=qmlcache* + QMAKE_CFLAGS += $$COVERAGE_OPTIONS + QMAKE_CXXFLAGS += $$COVERAGE_OPTIONS + QMAKE_LFLAGS += $$COVERAGE_OPTIONS +} + +testcase { + message(Building with QtTest) + QT += testlib + DEFINES += UNIT_TEST + HEADERS += \ + unittests/unittests.h + SOURCES += \ + unittests/unittests.cpp +} + # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = Index: main.cpp =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- main.cpp (.../main.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ main.cpp (.../main.cpp) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -23,7 +23,7 @@ // Qt #include #include -#include +#include #include // Project @@ -34,6 +34,10 @@ #include "guiglobals.h" #include "guicontroller.h" +#ifdef UNIT_TEST + #include "unittests/unittests.h" + QTEST_MAIN(unittests) +#else /*! \brief Application Initialization\n * Some part of the application need to be initialized out of any thread. * So is initialized here to be initialized in the main thread. @@ -45,22 +49,26 @@ // Qt Core Application parameters settings // Qt Core Application Initialization - QGuiApplication app(argc, argv); + QApplication app(argc, argv); QCoreApplication::setApplicationName(QLatin1String("Denali")); QCoreApplication::setOrganizationName(QLatin1String("Diality Inc.")); //! - Setting the application version regarding the Bamboo build number. QString ver_revis = QString("%1").arg(VER_REVIS); - if (ver_revis.isEmpty()) ver_revis = QString("%1").arg(VER_DEVEL); + if (ver_revis.isEmpty()) { + ver_revis = QString("%1").arg(VER_DEVEL); + } QCoreApplication::setApplicationVersion(QString("%1.%2.%3") .arg(VER_MAJOR) .arg(VER_MINOR) .arg(ver_revis)); //! - Translation initialization QTranslator translator; - if (translator.load(QLocale(), app.applicationName(), QLatin1String("_"), QLatin1String(":/translations"))) + bool trLoaded = translator.load(QLocale(), app.applicationName(), QLatin1String("_"), QLatin1String(":/translations")); + if (trLoaded) { app.installTranslator(&translator); + } //! - Initializing Main Timer _MainTimer->init(); @@ -74,7 +82,7 @@ //! - Initializing Application Controller _ApplicationController->init(); QObject::connect(_ApplicationController, &ApplicationController::quit, &app, [](int retcode) { - qDebug() << "Application Terminated:" << retcode; + //qDebug() << "Application Terminated:" << retcode; QCoreApplication::exit(retcode); }, Qt::QueuedConnection); @@ -86,3 +94,4 @@ return app.exec(); } +#endif Index: sources/applicationcontroller.cpp =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -73,7 +73,7 @@ */ void ApplicationController::onActionRequest(GuiActionType vAction) { - qDebug() << "ApplicationController.actionRequested : " << vAction; + // qDebug() << "ApplicationController.actionRequested : " << vAction; // Process the requested action by GUI // Process ... emit didActionRequest(vAction); @@ -88,7 +88,7 @@ */ void ApplicationController::onActionPerform(GuiActionType vAction, GuiActionInfo vInfo) { - qDebug() << "ApplicationController.actionPerformed : " << vAction << vInfo; + // qDebug() << "ApplicationController.actionPerformed : " << vAction << vInfo; // Process the performed action by GUI // Process ... emit didActionPerform(vAction, vInfo); @@ -102,7 +102,7 @@ */ void ApplicationController::onActionCommand(GuiActionType vAction) { - qDebug() << "ApplicationController.actionCommanded : " << vAction; + // qDebug() << "ApplicationController.actionCommanded : " << vAction; // Process the command and notify GUI Controller // Process ... emit didActionCommand(vAction); @@ -117,7 +117,7 @@ */ void ApplicationController::onActionConfirm(GuiActionType vAction, GuiActionInfo vInfo) { - qDebug() << "ApplicationController.actionConfirmed : " << vAction; + // qDebug() << "ApplicationController.actionConfirmed : " << vAction; // Process the command and notify GUI Controller // Process ... emit didActionConfirm(vAction, vInfo); Index: sources/canbus/caninterface.cpp =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -62,11 +62,12 @@ void CanInterface::connection() { - connect(_canDevice, SIGNAL(framesReceived()), - this , SLOT ( onRead())); - connect(_canDevice, SIGNAL(errorOccurred(QCanBusDevice::CanBusError)), - this , SLOT ( onError(QCanBusDevice::CanBusError))); - + if (_canDevice) { + connect(_canDevice, SIGNAL(framesReceived()), + this , SLOT ( onRead())); + connect(_canDevice, SIGNAL(errorOccurred(QCanBusDevice::CanBusError)), + this , SLOT ( onError(QCanBusDevice::CanBusError))); + } connect(_MessageHandler, SIGNAL(didActionPerform(QCanBusFrame)), this , SLOT( onActionPerform(QCanBusFrame))); connect(_MessageHandler, SIGNAL(didActionRequest(QCanBusFrame)), @@ -75,13 +76,20 @@ void CanInterface::status(const QString &vDescription, QString vError) { + QString mError=""; + if (_canDevice) { + mError = _canDevice->errorString() + vError; + } + else { + mError = vError; + } _canStatus = tr("%1 '%2[%3]', %4") .arg(vDescription) .arg(_canType) .arg(_canInterface) - .arg(_canDevice->errorString() + vError) + .arg(mError) ; - qDebug() << _canStatus; + // qDebug() << _canStatus; } void CanInterface::send(const QCanBusFrame &vFrame) @@ -155,9 +163,9 @@ const QString flags = frameFlags(frame); - qDebug() << time + flags + view; + // qDebug() << time + flags + view; // TODO : Needs to be investigated on how the messages on canBus will be received. - // my require to be moved at the end of the function. + // may require to be moved at the end of the function, to not to be called for each message. emit didRead(frame); } } Index: sources/canbus/caninterface.h =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/canbus/caninterface.h (.../caninterface.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/canbus/caninterface.h (.../caninterface.h) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -23,6 +23,9 @@ // Define #define _CanInterface CanInterface::I() +// forward declarations +class unittests; + // namespace namespace Can { @@ -37,18 +40,21 @@ { Q_OBJECT + // friends + friend class ::unittests; + // constants - const char *_canType = "socketcan"; - const char *_canInterface = "can0"; - const int _canBitRate = 250000; + const char *_canType = "socketcan"; + QString _canInterface = "can0"; + const int _canBitRate = 250000; // member variables QCanBusDevice *_canDevice = nullptr; qint64 _numberFramesWritten = 0; QString _canStatus = ""; // Singleton -SINGLETON_DECL(CanInterface) + SINGLETON_DECL(CanInterface) public: bool init(); void quit(); Index: sources/canbus/messagehandler.cpp =================================================================== diff -u -r25cb66f0126963addc781f161dbfb8b0ea58f547 -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/canbus/messagehandler.cpp (.../messagehandler.cpp) (revision 25cb66f0126963addc781f161dbfb8b0ea58f547) +++ sources/canbus/messagehandler.cpp (.../messagehandler.cpp) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -56,7 +56,7 @@ // From GUI connect(_ApplicationController, SIGNAL(didActionPerform(GuiActionType,GuiActionInfo)), this , SLOT( onActionPerform(GuiActionType, GuiActionInfo))); - + // From HD/DG connect(_CanInterface , SIGNAL(didRead(QCanBusFrame)), this , SLOT( onRead(QCanBusFrame))); @@ -71,14 +71,13 @@ void MessageHandler::onActionRequest(GuiActionType vAction) { // TODO : Test Code - qDebug() << "MessageHandler.actionRequested : " << vAction; QCanBusFrame mFrame; - QByteArray mPayload; + QString mPayload; switch (vAction) { case GuiActionType::PowerOff: - mFrame.setFrameId(2); - mPayload.append("\x01\x00\x01\x01\x00\x00\x00\x00"); - mFrame.setPayload(mPayload); + mFrame.setFrameId(eChlid_UI); + mPayload = "A5 01 00 00 00 00 00 00"; + mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char(' ')).toLatin1())); break; default: break; @@ -96,12 +95,11 @@ void MessageHandler::onActionPerform(GuiActionType vAction, GuiActionInfo vInfo) { // TODO : Test Code - qDebug() << "MessageHandler.actionPerformed : " << vAction << vInfo; QCanBusFrame mFrame; QString mPayload; switch (vAction) { case GuiActionType::PowerOff: - mFrame.setFrameId(256); + mFrame.setFrameId(eChlid_UI); if (vInfo == GuiActionInfo::Accepted) { mPayload = "A5 01 00 01 01 00 00 00"; } @@ -124,14 +122,24 @@ { // TODO : Test Code bool isCommand = true; + bool isUnknow = false; + + // TODO : For test + if (vFrame.toString() != " 020 [8] A5 01 00 00 00 00 00 00") { + isUnknow = true; + } + switch (vFrame.frameId()) { - case 20: - qDebug() << "HD Command:" << vFrame.payload(); + case eChlid_HD: + // qDebug() << "<=HD"; break; default: break; } + if (isUnknow) return; + if (isCommand) { + //qDebug() << vFrame.toString(); emit didActionCommand(GuiActions::PowerOff); } else { Index: sources/canbus/messagehandler.h =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/canbus/messagehandler.h (.../messagehandler.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/canbus/messagehandler.h (.../messagehandler.h) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -28,6 +28,9 @@ // Define #define _MessageHandler MessageHandler::I() +// forward declarations +class unittests; + // namespace using namespace Gui; namespace Can { @@ -39,7 +42,21 @@ { Q_OBJECT -SINGLETON_DECL(MessageHandler) + // friends + friend class ::unittests; + + // constants + enum payload_info { + ePayload_Sync = 0xA5, + }; + + enum can_id { + eChlid_HD = 0x020, + eChlid_UI = 0x100, + }; + + // Singleton + SINGLETON_DECL(MessageHandler) public: void init(); Index: sources/gui/guiactions.h =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/gui/guiactions.h (.../guiactions.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/gui/guiactions.h (.../guiactions.h) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -23,9 +23,11 @@ explicit GuiActions(); public: enum GuiActionsType_Enum { + Unknown, PowerOff, }; enum GuiActionsInfo_Enum { + NoInfo, Accepted, Rejected, }; Index: sources/gui/guicontroller.cpp =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/gui/guicontroller.cpp (.../guicontroller.cpp) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -63,7 +63,7 @@ { // Process the GuiView Request. // If can be processed in GuiController take action and notify GuiView - qDebug() << "GuiController.actionRequested : " << vAction; + //qDebug() << "GuiController.actionRequested : " << vAction; GuiActionInfo mInfo = GuiActionInfo::Accepted; Q_UNUSED(mInfo) switch (vAction) { @@ -87,7 +87,7 @@ */ void GuiController::doActionPerform(GuiActionType vAction, GuiActionInfo vInfo) { - qDebug() << "GuiController.actionPerformed : " << vAction << vInfo; + // qDebug() << "GuiController.actionPerformed : " << vAction << vInfo; // Process the performed action by Gui // Process ... emit didActionPerform(vAction, vInfo); @@ -101,7 +101,7 @@ */ void GuiController::onActionCommand(GuiActionType vAction) { - qDebug() << "GuiController.actionCommanded : " << vAction; + // qDebug() << "GuiController.actionCommanded : " << vAction; // Process the command and notify GuiView // Process ... emit didActionCommand(vAction); @@ -116,7 +116,7 @@ */ void GuiController::onActionConfirm(GuiActionType vAction, GuiActionInfo vInfo) { - qDebug() << "GuiController.actionConfirmed : " << vAction; + // qDebug() << "GuiController.actionConfirmed : " << vAction; // Process the command and notify GuiView // Process ... emit didActionConfirm(vAction, vInfo); Index: sources/gui/guiglobals.cpp =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/gui/guiglobals.cpp (.../guiglobals.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/gui/guiglobals.cpp (.../guiglobals.cpp) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -27,21 +27,26 @@ { qRegisterMetaType ("GuiActionType"); qRegisterMetaType ("GuiActionInfo"); + } + + void registerQmlTypes() + { qmlRegisterType ("Gui.View", 0, 1, "GuiView"); qmlRegisterUncreatableType ("Gui.Actions", 0, 1, "GuiActions",QStringLiteral("Used only for enumerations no need to have an object")); } void startGui() { _viewer = new QQuickView; registerTypes(); + registerQmlTypes(); QObject::connect(_viewer, &QQuickView::statusChanged, qApp, [=](QQuickView::Status vStatus) { bool ok = vStatus == QQuickView::Ready; if (ok) { _viewer->show(); } else if (vStatus == QQuickView::Error || vStatus == QQuickView::Null) { - qDebug() << "Application Terminated:" << _viewer->errors(); + // qDebug() << "Application Terminated:" << _viewer->errors(); QCoreApplication::exit(-1); } Index: sources/gui/guiglobals.h =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/gui/guiglobals.h (.../guiglobals.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/gui/guiglobals.h (.../guiglobals.h) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -23,5 +23,6 @@ namespace Gui { extern QQuickView *_viewer; void registerTypes(); + void registerQmlTypes(); void startGui(); } Index: sources/gui/qml/components/MainMenu.qml =================================================================== diff -u -r0473a1b252123675a75558aa8f6a4d536d09c506 -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/gui/qml/components/MainMenu.qml (.../MainMenu.qml) (revision 0473a1b252123675a75558aa8f6a4d536d09c506) +++ sources/gui/qml/components/MainMenu.qml (.../MainMenu.qml) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -15,7 +15,6 @@ // Qt import QtQuick 2.12 import QtQuick.Controls 2.12 -import QtQuick.Layouts 1.12 // Project // Qml imports Index: sources/gui/qml/pages/SettingsHome.qml =================================================================== diff -u -r5194f3afffb28dac90a7ca4153b6a0ca2f239387 -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/gui/qml/pages/SettingsHome.qml (.../SettingsHome.qml) (revision 5194f3afffb28dac90a7ca4153b6a0ca2f239387) +++ sources/gui/qml/pages/SettingsHome.qml (.../SettingsHome.qml) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -17,6 +17,8 @@ import QtQuick.Controls 2.12 // Project +import Gui.Actions 0.1; + // Qml imports import "qrc:/globals" import "qrc:/components" @@ -26,6 +28,20 @@ * which is the default screen in the "Settings" stack */ ScreenItem { id: _root + TouchRect { id : _poweroff + width: 150 + height: Variables.logoHeight + anchors { + top : parent.top + right : parent.right + topMargin : (Variables.headerHeight - Variables.logoHeight) / 2 + rightMargin : (Variables.headerHeight - Variables.logoHeight) / 2 + } + text.text: qsTr("Shutdown") + button.onPressed: { + _GuiView.doActionRequest(GuiActions.PowerOff) + } + } Column { spacing: Variables.columnSpacing anchors.centerIn: parent Index: sources/gui/qml/pages/TreatmentHome.qml =================================================================== diff -u -r174d5078531f9dfbe9cdc45274b852984bb72647 -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/gui/qml/pages/TreatmentHome.qml (.../TreatmentHome.qml) (revision 174d5078531f9dfbe9cdc45274b852984bb72647) +++ sources/gui/qml/pages/TreatmentHome.qml (.../TreatmentHome.qml) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -35,21 +35,6 @@ // exported properties // - TouchRect { id : _poweroff - width: 150 - height: Variables.logoHeight - anchors { - top : parent.top - right : parent.right - topMargin : (Variables.headerHeight - Variables.logoHeight) / 2 - rightMargin : (Variables.headerHeight - Variables.logoHeight) / 2 - } - text.text: qsTr("Shutdown") - button.onPressed: { - _GuiView.doActionRequest(GuiActions.ActionPowerOff) - } - } - TreatmentStart { id : _treatmentStart onBackPressed: { _treatmentStack.pop() Index: sources/storage/filehandler.cpp =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 --- sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/storage/filehandler.cpp (.../filehandler.cpp) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -35,7 +35,7 @@ void FileHandler::directoryChanged(const QString &vPath) { Q_UNUSED(vPath) - qDebug() << QFileInfo::exists("/dev/sda"); + // qDebug() << QFileInfo::exists("/dev/sda"); } bool FileHandler::mountUsb() Index: unittests/unittests.cpp =================================================================== diff -u --- unittests/unittests.cpp (revision 0) +++ unittests/unittests.cpp (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -0,0 +1,136 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + * IN PART OR IN WHOLE, + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * file unittests.cpp + * date 11/21/2019 + * author Behrouz NematiPour + * + */ +#include "unittests.h" + +//using namespace Can; +// Project +#include "guiglobals.h" +#include "caninterface.h" +#include "messagehandler.h" +#include "applicationcontroller.h" +#include "guicontroller.h" +#include "maintimer.h" + +unittests::unittests(QObject *parent) : QObject(parent) { } + +void unittests::initTestCase() +{ +} + +void unittests::initTestCase_data() +{ +} + +void unittests::init() +{ + _emited = false; +} + +void unittests::tst_CanInterface_Connect_Error_Interface() +{ + QString mTr = tr("Error: Connection"); + Can::_CanInterface->_canInterface = "can1"; + Can::_CanInterface ->init(); + QCOMPARE(Can::_CanInterface->status().left(mTr.length()), mTr); +} + +void unittests::tst_CanInterface_Connect_NoError() +{ + Can::_CanInterface->_canInterface = "can0"; + Can::_CanInterface ->init(); + QString mTr = tr("Connected"); + QCOMPARE(Can::_CanInterface->status().left(mTr.length()), mTr); + + Can::_CanInterface->onRead (); +} + +void unittests::tst_MessageHandler_Init() +{ + Can::_MessageHandler->init(); + connect(Can::_MessageHandler, &Can::MessageHandler::didActionPerform, [=](const QCanBusFrame &vFrame) { + _emited = true; + QString packet = vFrame.toString(); + QCOMPARE(packet, _expected); + }); + connect(Can::_MessageHandler, &Can::MessageHandler::didActionRequest, [=](const QCanBusFrame &vFrame) { + _emited = true; + QString packet = vFrame.toString(); + QCOMPARE(packet, _expected); + }); + connect(Can::_MessageHandler, &Can::MessageHandler::didActionCommand, [=](Gui::GuiActionType vAction) { + _emited = true; + QCOMPARE(vAction, _action); + }); +} + +void unittests::tst_MessageHandler_ActionPerform_PowerOff_Accepted() +{ + _expected = " 100 [8] A5 01 00 01 01 00 00 00"; + Can::_MessageHandler->onActionPerform(Gui::GuiActionType::PowerOff,Gui::GuiActionInfo::Accepted); + QVERIFY(_emited); +} + +void unittests::tst_MessageHandler_ActionPerform_PowerOff_Rejected() +{ + _expected = " 100 [8] A5 01 00 01 00 00 00 00"; + Can::_MessageHandler->onActionPerform(Gui::GuiActionType::PowerOff,Gui::GuiActionInfo::Rejected); + QVERIFY(_emited); +} + +void unittests::tst_MessageHandler_ActionPerform_Unknown() +{ + _expected = " 000 [0]"; + Can::_MessageHandler->onActionPerform(Gui::GuiActionType::Unknown,Gui::GuiActionInfo::NoInfo); + QVERIFY(_emited); +} + +void unittests::tst_MessageHandler_ActionRequest_PowerOff() +{ + _expected = " 100 [8] A5 01 00 00 00 00 00 00"; + Can::_MessageHandler->onActionRequest(Gui::GuiActionType::PowerOff); + QVERIFY(_emited); +} + +void unittests::tst_MessageHandler_ActionRequest_Unknown() +{ + _expected = " 000 [0]"; + Can::_MessageHandler->onActionRequest(Gui::GuiActionType::Unknown); + QVERIFY(_emited); +} + +void unittests::tst_MessageHandler_ActionCommand_PowerOff() +{ + _action = Gui::GuiActionType::PowerOff; + QCanBusFrame mFrame; + QString mPayload; + mFrame.setFrameId(Can::MessageHandler::eChlid_HD); + mPayload = "A5 01 00 00 00 00 00 00"; + mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char(' ')).toLatin1())); + emit Can::_CanInterface->didRead(mFrame); + QVERIFY(_emited); +} + +void unittests::cleanup() +{ + disconnect(Can::_MessageHandler); + Can::_CanInterface ->connection(); + Can::_MessageHandler->connection(); +} + +void unittests::cleanupTestCase() +{ + Can::_CanInterface->quit(); + QString mTr = tr("Disconnected"); + QCOMPARE(Can::_CanInterface->status().left(mTr.length()), mTr); +} Index: unittests/unittests.h =================================================================== diff -u --- unittests/unittests.h (revision 0) +++ unittests/unittests.h (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) @@ -0,0 +1,51 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, + * IN PART OR IN WHOLE, + * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * file unittests.h + * date 11/21/2019 + * author Behrouz NematiPour + * + */ +#pragma once + +#include +#include + +class unittests : public QObject +{ + Q_OBJECT + bool _emited = false; + QString _expected = ""; + int _action = -1; + +public: + explicit unittests(QObject *parent = nullptr); + +private slots: + void initTestCase_data(); + + void initTestCase(); + void init(); + + void tst_CanInterface_Connect_Error_Interface(); + void tst_CanInterface_Connect_Error_Type() {} + void tst_CanInterface_Connect_NoError(); + + void tst_MessageHandler_Init(); + + void tst_MessageHandler_ActionPerform_PowerOff_Accepted(); + void tst_MessageHandler_ActionPerform_PowerOff_Rejected(); + void tst_MessageHandler_ActionPerform_Unknown(); + void tst_MessageHandler_ActionRequest_PowerOff(); + void tst_MessageHandler_ActionRequest_Unknown(); + void tst_MessageHandler_ActionCommand_PowerOff(); + + void cleanup(); + void cleanupTestCase(); +}; +