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.

@startuml
hide empty members

class EasyNmea
class EasyNmeaImpl

EasyNmeaTest : void set_impl(std::unique_ptr<EasyNmeaImplMock> impl)

EasyNmeaImplMock : MOCK_METHOD(open)
EasyNmeaImplMock : MOCK_METHOD(is_open)
EasyNmeaImplMock : MOCK_METHOD(close)
EasyNmeaImplMock : MOCK_METHOD(take_next)
EasyNmeaImplMock : MOCK_METHOD(wait_for_data)

EasyNmeaImpl <|-- EasyNmeaImplMock
EasyNmea o-- "1" EasyNmeaImplMock
EasyNmea <|-- EasyNmeaTest
@enduml

open()

  1. openOk: Check that EasyNmea::open() passes the correct arguments to EasyNmeaImpl::open(), and that it returns ReturnCode::RETURN_CODE_OK whenever EasyNmeaImpl::open() does so.

  2. openError: Check that EasyNmea::open() passes the correct arguments to EasyNmeaImpl::open(), and that it returns ReturnCode::RETURN_CODE_ERROR whenever EasyNmeaImpl::open() does so.

  3. openIllegal: Check that EasyNmea::open() passes the correct arguments to EasyNmeaImpl::open(), and that it returns ReturnCode::RETURN_CODE_ILLEGAL_OPERATION whenever EasyNmeaImpl::open() does so.

is_open()

  1. is_openOpened: Check that EasyNmea::is_open() returns true when a connection is opened.

  2. is_openClosed: Check that EasyNmea::is_open() returns false when a connection is closed.

close()

  1. closeOk: Check that EasyNmea::close() returns ReturnCode::RETURN_CODE_OK when an opened port is closed correctly.

  2. closeError: Check that EasyNmea::close() returns ReturnCode::RETURN_CODE_ERROR when an opened port cannot be closed correctly.

  3. closeIllegal: Check that EasyNmea::close() returns ReturnCode::RETURN_CODE_ILLEGAL_OPERATION when attempting to close an already closed port.

take_next()

  1. take_nextOk: Check that EasyNmea::take_next() calls to EasyNmeaImpl::take_next() with the appropriate arguments, and that if returns ReturnCode::RETURN_CODE_OK whenever EasyNmeaImpl::take_next() does so. Furthermore, check that the data output is the sample output by EasyNmeaImpl::take_next().

  2. take_nextNoData: Check that EasyNmea::take_next() calls to EasyNmeaImpl::take_next() with the appropriate arguments, and that if returns ReturnCode::RETURN_CODE_OK whenever EasyNmeaImpl::take_next() does so. Furthermore, check that the data output is equal to the input.

wait_for_data()

  1. wait_for_dataOk: Check that EasyNmeaImpl::wait_for_data() is called with the appropriate arguments, and that EasyNmea::wait_for_data() returns ReturnCode::RETURN_CODE_OK whenever EasyNmeaImpl::wait_for_data() does so.

  2. wait_for_dataTimeout: Check that EasyNmeaImpl::wait_for_data() is called with the appropriate arguments, and that EasyNmea::wait_for_data() returns ReturnCode::RETURN_CODE_TIMEOUT whenever EasyNmeaImpl::wait_for_data() does so.

  3. 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.

  4. wait_for_dataIllegal: Check that EasyNmeaImpl::wait_for_data() is called with the appropriate arguments, and that EasyNmea::wait_for_data() returns ReturnCode::RETURN_CODE_ILLEGAL_OPERATION whenever EasyNmeaImpl::wait_for_data() does so.

  5. wait_for_dataError: Check that EasyNmeaImpl::wait_for_data() is called with the appropriate arguments, and that EasyNmea::wait_for_data() returns ReturnCode::RETURN_CODE_ERROR whenever EasyNmeaImpl::wait_for_data() does so.