Skip to content

Commit

Permalink
Rework tests to make them work on Windows and macOS as well; Remove c…
Browse files Browse the repository at this point in the history
…ompiler warnings for Clang and GCC; Remove deprecated Qt calls; Set Qt minimal version to 5.12; Bump CANdevStudio version up to v1.2.1

Signed-off-by: Remigiusz Kołłątaj <remigiusz.kollataj@gmail.com>
  • Loading branch information
rkollataj committed Jun 25, 2021
1 parent 96d4c60 commit fa2d90b
Show file tree
Hide file tree
Showing 28 changed files with 184 additions and 82 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest
run: ctest --output-on-failure
env:
QT_QPA_PLATFORM: offscreen

Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest
run: ctest --output-on-failure
env:
QT_QPA_PLATFORM: offscreen

Expand Down Expand Up @@ -183,14 +183,20 @@ jobs:

- name: Configure CMake
working-directory: ${{github.workspace}}/build
run: cmake .. -DCMAKE_BUILD_TYPE=Release -DWITH_TESTS=OFF -DCMAKE_PREFIX_PATH="$(brew --prefix qt5)/lib/cmake"
run: cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$(brew --prefix qt5)/lib/cmake"
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}

- name: Build
working-directory: ${{github.workspace}}/build
run: make -j4

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest --output-on-failure
env:
QT_QPA_PLATFORM: offscreen

- name: Create packages
if: startsWith(github.ref, 'refs/heads/')
working-directory: ${{github.workspace}}/build
Expand Down Expand Up @@ -260,7 +266,13 @@ jobs:

- name: Build
working-directory: ${{github.workspace}}/build
run: cmake --build . --config Release
run: cmake --build . --config Release -- /m

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C Release --output-on-failure
env:
QT_QPA_PLATFORM: offscreen

- name: Create Packages
if: startsWith(github.ref, 'refs/heads/')
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/CANdb
2 changes: 1 addition & 1 deletion 3rdParty/catch
Submodule catch updated 261 files
2 changes: 1 addition & 1 deletion 3rdParty/nodeeditor
2 changes: 1 addition & 1 deletion 3rdParty/qtCannelloniCanBus
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(CANdevStudio CXX)

set(VERSION_MAJOR 1)
set(VERSION_MINOR 2)
set(VERSION_PATCH 1)
set(VERSION_PATCH 2)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
Expand All @@ -17,6 +17,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)

option(WITH_COVERAGE "Build with coverage" OFF)
option(WITH_TESTS "Build with test" ON)
option(WITH_TOOLS "Build tools directory" OFF)
option(DEV_BUILD "Development build will include GIT hash and branch to versioning" ON)
option(STANDALONE "Builds self containing package including Qt libs" OFF)
Expand All @@ -27,7 +28,6 @@ endif()
message(STATUS "CMAKE_INSTALL_LIBDIR: '${CMAKE_INSTALL_LIBDIR}'")

if(UNIX)
option(WITH_TESTS "Build with test" ON)
if(STANDALONE)
set(INSTALL_DEST_LIB CANdevStudio)
set(INSTALL_DEST_BIN CANdevStudio)
Expand All @@ -38,14 +38,12 @@ if(UNIX)
set(INSTALL_DEST_PLUG ${CMAKE_INSTALL_LIBDIR}/qt/plugins/canbus)
endif()
else()
option(WITH_TESTS "Build with test" OFF)

set(GUI_TYPE WIN32)
set(INSTALL_DEST_LIB CANdevStudio)
set(INSTALL_DEST_BIN CANdevStudio)
endif()

set(QT_REQUIRED_VERSION "5.6")
set(QT_REQUIRED_VERSION "5.12")
find_package(Qt5Core ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5SerialBus ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Widgets ${QT_REQUIRED_VERSION} REQUIRED)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ If CMake failed to find Qt in your system:
```
cd CANdevStudio/build
rm -rf *
cmake .. -DCMAKE_PREFIX_PATH=/home/genivi/Qt5.8.0/5.8/gcc_64
cmake .. -DCMAKE_PREFIX_PATH=/home/genivi/Qt5.12.0/5.12.0/gcc_64
make
```
### Windows
Expand Down Expand Up @@ -310,7 +310,6 @@ CanDevice component can be configured using "configuration" property:
* Keys names are case sensitive, values are case insensitive
* Configuration keys are taken from [ConfigurationKey enum](https://doc.qt.io/qt-5/qcanbusdevice.html#ConfigurationKey-enum).
* RawFilterKey and ErrorFilterKey are currently not supported
* DataBitRateKey is available since Qt 5.9
* Whitespaces are ignored

E.g.
Expand Down
4 changes: 2 additions & 2 deletions src/common/propertyfields.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class PropertyFieldCombo : public PropertyField {
_cb->setEditable(editable);
_cb->setFrame(false);
layout()->addWidget(_cb);
connect(_cb, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged), this,
&PropertyFieldCombo::currentTextChanged);
connect(_cb, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
[this](int) { emit currentTextChanged(_cb->currentText()); });
}

