nmeasim::test¶
namespace nmeasim::test ยท Test suite
Shared helpers of the test suites: fixtures and utilities that several test files use.
It holds the core suite's fixture files and reference vessel states (tests/core/fixtures.hpp) and the Qt event-loop helper of the nmeasim::io suite (tests/io/event_loop.hpp). It is compiled only into the test executables.
Summary¶
Functions
| Name | Description |
|---|---|
fixture_path() |
Returns the absolute path of a file under tests/fixtures. |
read_fixture() |
Returns the contents of a file under tests/fixtures. |
fixture_state() |
Returns the reference vessel state, off Athens at 12:34:56.780 UTC on 22 September 2026. |
fixture_state_without_fix() |
Returns fixture_state with the GNSS receiver reporting no fix. |
fixture_state_extreme() |
Returns fixture_state with extreme values that produce the longest possible fields. |
body_of() |
Strips the start delimiter and the checksum from a framed sentence. |
wait_until() |
Pumps the Qt event loop until a condition holds or a timeout expires. |
Functions¶
fixture_path()¶
std::string fixture_path(std::string_view relative)
Returns the absolute path of a file under tests/fixtures.
Parameters
| Name | Type | Description |
|---|---|---|
relative |
std::string_view |
Path relative to tests/fixtures with / separators, such as tracks/timestamped.gpx. |
Returns std::string: NMEASIM_FIXTURES_DIR, a / and relative; whether the file exists is not checked, so tests can also name missing files.
Declared in tests/core/fixtures.hpp:36
read_fixture()¶
std::string read_fixture(std::string_view relative)
Returns the contents of a file under tests/fixtures.
The file is read in binary mode, so line terminators reach the parser byte for byte.
Parameters
| Name | Type | Description |
|---|---|---|
relative |
std::string_view |
Path relative to tests/fixtures, as for fixture_path. |
Returns std::string: The whole file, or an empty string when it does not exist or cannot be read.
Declared in tests/core/fixtures.hpp:46
fixture_state()¶
core::model::VesselState fixture_state()
Returns the reference vessel state, off Athens at 12:34:56.780 UTC on 22 September 2026.
Every navigation, GNSS, steering, water, wind, engine and destination value is set, and the values are chosen so that every encoder has something distinctive to show: a non-zero millisecond part for the time fields; course 047.3 and heading 045.0 that differ, and an easterly variation of 4.6 degrees that makes every magnetic value different from its true one (heading 040.4 and course 042.7 magnetic); a negative rate of turn and rudder angle, which exercise the signs of a turn to port; ten satellites in view, which need three GSV sentences; a positive transducer offset, which gives the Signal K surfaceToTransducer and belowSurface depths; one running and one stopped engine; and a destination off the vessel's track. The AIS static data keeps the model::AisStatic defaults (MMSI 239000001, which also forms the default Signal K context).
Returns core::model::VesselState: A new copy of the state; tests modify their copy freely.
Declared in tests/core/fixtures.hpp:65
fixture_state_without_fix()¶
core::model::VesselState fixture_state_without_fix()
Returns fixture_state with the GNSS receiver reporting no fix.
Every other value, the satellite counts included, is unchanged, so a test sees only what losing the fix changes: empty positions, V status fields, and the Signal K paths that need a fix left out.
Returns core::model::VesselState: fixture_state() with gnss.has_fix false.
Declared in tests/core/fixtures.hpp:107
fixture_state_extreme()¶
core::model::VesselState fixture_state_extreme()
Returns fixture_state with extreme values that produce the longest possible fields.
Positions within 0.00001 degrees of the poles and the antimeridian, the last centisecond of 2099, four-digit speeds, negative values with the most digits, twelve satellites, a differential fix, engine revolutions of 99999.9 and a waypoint name longer than model::kMaxWaypointNameLength with NMEA reserved characters. The registry test encodes every sentence from it to prove that each one still fits the 82-character limit, and the AIS test to prove that the fields are clamped.
Returns core::model::VesselState: A new copy of the extreme state.
Declared in tests/core/fixtures.hpp:123
body_of()¶
std::string body_of(std::string_view sentence)
Strips the start delimiter and the checksum from a framed sentence.
Tests compare bodies so that the expected strings need no checksum.
Parameters
| Name | Type | Description |
|---|---|---|
sentence |
std::string_view |
A sentence such as $GPHDT,45.0,T*0C, without line terminator. |
Returns std::string: The text between the first character and the last *, such as GPHDT,45.0,T; everything after the first character when there is no *; empty when sentence is empty, so that a test comparing the body of a missing sentence fails instead of throwing.
Declared in tests/core/fixtures.hpp:168
wait_until()¶
bool wait_until(const std::function<bool()>& condition, int timeout_ms = 3000)
Pumps the Qt event loop until a condition holds or a timeout expires.
Evaluates condition first, so a condition that already holds returns at once without processing any event. Otherwise it processes pending events for up to 20 milliseconds at a time and evaluates condition again after each round. Passing a condition that never holds turns the call into a wait of timeout_ms during which events are still delivered.
Parameters
| Name | Type | Description |
|---|---|---|
condition |
const std::function<bool()>& |
Predicate evaluated on the calling thread between rounds of event processing; it must be callable repeatedly and should be cheap. |
timeout_ms |
int |
Wall-clock time in milliseconds after which the wait gives up; 3000 ms by default. The timeout is checked between rounds of event processing, so the call can overrun it by one round. |
Returns bool: True as soon as condition returns true; false when it still returns false after timeout_ms milliseconds have elapsed.
Note
Events are delivered only for the calling thread, which in this suite is the thread of the QCoreApplication created in main.
Declared in tests/io/event_loop.hpp:36