EasyNmea Unit Tests¶
As documented in API Level, EasyNmea provides applications with APIs to open and close
the serial port, wait until data of one or more NMEA 0183 types is received, check whether the serial port connection is
opened, and take the next unread sample of a given NMEA 0183 type.
The EasyNmea tests use the EasyNmeaTest class, which derives from EasyNmea, adding
the possibility of substituting the EasyNmeaImpl with another instance.
This enables the tests to implement a EasyNmeaImplMock, which derives from EasyNmeaImpl,
mocking away the EasyNmeaImpl::open(), EasyNmeaImpl::is_open(), EasyNmeaImpl::close(),
EasyNmeaImpl::wait_for_data(), and EasyNmeaImpl::take_next() functions.
This way, the tests can substitute the EasyNmeaImpl instance in EasyNmeaTest with an instance
of EasyNmeaImplMock on which expectations can be set, and then check whether EasyNmea behaves
as expected depending on the EasyNmeaImpl returned values.
open()¶
openOk: Check that
EasyNmea::open()passes the correct arguments toEasyNmeaImpl::open(), and that it returnsReturnCode::RETURN_CODE_OKwheneverEasyNmeaImpl::open()does so.openError: Check that
EasyNmea::open()passes the correct arguments toEasyNmeaImpl::open(), and that it returnsReturnCode::RETURN_CODE_ERRORwheneverEasyNmeaImpl::open()does so.openIllegal: Check that
EasyNmea::open()passes the correct arguments toEasyNmeaImpl::open(), and that it returnsReturnCode::RETURN_CODE_ILLEGAL_OPERATIONwheneverEasyNmeaImpl::open()does so.
is_open()¶
is_openOpened: Check that
EasyNmea::is_open()returnstruewhen a connection is opened.is_openClosed: Check that
EasyNmea::is_open()returnsfalsewhen a connection is closed.
close()¶
closeOk: Check that
EasyNmea::close()returnsReturnCode::RETURN_CODE_OKwhen an opened port is closed correctly.closeError: Check that
EasyNmea::close()returnsReturnCode::RETURN_CODE_ERRORwhen an opened port cannot be closed correctly.closeIllegal: Check that
EasyNmea::close()returnsReturnCode::RETURN_CODE_ILLEGAL_OPERATIONwhen attempting to close an already closed port.
take_next()¶
take_nextOk: Check that
EasyNmea::take_next()calls toEasyNmeaImpl::take_next()with the appropriate arguments, and that if returnsReturnCode::RETURN_CODE_OKwheneverEasyNmeaImpl::take_next()does so. Furthermore, check that the data output is the sample output byEasyNmeaImpl::take_next().take_nextNoData: Check that
EasyNmea::take_next()calls toEasyNmeaImpl::take_next()with the appropriate arguments, and that if returnsReturnCode::RETURN_CODE_OKwheneverEasyNmeaImpl::take_next()does so. Furthermore, check that the data output is equal to the input.
wait_for_data()¶
wait_for_dataOk: Check that
EasyNmeaImpl::wait_for_data()is called with the appropriate arguments, and thatEasyNmea::wait_for_data()returnsReturnCode::RETURN_CODE_OKwheneverEasyNmeaImpl::wait_for_data()does so.wait_for_dataTimeout: Check that
EasyNmeaImpl::wait_for_data()is called with the appropriate arguments, and thatEasyNmea::wait_for_data()returnsReturnCode::RETURN_CODE_TIMEOUTwheneverEasyNmeaImpl::wait_for_data()does so.wait_for_dataTimeoutDefault: The difference with wait_for_dataTimeout os that in this case,
EasyNmea::wait_for_data()is called leaving the timeout as default.wait_for_dataIllegal: Check that
EasyNmeaImpl::wait_for_data()is called with the appropriate arguments, and thatEasyNmea::wait_for_data()returnsReturnCode::RETURN_CODE_ILLEGAL_OPERATIONwheneverEasyNmeaImpl::wait_for_data()does so.wait_for_dataError: Check that
EasyNmeaImpl::wait_for_data()is called with the appropriate arguments, and thatEasyNmea::wait_for_data()returnsReturnCode::RETURN_CODE_ERRORwheneverEasyNmeaImpl::wait_for_data()does so.