void setPropText(const QString& text) override
Expand Down
46 changes: 34 additions & 12 deletions src/components/candevice/tests/candevice_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ TEST_CASE("Initialization succeeded", "[candevice]")
Mock<CanDeviceInterface> deviceMock;
std::function<void()> rcvCbk;

Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setFramesWrittenCbk));
When(Method(deviceMock, setFramesReceivedCbk)).AlwaysDo([&](auto&& fn) { rcvCbk = fn; });
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand All @@ -79,6 +80,7 @@ TEST_CASE("Start failed", "[candevice]")
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;

Fake(Dtor(deviceMock));
When(Method(deviceMock, setFramesWrittenCbk)).Do([](const auto& cb) { cb(100); });
Fake(Method(deviceMock, setFramesReceivedCbk));
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand All @@ -96,6 +98,7 @@ TEST_CASE("Start failed - could not connect to device", "[candevice]")
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;

Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setFramesWrittenCbk));
Fake(Method(deviceMock, setFramesReceivedCbk));
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand Down Expand Up @@ -128,6 +131,7 @@ TEST_CASE("Start succeeded", "[candevice]")
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;

Fake(Dtor(deviceMock));
When(Method(deviceMock, setFramesWrittenCbk)).Do([](const auto& cb) { cb(100); });
Fake(Method(deviceMock, setFramesReceivedCbk));
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand All @@ -146,6 +150,7 @@ TEST_CASE("Stop uninitialized", "[candevice]")
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;

Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setParent));

CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };
Expand All @@ -158,6 +163,7 @@ TEST_CASE("Stop initialized", "[candevice]")
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;

Fake(Dtor(deviceMock));
When(Method(deviceMock, setFramesWrittenCbk)).Do([](const auto& cb) { cb(100); });
Fake(Method(deviceMock, setFramesReceivedCbk));
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand All @@ -178,6 +184,7 @@ TEST_CASE("Config changed", "[candevice]")
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;

Fake(Dtor(deviceMock));
When(Method(deviceMock, setFramesWrittenCbk)).Do([](const auto& cb) { cb(100); });
Fake(Method(deviceMock, setFramesReceivedCbk));
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand All @@ -199,6 +206,7 @@ TEST_CASE("writeFrame results in error", "[candevice]")
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;

Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setFramesWrittenCbk));
Fake(Method(deviceMock, setFramesReceivedCbk));
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand All @@ -221,6 +229,7 @@ TEST_CASE("sendFrame, writeframe returns true, no signal emitted", "[candevice]"
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;

Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setFramesWrittenCbk));
Fake(Method(deviceMock, setFramesReceivedCbk));
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand Down Expand Up @@ -260,6 +269,7 @@ TEST_CASE("sendFrame defers FrameSent until backend emits frameWritten", "[cande
const auto frame = QCanBusFrame{ 0x12345678, QByteArray{ "\x50\x30\10" } };
CanDeviceInterface::framesWritten_t writtenCbk;

Fake(Dtor(deviceMock));
When(Method(deviceMock, setFramesWrittenCbk)).Do([&](auto&& fn) { writtenCbk = fn; });
Fake(Method(deviceMock, setFramesReceivedCbk));
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand Down Expand Up @@ -291,6 +301,7 @@ TEST_CASE("Emits all available frames when notified by backend", "[candevice]")
auto currentFrame = frames.begin();
CanDeviceInterface::framesReceived_t receivedCbk;

Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setFramesWrittenCbk));
When(Method(deviceMock, setFramesReceivedCbk)).Do([&](auto&& fn) { receivedCbk = fn; });
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand Down Expand Up @@ -326,6 +337,7 @@ TEST_CASE("WriteError causes emitting frameSent with frameSent=false", "[candevi
const auto frame = QCanBusFrame{ 0x12345678, QByteArray{ "\x50\x30\10" } };
CanDeviceInterface::errorOccurred_t errorCbk;

Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setFramesWrittenCbk));
Fake(Method(deviceMock, setFramesReceivedCbk));
When(Method(deviceMock, setErrorOccurredCbk)).Do([&](auto&& fn) { errorCbk = fn; });
Expand All @@ -351,17 +363,19 @@ TEST_CASE("read configuration to json format", "[candevice]")
{
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;
Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setParent));
CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };
QJsonObject config = canDevice.getConfig();
REQUIRE(config.count() == canDevice.getSupportedProperties().size());
REQUIRE(config.count() == static_cast<int>(canDevice.getSupportedProperties().size()));
}

