self test for #1828 - it seems to pass for me

This commit is contained in:
Tester23 2025-10-10 17:44:44 +02:00
parent 6708337768
commit 22f3571be2
5 changed files with 32 additions and 3 deletions

View File

@ -376,8 +376,9 @@ void EventHandlers_FireEvent3(byte eventCode, int argument, int argument2, int a
ev = ev->next;
}
}
void EventHandlers_FireEvent2(byte eventCode, int argument, int argument2) {
int EventHandlers_FireEvent2(byte eventCode, int argument, int argument2) {
struct eventHandler_s *ev;
int ret = 0;
ev = g_eventHandlers;
@ -386,10 +387,12 @@ void EventHandlers_FireEvent2(byte eventCode, int argument, int argument2) {
if(argument == ev->requiredArgument && argument2 == ev->requiredArgument2) {
ADDLOG_INFO(LOG_FEATURE_EVENT, "EventHandlers_FireEvent2: executing command %s",ev->command);
CMD_ExecuteCommand(ev->command, COMMAND_FLAG_SOURCE_SCRIPT);
ret++;
}
}
ev = ev->next;
}
return ret;
}

View File

@ -233,7 +233,7 @@ void EventHandlers_FireEvent_String(byte eventCode, const char* argument);
// This is useful to fire an event when, for example, a button is pressed.
// Then eventCode is a BUTTON_PRESS and argument is a button index.
void EventHandlers_FireEvent(byte eventCode, int argument);
void EventHandlers_FireEvent2(byte eventCode, int argument, int argument2);
int EventHandlers_FireEvent2(byte eventCode, int argument, int argument2);
void EventHandlers_FireEvent3(byte eventCode, int argument, int argument2, int argument3);
// This is more advanced event handler. It will only fire handlers when a variable state changes from one to another.
// For example, you can watch for Voltage from BL0942 to change below 230, and it will fire event only when it becomes below 230.

View File

@ -42,6 +42,21 @@ void Test_Commands_Startup() {
CFG_SetShortStartupCommand(loremIpsum3);
CMD_ExecuteCommand(CFG_GetShortStartupCommand(), 0);
SIM_ShutdownOBK();
const char *t = "startDriver IR\n"
"setFlag 1 1\n"
"addEventHandler2 IR_NEC 0xC7EA 0x17 backlog IRSend NEC 0x0 0xA8; IRSend NEC 0x0 0xA8; IRSend NEC 0x0 0xA8\n"
"addEventHandler2 IR_NEC 0xC7EA 0xF backlog IRSend NEC 0x0 0x8C; IRSend NEC 0x0 0x8C; IRSend NEC 0x0 0x8C; IRSend NEC 0x0 0x8C; IRSend NEC 0x0 0x8C\n"
"addEventHandler2 IR_NEC 0xC7EA 0x10 backlog IRSend NEC 0x0 0x9C; IRSend NEC 0x0 0x9C; IRSend NEC 0x0 0x9C; IRSend NEC 0x0 0x9C\n";
CFG_SetShortStartupCommand(t);
CFG_Save_IfThereArePendingChanges();
// NOTE: THIS WILL RUN STARTUP COMMAND!!!!
SIM_StartOBK(0);
SELFTEST_ASSERT(1 == EventHandlers_FireEvent2(CMD_EVENT_IR_NEC, 0xC7EA, 0x17));
SELFTEST_ASSERT(1 == EventHandlers_FireEvent2(CMD_EVENT_IR_NEC, 0xC7EA, 0xF));
SELFTEST_ASSERT(1 == EventHandlers_FireEvent2(CMD_EVENT_IR_NEC, 0xC7EA, 0x10));
}

View File

@ -19,6 +19,8 @@ extern "C" {
void SIM_SetupNewFlashFile(const char *flashPath);
void SIM_SetupEmptyFlashModeNoFile();
void SIM_ClearOBK(const char *flashPath);
void SIM_ShutdownOBK();
void SIM_StartOBK(const char *flashPath);
bool SIM_IsFlashModified();
float SIM_GetDeltaTimeSeconds();
#ifdef __cplusplus

View File

@ -140,12 +140,14 @@ void SIM_Hack_ClearSimulatedPinRoles();
void CHANNEL_FreeLabels();
void SIM_ClearOBK(const char *flashPath) {
void SIM_ShutdownOBK() {
if (bObkStarted) {
DRV_ShutdownAllDrivers();
#if ENABLE_LITTLEFS
release_lfs();
#endif
SVM_FreeAllFiles();
SVM_StopAllScripts();
SIM_Hack_ClearSimulatedPinRoles();
WIN_ResetMQTT();
SPILED_Shutdown(); // won't hurt
@ -159,12 +161,19 @@ void SIM_ClearOBK(const char *flashPath) {
// LOG deinit after main init so commands will be re-added
LOG_DeInit();
}
}
void SIM_StartOBK(const char *flashPath) {
if (flashPath) {
SIM_SetupFlashFileReading(flashPath);
}
bObkStarted = true;
Main_Init();
}
void SIM_ClearOBK(const char *flashPath) {
SIM_ShutdownOBK();
SIM_StartOBK(flashPath);
}
void Win_DoUnitTests() {
//SELFTEST_ASSERT_EXPRESSION("sqrt(4)", 2)