simulation_runner_test.cpp¶
file tests/io/simulation_runner_test.cpp · Test suite
Tests of nmeasim::io::SimulationRunner, which runs a profile on a timer and feeds its outputs.
Source tests/io/simulation_runner_test.cpp
Covers applying a profile, starting, pausing, resuming, stepping, seeking and stopping in the delta, track and replay modes; output filters and disabled outputs; a failing output that does not stop the run; the profile start time; the relative paths of a loaded profile; recording to a log; and the Signal K, ViewSync and TAG block encodings together with custom sentences.
Fixtures read from tests/fixtures/: tracks/timestamped.gpx (five timed points over 12 min 0.5 s), tracks/malformed.gpx, logs/plain.nmea (four rounds of eight sentences, 500 ms apart) and logs/garbage.txt; tracks/missing.gpx deliberately does not exist. Network outputs bind to port 0 on the loopback interface, so that the operating system picks free ports; file outputs write to temporary directories.
Test cases¶
15 test cases, in source order.
Summary¶
File-local enumerations
| Name | Description |
|---|---|
SimulationMode |
What drives the vessel, the simulation.mode key of a profile. |
File-local functions
| Name | Description |
|---|---|
fast_profile() |
Returns the default profile with a fast tick, every registry sentence due every 100 ms and no outputs. |
fixture() |
Returns the path of a test fixture. |
read_sentences() |
Reads the non-empty lines of a text file. |
wait_until() |
Pumps the Qt event loop until a condition holds or a timeout expires. |
File-local enumerations¶
SimulationMode¶
enum class SimulationMode
What drives the vessel, the simulation.mode key of a profile.
Each enumerator is written as the string given in its description; to_string and simulation_mode_from_string convert. In every mode the delta seed supplies the values the driving source does not.
Declared in tests/io/simulation_runner_test.cpp:54 · defined in src/io/include/nmeasim/io/profile/profile.hpp:206
File-local functions¶
fast_profile()¶
Profile fast_profile()
Returns the default profile with a fast tick, every registry sentence due every 100 ms and no outputs.
The 20 ms tick and 100 ms periods keep the tests short: a few hundred milliseconds of wall clock produce several rounds of sentences. Each registry sentence keeps its default enabled state and an empty talker, which keeps the registry default. Tests add the outputs they need.
Returns Profile: A profile in delta mode, seeded by nmeasim::io::Profile::default_profile.
Declared in tests/io/simulation_runner_test.cpp:69
fixture()¶
QString fixture(const char* relative)
Returns the path of a test fixture.
Parameters
| Name | Type | Description |
|---|---|---|
relative |
const char* |
Path relative to tests/fixtures/, such as logs/plain.nmea. |
Returns QString: The absolute path, built from the NMEASIM_FIXTURES_DIR definition that tests/CMakeLists.txt passes to the compiler. The file need not exist.
Declared in tests/io/simulation_runner_test.cpp:85
read_sentences()¶
std::vector<std::string> read_sentences(const QString& path)
Reads the non-empty lines of a text file.
Fails the current test case through REQUIRE when the file cannot be opened.
Parameters
| Name | Type | Description |
|---|---|---|
path |
const QString& |
Path of the file, usually an output file written by the runner. |
Returns std::vector<std::string>: The lines in file order, with surrounding white space (including CR) removed; blank lines are skipped.
Declared in tests/io/simulation_runner_test.cpp:96
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/simulation_runner_test.cpp:56 · defined in tests/io/event_loop.hpp:36