main_window_test.cpp¶
file tests/app/main_window_test.cpp · Test suite
Tests of nmeasim::app::MainWindow, the main window of the desktop application.
Source tests/app/main_window_test.cpp
Covers the position and duration formatting, running a profile against a local TCP server, dashboard overrides and keyboard nudges reaching the delta simulation, loading and saving profiles (a profile the runner rejects, a missing profile given on the command line, a failed save), the order of the menus, the fractional zoom level kept between sessions, steering mode and the arrow keys in track mode, the about text, following a GPX track with step and seek, replaying a log to its end, recording a session to a log file, the engine tiles, and that the window's map uses the temporary tile cache of the test run, offline. The window is created on the offscreen platform (see main.cpp). The file reads the fixtures tracks/timestamped.gpx, tracks/malformed.gpx and logs/plain.nmea from tests/fixtures.
Test cases¶
17 test cases, in source order.
Summary¶
File-local functions
| Name | Description |
|---|---|
quick_profile() |
Returns the default profile made fast and self-contained for tests. |
fixture() |
Returns the absolute path of a file in the test fixtures directory. |
wait_until() |
Pumps the Qt event loop until a condition holds or a timeout expires. |
File-local functions¶
quick_profile()¶
nmeasim::io::Profile quick_profile()
Returns the default profile made fast and self-contained for tests.
The tick is 20 ms instead of the default 100 ms, and the only output is a TCP server on 127.0.0.1 with port 0, so that the operating system picks a free port and the test never collides with a port already in use. Every sentence of the standard registry is listed with its default enabled state, the default talker (the empty string) and a period of 100 ms, so that the console fills within a fraction of a second.
Returns nmeasim::io::Profile: The profile, ready for nmeasim::app::MainWindow::set_profile.
Declared in tests/app/main_window_test.cpp:67
fixture()¶
QString fixture(const char* relative)
Returns the absolute path of a file in the test fixtures directory.
Parameters
| Name | Type | Description |
|---|---|---|
relative |
const char* |
Path below tests/fixtures, for example "tracks/timestamped.gpx". |
Returns QString: The path, built from the NMEASIM_FIXTURES_DIR compile definition.
Declared in tests/app/main_window_test.cpp:87
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/app/main_window_test.cpp:53 · defined in tests/io/event_loop.hpp:36