EasyNmeaImpl Unit Tests¶
As documented in Implementation Level, EasyNmeaImpl provides with the implementation for the
EasyNmea public API, namely opening and closing the serial port, waiting until data of one or more NMEA 0183
types has been received, checking whether the serial port connection is opened, and taking the next unread sample of a
given NMEA 0183 type.
The EasyNmeaImpl tests use the EasyNmeaImplTest class, which derives from
EasyNmeaImpl, adding the possibility of substituting the SerialInterface with another instance.
This enables the tests to implement a SerialInterfaceMock, which derives from SerialInterface, mocking
away the SerialInterface::open(), SerialInterface::is_open(), SerialInterface::close(), and
SerialInterface::read_line() functions.
This way, the tests can substitute the SerialInterface instance in EasyNmeaImplTest with an instance
of SerialInterfaceMock on which expectations can be set, and then check whether EasyNmeaImpl
behaves as expected depending on the SerialInterface returned values.
open()¶
openSuccess: Opens a not previously opened
EasyNmeaImpl. The return is expected to beReturnCode::RETURN_CODE_OK.openOpened: Attempts to open an already opened
EasyNmeaImpl. This is simulated by forcingSerialInterface::is_open()to returntrue. The return is expected to beReturnCode::RETURN_CODE_ILLEGAL_OPERATION.openWrongPort: Attempts to open a
EasyNmeaImplon an invalid port. This is simulated by forcingSerialInterface::open()to returnfalse. The return is expected to beReturnCode::RETURN_CODE_ERROR.
is_open()¶
is_openOpened: Check that whenever
SerialInterface::is_open()returnstrue,EasyNmeaImpl::is_open()also returnstrue.is_openClosed: Check that whenever
SerialInterface::is_open()returnsfalse,EasyNmeaImpl::is_open()also returnsfalse. Furthermore, this test also checks thatEasyNmeaImpl::is_open()returnsfalsewhenever the underlying pointer toSerialInterfaceisnullptr.
close()¶
closeSuccess: Check that whenever
SerialInterfacereports that a port is opened at first, and then returntrueon the call toSerialInterface::close(), thenEasyNmeaImpl::close()returnsReturnCode::RETURN_CODE_OK.closeError: Check that whenever
SerialInterfacereports that a port is opened at first, and then returnfalseon the call toSerialInterface::close(), thenEasyNmeaImpl::close()returnsReturnCode::RETURN_CODE_ERROR.closeClosed: Check that calling
EasyNmeaImpl::close()on a non-openedEasyNmeaImplreturnsReturnCode::RETURN_CODE_ILLEGAL_OPERATION.
wait_for_data()¶
wait_for_dataData: Check that
EasyNmeaImpl::wait_for_data()returnsReturnCode::RETURN_CODE_OKwhen a sentence which type specified in theNMEA0183DataKindMaskmask is received. Furthermore, check that the output mask has the corresponding bit correctly set.wait_for_dataClosed: Check that
EasyNmeaImpl::wait_for_data()returnsReturnCode::RETURN_CODE_ILLEGAL_OPERATIONwhen called on a closedEasyNmeaImpl.wait_for_dataDataEmptyMask: Check that
EasyNmeaImpl::wait_for_data()will returnReturnCode::RETURN_CODE_TIMEOUTafter timing out when an emptyNMEA0183DataKindMaskis passed, even when data from any of the supported types has been received. It also checks that the outputNMEA0183DataKindMaskis set tonone.wait_for_dataError: Check that whenever
SerialInterface::read_line()returns false, the call toEasyNmeaImpl::wait_for_data()unblocks and returnsReturnCode::RETURN_CODE_ERROR. It also checks that the outputNMEA0183DataKindMaskis set tonone.
take_next()¶
take_next: Check that whenever
EasyNmeaImpl::wait_for_data()returnsReturnCode::RETURN_CODE_OK, then, data can be taken withEasyNmeaImpl::take_next(), which returnsReturnCode::RETURN_CODE_OK. Furthermore, it tests that other NMEA 0183 valid sentences are not returned nor reported to be have been received, and that incomplete GPGGA sentences are not returned nor reported either.
~EasyNmeaImpl()¶
destroyNoClose: Checks that letting an opened
EasyNmeaImplinstance go out of scope without callingEasyNmeaImpl::close()is alright.