Add working unit tests

This commit is contained in:
Jaakko Haakana 2025-07-26 15:19:49 +03:00
parent f609d54a14
commit 995cc7784c
106 changed files with 589 additions and 582 deletions

View file

@ -0,0 +1,21 @@
#include <gtest/gtest.h>
#include "../../Software/src/battery/NISSAN-LEAF-BATTERY.h"
#include "../../Software/src/datalayer/datalayer.h"
TEST(NissanLeafTests, ShouldReportVoltage) {
auto battery = new NissanLeafBattery();
battery->setup();
int expected_dV = 440;
int divided = expected_dV / 5;
CAN_frame frame = {.ID = 0x1DB, .data = {.u8 = {0, 0, (uint8_t)(divided >> 2), (uint8_t)((divided & 0xC0) << 6)}}};
frame.data.u8[7] = battery->calculate_crc(frame);
battery->handle_incoming_can_frame(frame);
battery->update_values();
EXPECT_EQ(datalayer.battery.status.voltage_dV, expected_dV);
}