transports_test.cpp¶
file tests/io/transports_test.cpp · Test suite
Tests of the nmeasim::io transports and of network interface enumeration.
Source tests/io/transports_test.cpp
Covers nmeasim::io::TcpServerTransport, nmeasim::io::TcpClientTransport, nmeasim::io::UdpTransport, nmeasim::io::WebSocketServerTransport, nmeasim::io::FileTransport, nmeasim::io::SerialTransport and nmeasim::io::LogTransport: opening and closing, state changes and errors, the bytes each one delivers, client counts, reconnection, and the nmeasim::io::to_string names of transport states and UDP modes. It also checks nmeasim::io::ipv4_interfaces and nmeasim::io::find_ipv4_interface.
The network tests (tagged [integration]) talk to Qt sockets over the loopback interface and bind to port 0, so that the operating system picks a free port and parallel test runs do not collide. Files are written to temporary directories; the serial test uses a device name that does not exist. The file reads no fixture.
Test cases¶
16 test cases, in source order.
Summary¶
File-local functions
| Name | Description |
|---|---|
wait_until() |
Pumps the Qt event loop until a condition holds or a timeout expires. |
File-local variables
| Name | Description |
|---|---|
kLine |
The line the transport tests write: a valid GLL sentence with its CR LF terminator. |
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/io/transports_test.cpp:43 · defined in tests/io/event_loop.hpp:36
File-local variables¶
kLine¶
const QByteArray kLine{"$GPGLL,4916.45,N,12311.12,W,225444,A,*1D\r\n"}
The line the transport tests write: a valid GLL sentence with its CR LF terminator.
It reports 49 degrees 16.45 minutes north, 123 degrees 11.12 minutes west at 22:54:44 UTC. Its checksum 1D is the XOR of the characters between $ and *.
Declared in tests/io/transports_test.cpp:51