mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 19:42:08 +02:00
Add working unit tests
This commit is contained in:
parent
f609d54a14
commit
995cc7784c
106 changed files with 589 additions and 582 deletions
21
test/battery/NissanLeafTest.cpp
Normal file
21
test/battery/NissanLeafTest.cpp
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue