Skip to content

Commit

Permalink
addEventHandler + if conditional - scripting self test
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Oct 7, 2023
1 parent 0492761 commit 9fee4e1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/selftest/selftest_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,41 @@ void Test_Command_If_Else() {
SELFTEST_ASSERT_CHANNEL(12, 1111);//keeps old val
SELFTEST_ASSERT_CHANNEL(13, 4444);

CMD_ExecuteCommand("setChannel 5 0", 0);
CMD_ExecuteCommand("addEventHandler OnChannelChange 5 if $CH11 then \"setChannel 12 2024\" else \"setChannel 12 5000\"", 0);
SELFTEST_ASSERT_CHANNEL(5, 0);
SELFTEST_ASSERT_CHANNEL(11, 0);
SELFTEST_ASSERT_CHANNEL(12, 1111);//keeps old val
SELFTEST_ASSERT_CHANNEL(13, 4444);

CMD_ExecuteCommand("setChannel 11 1", 0);
CMD_ExecuteCommand("setChannel 5 1", 0);
// change will fire if and since CH11 is 1 it will set 12 to 2024
SELFTEST_ASSERT_CHANNEL(5, 1);
SELFTEST_ASSERT_CHANNEL(11, 1);
SELFTEST_ASSERT_CHANNEL(12, 2024);
SELFTEST_ASSERT_CHANNEL(13, 4444);

// clear 12 for test
CMD_ExecuteCommand("setChannel 12 0", 0);
SELFTEST_ASSERT_CHANNEL(12, 0);

// change will fire if and since CH11 is 1 it will set 12 to 2024
CMD_ExecuteCommand("addChannel 5 1", 0);
SELFTEST_ASSERT_CHANNEL(12, 2024);

// clear 12 for test
CMD_ExecuteCommand("setChannel 12 0", 0);
SELFTEST_ASSERT_CHANNEL(12, 0);
// set 11 so IF will behave differently
CMD_ExecuteCommand("setChannel 11 0", 0);
SELFTEST_ASSERT_CHANNEL(11, 0);
// 'if' didnt fire yet, so it should still have prev val:
SELFTEST_ASSERT_CHANNEL(12, 0);
// change will fire if and since CH11 is 1 it will set 12 to 5000
CMD_ExecuteCommand("addChannel 5 1", 0);
SELFTEST_ASSERT_CHANNEL(12, 5000);

// cause error
//SELFTEST_ASSERT_CHANNEL(1, 666);

Expand Down
2 changes: 1 addition & 1 deletion src/win_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void SIM_ClearOBK(const char *flashPath) {
}
void Win_DoUnitTests() {

Test_Command_If_Else();
Test_MQTT();
Test_ChargeLimitDriver();
// this is slowest
Expand Down Expand Up @@ -178,7 +179,6 @@ void Win_DoUnitTests() {
Test_Scripting();
Test_Commands_Channels();
Test_Command_If();
Test_Command_If_Else();
Test_Tokenizer();
Test_Http();
Test_DeviceGroups();
Expand Down

0 comments on commit 9fee4e1

Please sign in to comment.