-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Clovis Durand <[email protected]>
- Loading branch information
Showing
3 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |