Skip to content

Commit

Permalink
[#13] Started Relay class UTs
Browse files Browse the repository at this point in the history
Signed-off-by: Clovis Durand <[email protected]>
  • Loading branch information
Clovel committed Nov 22, 2019
1 parent e17eddd commit ef8e205
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
97 changes: 97 additions & 0 deletions software/tests/tests_Relay.cxx
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 10 additions & 0 deletions software/tests/tests_Relay.hxx
Original file line number Diff line number Diff line change
@@ -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);
48 changes: 48 additions & 0 deletions software/tests/tests_main.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @brief Main testing file
*/

/* Includes -------------------------------------------- */
/* Gaussian */
#include "tests_Relay.hxx"

/* System */
#include <iostream>

/* C System */
#include <cstring>

/* Support functions ----------------------------------- */
static void print_usage(const char * const pProgName)
{
std::cout << "[USAGE] " << pProgName << " <test#>" << 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;
}

0 comments on commit ef8e205

Please sign in to comment.