CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
candevice_test.cpp File Reference
#include "candevice.h"
#include <QApplication>
#include <QSignalSpy>
#include <QtSerialBus/QCanBusDevice>
#include <candeviceinterface.h>
#include <catch.hpp>
#include <context.h>
#include <fakeit.hpp>
#include <log.h>
Include dependency graph for candevice_test.cpp:

Macros

#define CATCH_CONFIG_RUNNER
 
#define testConfig_Expect0(mock, dev, str)
 
#define testConfig_Expect1(mock, dev, key, val, str)
 

Functions

 Q_DECLARE_METATYPE (QCanBusFrame)
 
 TEST_CASE ("Initialization failed", "[candevice]")
 
 TEST_CASE ("Initialization succeeded", "[candevice]")
 
 TEST_CASE ("Start failed", "[candevice]")
 
 TEST_CASE ("Start failed - could not connect to device", "[candevice]")
 
 TEST_CASE ("Start succeeded", "[candevice]")
 
 TEST_CASE ("Stop uninitialized", "[candevice]")
 
 TEST_CASE ("Stop initialized", "[candevice]")
 
 TEST_CASE ("Config changed", "[candevice]")
 
 TEST_CASE ("writeFrame results in error", "[candevice]")
 
 TEST_CASE ("sendFrame, writeframe returns true, no signal emitted", "[candevice]")
 
 TEST_CASE ("sendFrame, no device available, frameSent is not emitted", "[candevice]")
 
 TEST_CASE ("sendFrame defers FrameSent until backend emits frameWritten", "[candevice]")
 
 TEST_CASE ("Emits all available frames when notified by backend", "[candevice]")
 
 TEST_CASE ("WriteError causes emitting frameSent with frameSent=false", "[candevice]")
 
 TEST_CASE ("read configuration to json format", "[candevice]")
 
 TEST_CASE ("setConfig using JSON read with QObject", "[candevice]")
 
 TEST_CASE ("Stubbed methods", "[candevice]")
 
void prepareConfigTestMock (fakeit::Mock< CanDeviceInterface > &deviceMock, std::vector< std::pair< int, QVariant > > &ver)
 
void testConfig (fakeit::Mock< CanDeviceInterface > &deviceMock, CanDevice &canDevice, const QString &configStr)
 
 TEST_CASE ("Config parameter - invalid format and unsupported", "[candevice]")
 
 TEST_CASE ("Config parameter - LoopbackKey", "[candevice]")
 
 TEST_CASE ("Config parameter - ReceiveOwnKey", "[candevice]")
 
 TEST_CASE ("Config parameter - CanFdKey", "[candevice]")
 
 TEST_CASE ("Config parameter - BitRateKey", "[candevice]")
 
 TEST_CASE ("Config parameter - UserKey", "[candevice]")
 
 TEST_CASE ("Config parameter - multiple keys", "[candevice]")
 
int main (int argc, char *argv[])
 

Variables

std::shared_ptr< spdlog::logger > kDefaultLogger
 

Macro Definition Documentation

◆ CATCH_CONFIG_RUNNER

#define CATCH_CONFIG_RUNNER

◆ testConfig_Expect0

#define testConfig_Expect0 (   mock,
  dev,
  str 
)
Value:
testConfig(mock, dev, str); \
fakeit::Verify(Method(mock, setConfigurationParameter)).Exactly(0);
void testConfig(fakeit::Mock< CanDeviceInterface > &deviceMock, CanDevice &canDevice, const QString &configStr)
Definition candevice_test.cpp:428

◆ testConfig_Expect1

#define testConfig_Expect1 (   mock,
  dev,
  key,
  val,
  str 
)
Value:
testConfig(mock, dev, str); \
fakeit::Verify(Method(mock, setConfigurationParameter)).Exactly(1); \
REQUIRE(v.back().first == key); \
REQUIRE(v.back().second == val);

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

◆ prepareConfigTestMock()

void prepareConfigTestMock ( fakeit::Mock< CanDeviceInterface > &  deviceMock,
std::vector< std::pair< int, QVariant > > &  ver 
)

◆ Q_DECLARE_METATYPE()

Q_DECLARE_METATYPE ( QCanBusFrame  )

◆ TEST_CASE() [1/24]

TEST_CASE ( "Config changed"  ,
""  [candevice] 
)

◆ TEST_CASE() [2/24]

TEST_CASE ( "Config parameter - BitRateKey"  ,
""  [candevice] 
)

◆ TEST_CASE() [3/24]

TEST_CASE ( "Config parameter - CanFdKey"  ,
""  [candevice] 
)

◆ TEST_CASE() [4/24]

TEST_CASE ( "Config parameter - invalid format and unsupported"  ,
""  [candevice] 
)

◆ TEST_CASE() [5/24]

TEST_CASE ( "Config parameter - LoopbackKey"  ,
""  [candevice] 
)

◆ TEST_CASE() [6/24]

TEST_CASE ( "Config parameter - multiple keys"  ,
""  [candevice] 
)

◆ TEST_CASE() [7/24]

TEST_CASE ( "Config parameter - ReceiveOwnKey"  ,
""  [candevice] 
)

◆ TEST_CASE() [8/24]

TEST_CASE ( "Config parameter - UserKey"  ,
""  [candevice] 
)

◆ TEST_CASE() [9/24]

TEST_CASE ( "Emits all available frames when notified by backend"  ,
""  [candevice] 
)

◆ TEST_CASE() [10/24]

TEST_CASE ( "Initialization failed"  ,
""  [candevice] 
)

◆ TEST_CASE() [11/24]

TEST_CASE ( "Initialization succeeded"  ,
""  [candevice] 
)

◆ TEST_CASE() [12/24]

TEST_CASE ( "read configuration to json format"  ,
""  [candevice] 
)

◆ TEST_CASE() [13/24]

TEST_CASE ( "sendFrame defers FrameSent until backend emits frameWritten"  ,
""  [candevice] 
)

◆ TEST_CASE() [14/24]

TEST_CASE ( sendFrame,
no device  available,
frameSent is not emitted"  ,
""  [candevice] 
)

◆ TEST_CASE() [15/24]

TEST_CASE ( sendFrame,
writeframe returns  true,
no signal emitted"  ,
""  [candevice] 
)

◆ TEST_CASE() [16/24]

TEST_CASE ( "setConfig using JSON read with QObject"  ,
""  [candevice] 
)

◆ TEST_CASE() [17/24]

TEST_CASE ( "Start failed - could not connect to device"  ,
""  [candevice] 
)

◆ TEST_CASE() [18/24]

TEST_CASE ( "Start failed"  ,
""  [candevice] 
)

◆ TEST_CASE() [19/24]

TEST_CASE ( "Start succeeded"  ,
""  [candevice] 
)

◆ TEST_CASE() [20/24]

TEST_CASE ( "Stop initialized"  ,
""  [candevice] 
)

◆ TEST_CASE() [21/24]

TEST_CASE ( "Stop uninitialized"  ,
""  [candevice] 
)

◆ TEST_CASE() [22/24]

TEST_CASE ( "Stubbed methods"  ,
""  [candevice] 
)

◆ TEST_CASE() [23/24]

TEST_CASE ( )

◆ TEST_CASE() [24/24]

TEST_CASE ( "writeFrame results in error"  ,
""  [candevice] 
)

◆ testConfig()

void testConfig ( fakeit::Mock< CanDeviceInterface > &  deviceMock,
CanDevice canDevice,
const QString &  configStr 
)

Variable Documentation

◆ kDefaultLogger

std::shared_ptr<spdlog::logger> kDefaultLogger