map_test.cpp¶
file tests/app/map_test.cpp · Test suite
Tests of the map: nmeasim::app::map::MapWidget, nmeasim::app::map::TileCache and the tile arithmetic of map/tile_math.hpp.
Source tests/app/map_test.cpp
Covers slippy-map tile coordinates and ground resolution, the disk and memory tile cache, coordinate conversion, panning, zooming and following in the widget, longitudes wrapped across the antimeridian, the attribution of the tile server, the sailed track, the loaded route, the destination, the scale bar, painting in both themes, and how nmeasim::app::MainWindow reacts to positions and destinations picked on the map. Every tile cache is switched offline, and the tiles a test needs are written into a temporary directory. The widgets are painted on the offscreen platform (see main.cpp). The file reads no fixtures.
Test cases¶
15 test cases, in source order.
Summary¶
File-local functions
| Name | Description |
|---|---|
write_tile() |
Writes a tile of one colour into a tile cache directory. |
wait_until() |
Pumps the Qt event loop until a condition holds or a timeout expires. |
File-local functions¶
write_tile()¶
void write_tile(const QString& directory, map::TileKey key, QColor color)
Writes a tile of one colour into a tile cache directory.
The file is a kTileSize square PNG at directory/zoom/x/y.png, the layout nmeasim::app::map::TileCache reads. The test fails if the file cannot be written.
Parameters
| Name | Type | Description |
|---|---|---|
directory |
const QString& |
Root directory of the cache; the subdirectories are created as needed. |
key |
map::TileKey |
The tile to write. |
color |
QColor |
Colour that fills the whole tile. |
Declared in tests/app/map_test.cpp:56
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/map_test.cpp:43 · defined in tests/io/event_loop.hpp:36