Index: .gitignore
===================================================================
diff -u -r618ed822b8422dc2374c4c9e8f356e72f5dd2841 -r561055268da68e24fe91a1148b76bf1785dae14d
--- .gitignore (.../.gitignore) (revision 618ed822b8422dc2374c4c9e8f356e72f5dd2841)
+++ .gitignore (.../.gitignore) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -1,3 +1,2 @@
-*.pro.user*
*.autosave
Index: denali.pro
===================================================================
diff -u -rd3f98384e9400f8acb84c88dee75f1c480986998 -r561055268da68e24fe91a1148b76bf1785dae14d
--- denali.pro (.../denali.pro) (revision d3f98384e9400f8acb84c88dee75f1c480986998)
+++ denali.pro (.../denali.pro) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -92,22 +92,24 @@
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*
+ COVERAGE_OPTIONS += --cs-exclude-file-regex=tst_*
QMAKE_CFLAGS += $$COVERAGE_OPTIONS
QMAKE_CXXFLAGS += $$COVERAGE_OPTIONS
QMAKE_LFLAGS += $$COVERAGE_OPTIONS
}
-testcase {
- message(Building with QtTest)
+tst_canbus {
+ message(Building with QtTest test case canbus)
QT += testlib
- DEFINES += UNIT_TEST
+ DEFINES += UNIT_TEST \
+ TEST_CLASS_INCLUDE=\\\"unittests/tst_canbus.h\\\" \
+ TEST_CLASS_NAME=tst_canbus
HEADERS += \
- unittests/unittests.h
- SOURCES += \
- unittests/unittests.cpp
+ unittests/tst_canbus.h
+ SOURCES += \
+ unittests/tst_canbus.cpp
}
# Additional import path used to resolve QML modules in Qt Creator's code model
Index: denali.pro.user
===================================================================
diff -u
--- denali.pro.user (revision 0)
+++ denali.pro.user (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -0,0 +1,737 @@
+
+
+
+
+
+ EnvironmentId
+ {67370740-e20f-4fc6-be45-6652e866a8bf}
+
+
+ ProjectExplorer.Project.ActiveTarget
+ 0
+
+
+ ProjectExplorer.Project.EditorSettings
+
+ true
+ false
+ true
+
+ Cpp
+
+ CppGlobal
+
+
+
+ QmlJS
+
+ QmlJSGlobal
+
+
+
+ Nim
+
+ NimGlobal
+
+
+ 3
+ UTF-8
+ false
+ 4
+ false
+ 80
+ true
+ true
+ 1
+ true
+ false
+ 0
+ true
+ true
+ 0
+ 8
+ true
+ 1
+ true
+ true
+ true
+ false
+
+
+
+ ProjectExplorer.Project.PluginSettings
+
+
+
+ ProjectExplorer.Project.Target.0
+
+ Desktop Qt 5.12.5 GCC 64bit
+ Desktop Qt 5.12.5 GCC 64bit
+ qt.qt5.5125.gcc_64_kit
+ 3
+ 0
+ 0
+
+ /home/denali/Project/tmp/build/denali-Desktop_Qt_5_12_5_GCC_64bit-Debug
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ false
+ true
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Debug
+ Debug
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+ true
+
+
+ /home/denali/Project/tmp/build/denali-Desktop_Qt_5_12_5_GCC_64bit-Release
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ false
+
+ false
+ false
+ true
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Release
+ Release
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+
+ /home/denali/Project/tmp/build/denali-Desktop_Qt_5_12_5_GCC_64bit-Profile
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ true
+ true
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Profile
+ Profile
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+
+ /home/denali/Project/tmp/build/unittest/tst_canbus
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+ CONFIG+=tst_canbus CONFIG+=CodeCoverage
+ false
+ true
+ true
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+ LINK=csg++ AR=csar CXX=csg++ CC=csgcc -j4
+
+ false
+
+
+ true
+
+ %{buildDir}/denali
+ %{buildDir}
+ Custom Process Step
+
+ ProjectExplorer.ProcessStep
+
+
+ true
+ -m denali.csmes -t UnitTests denali.csexe
+ cmcsexeimport
+ %{buildDir}
+ Custom Process Step
+
+ ProjectExplorer.ProcessStep
+
+
+ true
+ --csmes=denali.csmes --html=Coverage/index
+ cmreport
+ %{buildDir}
+ Custom Process Step
+
+ ProjectExplorer.ProcessStep
+
+
+ true
+ --csmes=denali.csmes --csv-excel=Coverage/coverage.csv
+ cmreport
+ %{buildDir}
+ Custom Process Step
+
+ ProjectExplorer.ProcessStep
+
+ 6
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ PATH=/opt/SquishCoco/bin:/opt/SquishCoco/wrapper/bin:/opt/Qt5.12.5/5.12.5/gcc_64/bin:/usr/bin:/home/denali/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
+
+ Test
+ tst_canbus
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+ true
+
+ 4
+
+
+ 0
+ Deploy
+
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+ Deploy Configuration
+
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+
+ dwarf
+
+ cpu-cycles
+
+
+ 250
+ -F
+ true
+ 4096
+ false
+ false
+ 1000
+
+ true
+
+ false
+ false
+ false
+ false
+ true
+ 0.01
+ 10
+ true
+ kcachegrind
+ 1
+ 25
+
+ 1
+ true
+ false
+ true
+ valgrind
+
+ 0
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
+ 11
+ 12
+ 13
+ 14
+
+ 2
+
+ denali
+
+ Qt4ProjectManager.Qt4RunConfiguration:/home/denali/Project/application/denali.pro
+
+ 3768
+ false
+ true
+ true
+ false
+ true
+ false
+
+ /home/denali/Project/tmp/build/unittest/tst_canbus
+
+ 1
+
+
+
+ ProjectExplorer.Project.Target.1
+
+ Qt 5.12.5 (iMX8)
+ Qt 5.12.5 (iMX8)
+ {5d6458ef-f917-4aef-a092-c77bbe106149}
+ 1
+ 0
+ 0
+
+ /home/denali/Project/tmp/build/denali-Qt_5_12_5_iMX8-Debug
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ false
+ false
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Debug
+ Debug
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+ true
+
+
+ /home/denali/Project/tmp/build/denali-Qt_5_12_5_iMX8-Release
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ false
+
+ false
+ false
+ true
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Release
+ Release
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+
+ /home/denali/Project/tmp/build/denali-Qt_5_12_5_iMX8-Profile
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ true
+ true
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+ false
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+ false
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Profile
+ Profile
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+ 3
+
+
+
+ true
+ Check for free disk space
+
+ RemoteLinux.CheckForFreeDiskSpaceStep
+
+
+
+
+ /
+ 5242880
+
+
+
+
+ true
+ Kill current application instance
+
+ RemoteLinux.KillAppStep
+
+
+
+
+
+
+
+
+ true
+ Deploy files via rsync
+
+ RemoteLinux.RsyncDeployStep
+
+
+
+
+
+
+ -av
+ false
+
+ 3
+ Deploy
+
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+ Deploy to Remote Linux Host
+
+ DeployToGenericLinux
+
+ 1
+
+
+ dwarf
+
+ cpu-cycles
+
+
+ 250
+ -F
+ true
+ 4096
+ false
+ false
+ 1000
+
+ true
+
+ false
+ false
+ false
+ false
+ true
+ 0.01
+ 10
+ true
+ kcachegrind
+ 1
+ 25
+
+ 1
+ true
+ false
+ true
+ valgrind
+
+ 0
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
+ 11
+ 12
+ 13
+ 14
+
+ 1
+
+
+ denali (on Generic Linux Device (iMX8))
+ RemoteLinuxRunConfiguration:/home/denali/Project/application/denali.pro
+ 1
+
+ false
+
+ 3768
+ false
+ true
+ false
+ false
+ true
+ false
+
+
+ :0
+
+ 1
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 2
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 22
+
+
+ Version
+ 22
+
+
Index: main.cpp
===================================================================
diff -u -rd3f98384e9400f8acb84c88dee75f1c480986998 -r561055268da68e24fe91a1148b76bf1785dae14d
--- main.cpp (.../main.cpp) (revision d3f98384e9400f8acb84c88dee75f1c480986998)
+++ main.cpp (.../main.cpp) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -36,8 +36,8 @@
#include "guicontroller.h"
#ifdef UNIT_TEST
- #include "unittests/unittests.h"
- QTEST_MAIN(unittests)
+ #include TEST_CLASS_INCLUDE
+ QTEST_MAIN(TEST_CLASS_NAME)
#else
/*! \brief Application Initialization\n
* Some part of the application need to be initialized out of any thread.
Index: sources/canbus/caninterface.cpp
===================================================================
diff -u -rd3f98384e9400f8acb84c88dee75f1c480986998 -r561055268da68e24fe91a1148b76bf1785dae14d
--- sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision d3f98384e9400f8acb84c88dee75f1c480986998)
+++ sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -247,5 +247,6 @@
void CanInterface::onFrameTransmit(const QCanBusFrame &vFrame)
{
bool ok = transmit(vFrame);
+ consoleOut(vFrame);
emit didFrameTransmit(ok);
}
Index: sources/canbus/caninterface.h
===================================================================
diff -u -rc5389647e2259e67f8e6d923f3481d7d3f4eab68 -r561055268da68e24fe91a1148b76bf1785dae14d
--- sources/canbus/caninterface.h (.../caninterface.h) (revision c5389647e2259e67f8e6d923f3481d7d3f4eab68)
+++ sources/canbus/caninterface.h (.../caninterface.h) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -24,7 +24,7 @@
#define _CanInterface CanInterface::I()
// forward declarations
-class unittests;
+class tst_canbus;
// namespace
namespace Can {
@@ -43,7 +43,7 @@
Q_OBJECT
// friends
- friend class ::unittests;
+ friend class ::tst_canbus;
// constants
const char *_canType = "socketcan";
Index: sources/canbus/frameinterface.h
===================================================================
diff -u -rd3f98384e9400f8acb84c88dee75f1c480986998 -r561055268da68e24fe91a1148b76bf1785dae14d
--- sources/canbus/frameinterface.h (.../frameinterface.h) (revision d3f98384e9400f8acb84c88dee75f1c480986998)
+++ sources/canbus/frameinterface.h (.../frameinterface.h) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -28,7 +28,7 @@
#define _FrameInterface FrameInterface::I()
// forward declarations
-class unittests;
+class tst_canbus;
// namespace
using namespace Gui;
@@ -46,7 +46,7 @@
Q_OBJECT
// friends
- friend class ::unittests;
+ friend class ::tst_canbus;
/*!
* \brief The ChannelGroup enum
Index: sources/canbus/messagebuilder.cpp
===================================================================
diff -u -rc5389647e2259e67f8e6d923f3481d7d3f4eab68 -r561055268da68e24fe91a1148b76bf1785dae14d
--- sources/canbus/messagebuilder.cpp (.../messagebuilder.cpp) (revision c5389647e2259e67f8e6d923f3481d7d3f4eab68)
+++ sources/canbus/messagebuilder.cpp (.../messagebuilder.cpp) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -90,7 +90,7 @@
vPayload += mAction & 0xFF;// low byte
} else {
QString mHexString = Format::toHexString(vAction, false, 3);
- qDebug() << "ERROR :" << tr("Not enough data has been provided for the Message ID '%1'").arg(mHexString);
+ qDebug() << "ERROR :" << tr("Incorrect Action ID '%1'").arg(mHexString);
return false;
}
return true;
@@ -107,12 +107,6 @@
bool MessageBuilder::addData(QByteArray &vPayload, GuiActionType vAction, const QByteArray &vData)
{
quint8 len = payloadLen[vAction];
- if (vData.length() < len) {
- QString mHexString = Format::toHexString(vAction, false, 3);
- qDebug() << "ERROR :" << tr("Not enough data has been provided for the Message ID '%1'").arg(mHexString);
- qDebug() << vData.toHex('.');
- return false;
- }
// if len has been set to max(255)
// it means it has no limit and can be as long as 255 bytes
if (len == eLenMaxData) {
@@ -122,6 +116,12 @@
len = vData.length();
}
}
+ if (vData.length() < len) {
+ QString mHexString = Format::toHexString(vAction, false, 3);
+ qDebug() << "ERROR :" << tr("Not enough data has been provided for the Message ID '%1'").arg(mHexString);
+ qDebug() << vData.toHex('.');
+ return false;
+ }
vPayload += len;
vPayload += vData.mid(0, len); // Adding required Data
return true;
Index: sources/canbus/messagedispatcher.h
===================================================================
diff -u -r4b9619614f0a9deb0438a803c057918b94aacbec -r561055268da68e24fe91a1148b76bf1785dae14d
--- sources/canbus/messagedispatcher.h (.../messagedispatcher.h) (revision 4b9619614f0a9deb0438a803c057918b94aacbec)
+++ sources/canbus/messagedispatcher.h (.../messagedispatcher.h) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -25,6 +25,9 @@
// define
#define _MessageDispatcher MessageDispatcher::I()
+// forward declarations
+class tst_canbus;
+
using namespace Gui;
namespace Can {
/*!
@@ -84,6 +87,9 @@
MessageBuilder _builder;
MessageInterpreter _interpreter;
+ // friends
+ friend class ::tst_canbus;
+
// Singleton
SINGLETON_DECL(MessageDispatcher)
public:
Index: sources/canbus/messageinterpreter.cpp
===================================================================
diff -u -rc5389647e2259e67f8e6d923f3481d7d3f4eab68 -r561055268da68e24fe91a1148b76bf1785dae14d
--- sources/canbus/messageinterpreter.cpp (.../messageinterpreter.cpp) (revision c5389647e2259e67f8e6d923f3481d7d3f4eab68)
+++ sources/canbus/messageinterpreter.cpp (.../messageinterpreter.cpp) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -97,6 +97,7 @@
case eChlid_HD_Alarm:
case eChlid_HD_Sync:
ok = interpretMessage_HD(vMessage, vActionId, vData);
+ break;
default:
break;
}
Index: sources/utility/format.cpp
===================================================================
diff -u -rc5389647e2259e67f8e6d923f3481d7d3f4eab68 -r561055268da68e24fe91a1148b76bf1785dae14d
--- sources/utility/format.cpp (.../format.cpp) (revision c5389647e2259e67f8e6d923f3481d7d3f4eab68)
+++ sources/utility/format.cpp (.../format.cpp) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -18,6 +18,7 @@
}
+
QString Format::toHexString(quint16 vValue, bool vWith0x, quint8 vLen) {
if ( vWith0x ) {
return "0x" + QString("%1").arg(vValue,0,16).rightJustified(vLen, '0').toUpper();
@@ -26,6 +27,11 @@
}
}
+QByteArray Format::toHexString(const QByteArray &vData, char separator)
+{
+ return vData.toHex(separator).toUpper();
+}
+
QByteArray Format::fromVariant(const QVariant &vData)
{
QByteArray mData;
@@ -36,3 +42,4 @@
}
return mData;
}
+
Index: sources/utility/format.h
===================================================================
diff -u -rfee7fabf49befb065c89248c19e15efc9ca194e4 -r561055268da68e24fe91a1148b76bf1785dae14d
--- sources/utility/format.h (.../format.h) (revision fee7fabf49befb065c89248c19e15efc9ca194e4)
+++ sources/utility/format.h (.../format.h) (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -23,8 +23,8 @@
{
Format();
public:
- static QString toHexString(quint16 vValue, bool vWith0x = true, quint8 vLen = 4);
- static QByteArray fromVariant(const QVariant &vData);
-
+ static QString toHexString(quint16 vValue, bool vWith0x = true, quint8 vLen = 4);
+ static QByteArray toHexString(const QByteArray &vData, char separator = '.');
+ static QByteArray fromVariant(const QVariant &vData);
};
Index: unittests/tst_canbus.cpp
===================================================================
diff -u
--- unittests/tst_canbus.cpp (revision 0)
+++ unittests/tst_canbus.cpp (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -0,0 +1,277 @@
+/*!
+ *
+ * Copyright (c) 2019-2019 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 tst_canbus.cpp
+ * date 11/21/2019
+ * author Behrouz NematiPour
+ *
+ */
+#include "tst_canbus.h"
+
+//using namespace Can;
+// Project
+#include "guiglobals.h"
+#include "caninterface.h"
+#include "frameinterface.h"
+#include "messagedispatcher.h"
+#include "applicationcontroller.h"
+#include "guicontroller.h"
+#include "maintimer.h"
+#include "format.h"
+
+tst_canbus::tst_canbus(QObject *parent) : QObject(parent) { }
+
+void tst_canbus::initTestCase()
+{
+}
+
+void tst_canbus::initTestCase_data()
+{
+}
+
+void tst_canbus::init()
+{
+ _emited = false;
+}
+
+void tst_canbus::tst_CanInterface_Connect_Error_Interface()
+{
+ QString mTr = tr("Error: Connection");
+ Can::_CanInterface->_canInterface = "can1";
+ Can::_CanInterface ->init();
+ Can::_CanInterface ->enableConsoleOut(false);
+ QCOMPARE(Can::_CanInterface->status().left(mTr.length()), mTr);
+}
+
+void tst_canbus::tst_CanInterface_Connect_NoError()
+{
+ Can::_CanInterface->_canInterface = "can0";
+ Can::_CanInterface ->init();
+ Can::_CanInterface ->enableConsoleOut(true);
+ QString mTr = tr("Connected");
+ QCOMPARE(Can::_CanInterface->status().left(mTr.length()), mTr);
+
+ Can::_CanInterface->onFrameReceive ();
+}
+
+void tst_canbus::tst_FrameInterface_Init()
+{
+ Can::_FrameInterface->init();
+ Can::_MessageDispatcher->init();
+ Can::_MessageDispatcher->enableConsoleOut(true);
+
+ connect(Can::_MessageDispatcher, &Can::MessageDispatcher::didFrameTransmit, [=](Can_Id vCanId , const QByteArray &vPayload) {
+ _emited = true;
+ QCOMPARE(Format::toHexString(vPayload), _expected);
+ });
+ connect(Can::_MessageDispatcher, &Can::MessageDispatcher::didActionReceive, [=](GuiActionType vAction , const QVariantList &vData ) {
+ _emited = true;
+ QCOMPARE(vAction, _action);
+ QCOMPARE(vData , _data );
+ });
+}
+
+void tst_canbus::tst_FrameInterface_ActionTransmit_KeepAlive()
+{
+ _expected = "A5.07.00.00.E3.00.00.00";
+ _MessageDispatcher->onActionTransmit(Gui::GuiActionType::KeepAlive, {});
+ QVERIFY(_emited);
+}
+
+void tst_canbus::tst_FrameInterface_TransmitFrame_LongerData()
+{
+ _expected = QByteArray("123456789");
+ _FrameInterface->transmitFrame(Can_Id::eChlid_HD, _expected);
+ QCOMPARE(_emited, false); //there is no signal call - Code Coverage only : Error : "Payload can't be larger than 8 bytes"
+}
+
+void tst_canbus::tst_FrameInterface_ActionTransmit_PowerOff_Accepted()
+{
+ _expected = "A5.01.00.01.01.5E.00.00";
+ QVariantList mData {static_cast(Gui::GuiActionData::Accepted)};
+ _MessageDispatcher->onActionTransmit(Gui::GuiActionType::PowerOff, mData);
+ QVERIFY(_emited);
+}
+
+void tst_canbus::tst_FrameInterface_ActionTransmit_PowerOff_Rejected()
+{
+ _expected = "A5.01.00.01.02.0D.00.00";
+ QVariantList mData {static_cast(Gui::GuiActionData::Rejected)};
+ _MessageDispatcher->onActionTransmit(Gui::GuiActionType::PowerOff, mData);
+ QVERIFY(_emited);
+}
+
+void tst_canbus::tst_FrameInterface_ActionTransmit_PowerOff()
+{
+ _expected = "A5.01.00.01.00.6F.00.00";
+ QVariantList mData {static_cast(Gui::GuiActionData::NoData)};
+ _MessageDispatcher->onActionTransmit(Gui::GuiActionType::PowerOff, mData);
+ QVERIFY(_emited);
+}
+
+void tst_canbus::tst_FrameInterface_ActionTransmit_LongFF()
+{
+ // An example of longest data transmission by Gui::GuiActionType::String
+ // which can be as long as 255 byte.
+ _expected = "A5.FF.FF.03.41.42.43.EF";
+ QVariantList mData {"ABC"};
+ _MessageDispatcher->onActionTransmit(Gui::GuiActionType::String, mData);
+ QVERIFY(_emited);
+}
+
+void tst_canbus::tst_FrameInterface_ActionTransmit_Unknown()
+{
+ _expected = "";
+ _MessageDispatcher->onActionTransmit(Gui::GuiActionType::Unknown, {});
+ QCOMPARE(_emited, false); // should not emit the signal due to unknown action
+}
+
+void tst_canbus::tst_FrameInterface_FrameReceived_PowerOff()
+{
+ _action = Gui::GuiActionType::PowerOff;
+ _data = {0};
+ QCanBusFrame mFrame;
+ QString mPayload;
+ mFrame.setFrameId(Can::Can_Id::eChlid_HD);
+ mPayload = "A5.01.00.01.00.6F.00.00";
+ mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1()));
+ emit Can::_CanInterface->didFrameReceive(mFrame);
+ QVERIFY(_emited);
+}
+
+void tst_canbus::tst_FrameInterface_FrameReceived_PowerOff_Timeout()
+{
+ _action = Gui::GuiActionType::PowerOff;
+ _data = {1};
+ QCanBusFrame mFrame;
+ QString mPayload;
+ mFrame.setFrameId(Can::Can_Id::eChlid_HD);
+ mPayload = "A5.01.00.01.01.5E.00.00";
+ mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1()));
+ emit Can::_CanInterface->didFrameReceive(mFrame);
+ QVERIFY(_emited);
+}
+
+void tst_canbus::tst_FrameInterface_FrameReceived_Channel_NotListen()
+{
+ _action = Gui::GuiActionType::PowerOff;
+ _data = {1};
+ QCanBusFrame mFrame;
+ QString mPayload;
+ mFrame.setFrameId(Can::Can_Id::eChlid_HD_DG);
+ mPayload = "A5.01.00.01.01.5E.00.00";
+ mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1()));
+ emit Can::_CanInterface->didFrameReceive(mFrame);
+ QCOMPARE(_emited, false); // should not be emitted due to not listening channel
+}
+
+void tst_canbus::tst_FrameInterface_FrameReceived_Channel_Incorrect()
+{
+ _action = Gui::GuiActionType::PowerOff;
+ _data = {1};
+ QCanBusFrame mFrame;
+ QString mPayload;
+ mFrame.setFrameId(0x999);
+ mPayload = "A5.01.00.01.01.5E.00.00";
+ mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1()));
+ emit Can::_CanInterface->didFrameReceive(mFrame);
+ QCOMPARE(_emited, false); // should not be emitted due to not listening channel
+}
+
+void tst_canbus::tst_FrameInterface_FrameReceived_CRC_Error()
+{
+ _action = Gui::GuiActionType::PowerOff;
+ _data = {0};
+ QCanBusFrame mFrame;
+ QString mPayload;
+ mFrame.setFrameId(Can::Can_Id::eChlid_HD);
+ mPayload = "A5.01.00.01.00.66.00.00";
+ mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1()));
+ emit Can::_CanInterface->didFrameReceive(mFrame);
+ QCOMPARE(_emited, false); // Should not emit due to crc error
+}
+
+void tst_canbus::tst_FrameInterface_FrameReceived_ShortFrame_Error()
+{
+ _action = Gui::GuiActionType::PowerOff;
+ _data = {0};
+ QCanBusFrame mFrame;
+ QString mPayload;
+ mFrame.setFrameId(Can::Can_Id::eChlid_HD);
+ mPayload = "A5.01.00.01.00.6F";
+ mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1()));
+ emit Can::_CanInterface->didFrameReceive(mFrame);
+ QVERIFY(_emited); // Should not emit due to crc error
+}
+
+void tst_canbus::tst_FrameInterface_FrameReceived_LongFrame_Error()
+{
+ _action = Gui::GuiActionType::PowerOff;
+ _data = {0};
+ QCanBusFrame mFrame;
+ QString mPayload;
+ mFrame.setFrameId(Can::Can_Id::eChlid_HD);
+ mPayload = "A5.01.00.01.00.6F.FF.FF.FF";
+ mFrame.setPayload(QByteArray::fromHex(mPayload.remove(QLatin1Char('.')).toLatin1()));
+ emit Can::_CanInterface->didFrameReceive(mFrame);
+ QVERIFY(_emited); // Should not emit due to crc error
+}
+
+void tst_canbus::tst_FrameInterface_FrameReceived_LongFrame_BloodFlow()
+{
+ _action = Gui::GuiActionType::BloodFlow;
+ _data = {500, 501.00, 100.00, 1000.00, -1001.25, 750.00};
+ QCanBusFrame mFrame;
+ mFrame.setFrameId(Can::Can_Id::eChlid_HD_Sync);
+ QStringList mPayloadList {
+ "a5.05.00.18.f4.01.00.00",
+ "00.80.fa.43.00.00.c8.42",
+ "00.00.7a.44.00.50.7a.c4",
+ "00.80.3b.44.88.00.00.00",
+ };
+ for ( QString payload : mPayloadList ) {
+ mFrame.setPayload(QByteArray::fromHex(payload.remove(QLatin1Char('.')).toLatin1()));
+ emit Can::_CanInterface->didFrameReceive(mFrame);
+ }
+ QVERIFY(_emited); // Should not emit due to crc error
+}
+
+void tst_canbus::tst_FrameInterface_FrameReceived_LongFrame_BloodFlow_LessData()
+{
+ _action = Gui::GuiActionType::BloodFlow;
+ _data = {500, 501.00, 100.00, 1000.00, -1001.25, 750.00};
+ QCanBusFrame mFrame;
+ mFrame.setFrameId(Can::Can_Id::eChlid_HD_Sync);
+ QStringList mPayloadList {
+ "a5.05.00.15.f4.01.00.00",
+ "00.80.fa.43.00.00.c8.42",
+ "00.00.7a.44.00.50.7a.c4",
+ "00.19.00.00.00.00.00.00",
+ };
+ for ( QString payload : mPayloadList ) {
+ mFrame.setPayload(QByteArray::fromHex(payload.remove(QLatin1Char('.')).toLatin1()));
+ emit Can::_CanInterface->didFrameReceive(mFrame);
+ }
+ QCOMPARE(_emited, false); // Should not emit due to - ERROR : "Incorrect data for Message ID (HD) '0x0500'"
+}
+
+void tst_canbus::cleanup()
+{
+ //disconnect(Can::_FrameInterface );
+ //disconnect(Can::_MessageDispatcher );
+ //Can::_CanInterface ->initConnections();
+ //Can::_FrameInterface ->initConnections();
+ //Can::_MessageDispatcher ->initConnections();
+}
+
+void tst_canbus::cleanupTestCase()
+{
+ Can::_CanInterface->quit();
+ QString mTr = tr("Disconnected");
+ QCOMPARE(Can::_CanInterface->status().left(mTr.length()), mTr);
+}
Index: unittests/tst_canbus.h
===================================================================
diff -u
--- unittests/tst_canbus.h (revision 0)
+++ unittests/tst_canbus.h (revision 561055268da68e24fe91a1148b76bf1785dae14d)
@@ -0,0 +1,62 @@
+/*!
+ *
+ * Copyright (c) 2019-2019 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 tst_canbus : public QObject
+{
+ Q_OBJECT
+
+ bool _emited = false ;
+ QByteArray _expected {} ;
+ QVariantList _data {} ;
+ int _action = -1 ;
+
+public:
+ explicit tst_canbus(QObject *parent = nullptr);
+
+private slots:
+ void initTestCase_data();
+
+ void initTestCase();
+ void init();
+
+ void tst_CanInterface_Connect_Error_Interface();
+ void tst_CanInterface_Connect_NoError();
+
+ void tst_FrameInterface_Init();
+
+ void tst_FrameInterface_ActionTransmit_KeepAlive();
+ void tst_FrameInterface_TransmitFrame_LongerData();
+ void tst_FrameInterface_ActionTransmit_PowerOff_Accepted();
+ void tst_FrameInterface_ActionTransmit_PowerOff_Rejected();
+ void tst_FrameInterface_ActionTransmit_PowerOff();
+ void tst_FrameInterface_ActionTransmit_LongFF();
+ void tst_FrameInterface_ActionTransmit_Unknown ();
+ void tst_FrameInterface_FrameReceived_PowerOff();
+ void tst_FrameInterface_FrameReceived_PowerOff_Timeout();
+ void tst_FrameInterface_FrameReceived_Channel_NotListen();
+ void tst_FrameInterface_FrameReceived_Channel_Incorrect();
+ void tst_FrameInterface_FrameReceived_CRC_Error();
+ void tst_FrameInterface_FrameReceived_ShortFrame_Error();
+ void tst_FrameInterface_FrameReceived_LongFrame_Error();
+ void tst_FrameInterface_FrameReceived_LongFrame_BloodFlow();
+ void tst_FrameInterface_FrameReceived_LongFrame_BloodFlow_LessData();
+
+ void cleanup();
+ void cleanupTestCase();
+};
+
Fisheye: Tag 561055268da68e24fe91a1148b76bf1785dae14d refers to a dead (removed) revision in file `unittests/unittests.cpp'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 561055268da68e24fe91a1148b76bf1785dae14d refers to a dead (removed) revision in file `unittests/unittests.h'.
Fisheye: No comparison available. Pass `N' to diff?