mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 09:49:32 +02:00
105 lines
2.7 KiB
Text
105 lines
2.7 KiB
Text
// The test library must be included first!
|
|
#include "../test_lib.h"
|
|
|
|
#include "../../Software/src/devboard/config.h"
|
|
#include "../../Software/src/devboard/utils/timer.cpp"
|
|
|
|
|
|
class EEPROMClass {
|
|
public:
|
|
void begin(int s) {}
|
|
void writeUShort(int a, uint16_t d) {}
|
|
void commit(void) {}
|
|
uint16_t readUShort(int a) {}
|
|
|
|
template<typename T>
|
|
void get(int address, T &t) {}
|
|
|
|
template<typename T>
|
|
void put(int address, const T &t) {}
|
|
};
|
|
|
|
EEPROMClass EEPROM;
|
|
|
|
#include "../../Software/src/devboard/utils/events.cpp"
|
|
/* Local test variables */
|
|
bool elapsed = false;
|
|
|
|
/* Stubs */
|
|
void run_sequence_on_target(void) {}
|
|
|
|
/* Helper functions */
|
|
/* Test functions */
|
|
|
|
TEST(init_events_test) {
|
|
init_events();
|
|
|
|
for (uint8_t i = 0; i < EVENT_NOF_EVENTS; i++) {
|
|
ASSERT_EQ(events.entries[i].occurences, 0);
|
|
ASSERT_EQ(events.entries[i].data, 0);
|
|
ASSERT_EQ(events.entries[i].timestamp, 0);
|
|
}
|
|
}
|
|
|
|
TEST(update_event_time_test) {
|
|
// Reset
|
|
testlib_millis = 0;
|
|
events.time_seconds = 0;
|
|
init_events();
|
|
|
|
// No delta, so time shouldn't increase
|
|
update_event_time();
|
|
ASSERT_EQ(events.time_seconds, 0);
|
|
|
|
// Almost time to bump the seconds
|
|
testlib_millis = 999;
|
|
update_event_time();
|
|
ASSERT_EQ(events.time_seconds, 0);
|
|
|
|
// millis == 1000, so we should add a second
|
|
testlib_millis = 1000;
|
|
update_event_time();
|
|
ASSERT_EQ(events.time_seconds, 1);
|
|
|
|
// We shouldn't add more seconds until 2000 now
|
|
testlib_millis = 1999;
|
|
update_event_time();
|
|
ASSERT_EQ(events.time_seconds, 1);
|
|
testlib_millis = 2000;
|
|
update_event_time();
|
|
ASSERT_EQ(events.time_seconds, 2);
|
|
}
|
|
|
|
TEST(set_event_test) {
|
|
// Reset
|
|
init_events();
|
|
events.time_seconds = 0;
|
|
|
|
// Initially, the event should not have any data or occurences
|
|
ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].data, 0);
|
|
ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].occurences, 0);
|
|
ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 0);
|
|
// Set current time and overvoltage event for cell 23 (RED color, bms_status == FAULT)
|
|
events.time_seconds = 345;
|
|
set_event(EVENT_CELL_OVER_VOLTAGE, 123);
|
|
// Ensure proper event data
|
|
ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].data, 123);
|
|
ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].occurences, 1);
|
|
ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 345);
|
|
ASSERT_EQ(bms_status, FAULT);
|
|
}
|
|
|
|
TEST(events_message_test) {
|
|
set_event(EVENT_DUMMY_ERROR, 0); // Set dummy event with no data
|
|
|
|
ASSERT_STREQ("The dummy error event was set!", get_event_message_string(EVENT_DUMMY_ERROR));
|
|
}
|
|
|
|
TEST(events_level_test) {
|
|
init_events();
|
|
set_event(EVENT_DUMMY_ERROR, 0); // Set dummy event with no data
|
|
|
|
ASSERT_STREQ("ERROR", get_event_level_string(EVENT_DUMMY_ERROR));
|
|
}
|
|
|
|
TEST_MAIN();
|