Skip to content

Commit

Permalink
changing to .at(), testing exception, removing headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Abyl Ikhsanov committed Feb 19, 2024
1 parent 313014f commit 51fc410
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion isobus/src/can_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ namespace isobus
{
auto byteIndex = i / 8;
auto bitIndexWithinByte = i % 8;
auto bit = (data[byteIndex] >> (indexOfFinalByteBit - bitIndexWithinByte)) & 1;
auto bit = (data.at(byteIndex) >> (indexOfFinalByteBit - bitIndexWithinByte)) & 1;
if (length - bitCounter < 8)
{
currentByte |= static_cast<uint8_t>(bit) << (length - 1 - bitCounter);
Expand Down
6 changes: 2 additions & 4 deletions test/can_message_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <gtest/gtest.h>
#include "isobus/hardware_integration/can_hardware_interface.hpp"
#include "isobus/hardware_integration/socket_can_interface.hpp"
#include "isobus/hardware_integration/virtual_can_plugin.hpp"
#include "isobus/isobus/can_message.hpp"
#include "isobus/isobus/can_message_frame.hpp"
Expand Down Expand Up @@ -37,16 +36,15 @@ void callback(const CANMessage &message, void *parent)
EXPECT_EQ(value64, 4);
value64 = message.get_data_custom_length(14, 3, CANMessage::ByteFormat::BigEndian);
EXPECT_EQ(value64, 4);
EXPECT_THROW({ value64 = message.get_data_custom_length(63, 999999); }, std::out_of_range);
EXPECT_THROW({ value64 = message.get_data_custom_length(65748321, 1); }, std::out_of_range);
}

TEST(CAN_MESSAGE_TESTS, DataCorrectnessTest)
{
CANHardwareInterface::set_number_of_can_channels(1);
CANHardwareInterface::assign_can_channel_frame_handler(0, std::make_shared<VirtualCANPlugin>());
CANHardwareInterface::start();
NAME testName;
std::shared_ptr<InternalControlFunction> testEcu = InternalControlFunction::create(testName, 0x1C, 0);
std::shared_ptr<InternalControlFunction> testEcu2 = InternalControlFunction::create(testName, 0x1A, 0);
CANNetworkManager::CANNetwork.update();
CANNetworkManager::CANNetwork.add_global_parameter_group_number_callback(0xE100, callback, nullptr);

Expand Down

0 comments on commit 51fc410

Please sign in to comment.