Skip to content

Extend CanMsg to allow to distinguish between standard and extended ids … #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding test code for CanMsg::CanMsg.
  • Loading branch information
aentinger committed Aug 3, 2023
commit bba303d2e6016e68d214696b50fed951e563dd35
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(TEST_TARGET ${CMAKE_PROJECT_NAME})
##########################################################################

set(TEST_SRCS
src/CanMsg/test_CanMsg.cpp
src/CanMsg/test_CanExtendedId.cpp
src/CanMsg/test_CanStandardId.cpp
src/CanMsg/test_isExtendedId.cpp
Expand Down
52 changes: 52 additions & 0 deletions test/src/CanMsg/test_CanMsg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include <catch.hpp>

#include <CanMsg.h>

/**************************************************************************************
* NAMESPACE
**************************************************************************************/

using namespace arduino;

/**************************************************************************************
* TEST CODE
**************************************************************************************/

TEST_CASE ("Test constructor with no data (data length = 0)", "[CanMsg-CanMsg-01]")
{
CanMsg const msg(CanStandardId(0x20), 0, nullptr);

REQUIRE(msg.data_length == 0);
for (size_t i = 0; i < CanMsg::MAX_DATA_LENGTH; i++)
REQUIRE(msg.data[i] == 0);
}

TEST_CASE ("Test constructor with data (data length < CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-02]")
{
uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE};

CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data);

REQUIRE(msg.data_length == 4);
for (size_t i = 0; i < msg.data_length; i++)
REQUIRE(msg.data[i] == msg_data[i]);
}

TEST_CASE ("Test constructor with data (data length > CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-03]")
{
uint8_t const msg_data[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data);

REQUIRE(msg.data_length == 8);
for (size_t i = 0; i < msg.data_length; i++)
REQUIRE(msg.data[i] == msg_data[i]);
}