#include "test.h" #include "relays.h" int test_relays() { bool ret; bool state=0; uint8_t idx; float last_change; ret = relays_init("0,A"); ASSERT(ret!=0, "relays_init should not have taken '0,A'"); ret = relays_init("0,41"); ASSERT(ret!=0, "relays_init should not have taken '0,41'"); ret = relays_init("0,1,2,3,4,5,6,7,8"); ASSERT(ret!=0, "relays_init should not have taken '0,1,2,3,4,5,6,7,8'"); ret = relays_init(" 0, 2, "); ASSERT(ret==0, "relays_init should have taken ' 0, 2, '"); ret = relays_init("12,13,14,16"); ASSERT(ret==0, "relays_init should have taken '12,13,14,16'"); idx = relays_find_by_gpio(1); ASSERT(idx==255, "should not have gpio=1"); idx = relays_find_by_gpio(12); ASSERT(idx==0, "should have gpio=12 at idx=0"); last_change = relays_get_last_change_by_gpio(12); ASSERT(last_change==-1, "button at gpio=12 should have last_change==-1"); relays_set_by_gpio(12, true); state = relays_get_by_gpio(12); ASSERT(state==true, "relay at gpio=12 should be state=true"); state = relays_get_by_idx(0); ASSERT(state==true, "relay at idx=0 should be state=true"); state = relays_get_by_idx(1); ASSERT(state==false, "relay at idx=1 should be state=false"); last_change = relays_get_last_change_by_gpio(12); ASSERT(last_change>0, "button at gpio=12 should have last_change>0"); relays_set_by_idx(0, false); state = relays_get_by_idx(0); ASSERT(state==false, "relay at idx=0 should be state=false"); state = relays_get_by_gpio(12); ASSERT(state==false, "relay at gpio=12 should be state=false"); last_change = relays_get_last_change_by_gpio(12); ASSERT(last_change>0, "button at gpio=12 should have last_change>0"); return 0; }