TEST_CASE("setConfig using JSON read with QObject", "[candevice]")
{
using namespace fakeit;

Mock<CanDeviceInterface> deviceMock;
Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setParent));
CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };

Expand All @@ -386,18 +400,19 @@ TEST_CASE("Stubbed methods", "[candevice]")
{
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;
Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setParent));
CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };

REQUIRE(canDevice.mainWidget() == nullptr);
REQUIRE(canDevice.mainWidgetDocked() == true);
}

auto prepareConfigTestMock(std::vector<std::pair<int, QVariant>>& ver)
void prepareConfigTestMock(fakeit::Mock<CanDeviceInterface>& deviceMock, std::vector<std::pair<int, QVariant>>& ver)
{
using namespace fakeit;
Mock<CanDeviceInterface> deviceMock;

Fake(Dtor(deviceMock));
Fake(Method(deviceMock, setFramesWrittenCbk));
Fake(Method(deviceMock, setFramesReceivedCbk));
Fake(Method(deviceMock, setErrorOccurredCbk));
Expand All @@ -408,7 +423,6 @@ auto prepareConfigTestMock(std::vector<std::pair<int, QVariant>>& ver)
When(Method(deviceMock, setConfigurationParameter)).AlwaysDo([&](int key, const QVariant& v) {
ver.push_back(std::make_pair(key, v));
});
return deviceMock;
}

void testConfig(fakeit::Mock<CanDeviceInterface>& deviceMock, CanDevice& canDevice, const QString& configStr)
Expand Down Expand Up @@ -440,7 +454,8 @@ TEST_CASE("Config parameter - invalid format and unsupported", "[candevice]")
{
using namespace fakeit;
std::vector<std::pair<int, QVariant>> v;
auto&& deviceMock = prepareConfigTestMock(v);
Mock<CanDeviceInterface> deviceMock;
prepareConfigTestMock(deviceMock, v);

CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };

Expand All @@ -458,7 +473,8 @@ TEST_CASE("Config parameter - LoopbackKey", "[candevice]")
{
using namespace fakeit;
std::vector<std::pair<int, QVariant>> v;
auto&& deviceMock = prepareConfigTestMock(v);
Mock<CanDeviceInterface> deviceMock;
prepareConfigTestMock(deviceMock, v);

CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };

Expand All @@ -482,7 +498,8 @@ TEST_CASE("Config parameter - ReceiveOwnKey", "[candevice]")
{
using namespace fakeit;
std::vector<std::pair<int, QVariant>> v;
auto&& deviceMock = prepareConfigTestMock(v);
Mock<CanDeviceInterface> deviceMock;
prepareConfigTestMock(deviceMock, v);

CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };

Expand All @@ -506,7 +523,8 @@ TEST_CASE("Config parameter - CanFdKey", "[candevice]")
{
using namespace fakeit;
std::vector<std::pair<int, QVariant>> v;
auto&& deviceMock = prepareConfigTestMock(v);
Mock<CanDeviceInterface> deviceMock;
prepareConfigTestMock(deviceMock, v);

CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };

Expand All @@ -530,7 +548,8 @@ TEST_CASE("Config parameter - BitRateKey", "[candevice]")
{
using namespace fakeit;
std::vector<std::pair<int, QVariant>> v;
auto&& deviceMock = prepareConfigTestMock(v);
Mock<CanDeviceInterface> deviceMock;
prepareConfigTestMock(deviceMock, v);

CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };

Expand All @@ -551,7 +570,8 @@ TEST_CASE("Config parameter - UserKey", "[candevice]")
{
using namespace fakeit;
std::vector<std::pair<int, QVariant>> v;
auto&& deviceMock = prepareConfigTestMock(v);
Mock<CanDeviceInterface> deviceMock;
prepareConfigTestMock(deviceMock, v);

CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };

Expand All @@ -575,7 +595,8 @@ TEST_CASE("Config parameter - DataBitRateKey", "[candevice]")
{
using namespace fakeit;
std::vector<std::pair<int, QVariant>> v;
auto&& deviceMock = prepareConfigTestMock(v);
Mock<CanDeviceInterface> deviceMock;
prepareConfigTestMock(deviceMock, v);

CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };

Expand All @@ -598,7 +619,8 @@ TEST_CASE("Config parameter - multiple keys", "[candevice]")
{
using namespace fakeit;
std::vector<std::pair<int, QVariant>> v;
auto&& deviceMock = prepareConfigTestMock(v);
Mock<CanDeviceInterface> deviceMock;
prepareConfigTestMock(deviceMock, v);

CanDevice canDevice{ CanDeviceCtx(&deviceMock.get()) };

Expand Down
Loading

0 comments on commit fa2d90b

Please sign in to comment.