Skip to content

tile_cache_test.cpp

file tests/app/tile_cache_test.cpp · Test suite

Tests of the downloads of nmeasim::app::map::TileCache.

Source tests/app/tile_cache_test.cpp

Covers the User-Agent of the requests, caching a downloaded tile, the memory of failed downloads (HTTP 404 never requested again, other failures only after a retry delay), and aborting running downloads when downloading is switched off or the cache is cleared, so that a tile is never requested twice at once. The tiles come from TileServer, a minimal HTTP server on the loopback interface with a port chosen by the operating system, and the cache lives in a temporary directory, so the tests never touch the network or the user's tile cache. The file reads no fixtures.

Test cases

5 test cases, in source order.

Test case Tags
the tile cache downloads a tile, caches it and names the application [app][map]
the tile cache never requests a tile again that the server does not have [app][map]
the tile cache retries a failed tile only after a delay [app][map]
switching downloads off aborts them so that a tile is never requested twice [app][map]
clearing the tile cache aborts the running downloads [app][map]

Types

Type Description
TileServer A minimal HTTP/1.1 tile server on 127.0.0.1 that answers every request the same way.

Summary

File-local functions

Name Description
wait_until() Pumps the Qt event loop until a condition holds or a timeout expires.

File-local functions

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/tile_cache_test.cpp:37 · defined in tests/io/event_loop.hpp:36