diff --git a/software/tests/tests_Relay.cxx b/software/tests/tests_Relay.cxx new file mode 100644 index 0000000..fb91d20 --- /dev/null +++ b/software/tests/tests_Relay.cxx @@ -0,0 +1,97 @@ +/** + * @brief UTs for the Relay class + */ + +/* Includes -------------------------------------------- */ +#include "Relay.hxx" + +/* Tests ----------------------------------------------- */ +int test_Relay_isOn(void) { + /* Create normal relay */ + elec::Relay lRelay(13, elec::RELAY_MODE_NORMAL); + + /* Check the relay state */ + bool lState = lRelay.isOn(); + assert(false == lState); + + return EXIT_SUCCESS; +} + +int test_Relay_switchState(void) { + /* Create normal relay */ + elec::Relay lRelay(13, elec::RELAY_MODE_NORMAL); + + /* Check the relay state */ + bool lState = lRelay.isOn(); + assert(false == lState); + + /* Switch state */ + lRelay.switchState(); + + /* Check the relay state */ + lState = lRelay.isOn(); + assert(true == lState); + + return EXIT_SUCCESS; +} + +int test_Relay_turnOn(void) { + /* Create normal relay */ + elec::Relay lRelay(13, elec::RELAY_MODE_NORMAL); + + /* Check the relay state */ + bool lState = lRelay.isOn(); + assert(false == lState); + + /* TurnOn */ + lRelay.turnOn(); + + /* Check the relay state */ + lState = lRelay.isOn(); + assert(true == lState); + + return EXIT_SUCCESS; +} + +int test_Relay_turnOff(void) { + /* Create normal relay */ + elec::Relay lRelay(13, elec::RELAY_MODE_NORMAL); + + /* Check the relay state */ + bool lState = lRelay.isOn(); + assert(false == lState); + + /* TurnOn */ + lRelay.turnOn(); + + /* Check the relay state */ + lState = lRelay.isOn(); + assert(true == lState); + + /* TurnOff */ + lRelay.turnOn(); + + /* Check the relay state */ + lState = lRelay.isOff(); + assert(false == lState); + + return EXIT_SUCCESS; +} + +int test_Relay_setMode(void) { + /* Create normal relay */ + elec::Relay lRelay(13, elec::RELAY_MODE_NORMAL); + + /* Get mode */ + relayMode_t lMode = lRelay.mode(); + assert(elec::RELAY_MODE_NORMAL == lMode); + + /* Set other mode */ + lRelay.setMode(elec::RELAY_MODE_INVERTED); + + /* Get mode */ + lMode = lRelay.mode(); + assert(elec::RELAY_MODE_INVERTED == lMode); + + return EXIT_SUCCESS; +} diff --git a/software/tests/tests_Relay.hxx b/software/tests/tests_Relay.hxx new file mode 100644 index 0000000..f2f8f06 --- /dev/null +++ b/software/tests/tests_Relay.hxx @@ -0,0 +1,10 @@ +/** + * @brief UTs for the Relay class + */ + +/* Tests ----------------------------------------------- */ +int test_Relay_isOn(void); +int test_Relay_switchState(void); +int test_Relay_turnOn(void); +int test_Relay_turnOff(void); +int test_Relay_setMode(void); \ No newline at end of file diff --git a/software/tests/tests_main.cxx b/software/tests/tests_main.cxx new file mode 100644 index 0000000..2ebd141 --- /dev/null +++ b/software/tests/tests_main.cxx @@ -0,0 +1,48 @@ +/** + * @brief Main testing file + */ + +/* Includes -------------------------------------------- */ +/* Gaussian */ +#include "tests_Relay.hxx" + +/* System */ +#include + +/* C System */ +#include + +/* Support functions ----------------------------------- */ +static void print_usage(const char * const pProgName) +{ + std::cout << "[USAGE] " << pProgName << " " << std::endl; +} + +/* Main ------------------------------------------------ */ +int main(const int argc, const char * const * const argv) { + /* Test function initialization */ + int32_t lTestNum; + int16_t lResult = EXIT_SUCCESS; + + if ((2 > argc) || (0 == std::strcmp(argv[1], "--help"))) { + print_usage(argv[0]); + return EXIT_FAILURE; + } + + lTestNum = strtol(argv[1], NULL, 10); + std::cout << "[TEST ] Executing test #" << lTestNum << std::endl; + + /* Executing test */ + switch (lTestNum) { + case 0: + lResult = test_Relay_isOn() + break; + default: + std::cout << "[INFO ] test #" << lTestNum << " not available" << std::endl; + fflush(stdout); + lResult = EXIT_FAILURE; + break; + } + + return lResult; +}