Skip to content

TileServer

class (anonymous namespace){tile_cache_test.cpp}::TileServer ยท Test suite

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

Declared in tests/app/tile_cache_test.cpp (line 49)

The server listens on a port the operating system picks and counts the requests it receives, whatever connection they arrive on (the network access manager reuses connections). It lives in the test's thread and makes progress only while the event loop runs, for example inside nmeasim::test::wait_until.

Summary

Public types

Name Description
Answer How the server answers a request.

Public member functions

Name Description
TileServer() Starts listening.
url_template() Returns the tile URL template that points at this server.
requests() Returns the number of requests received so far.
headers() Returns the header block of every request received so far, oldest first.
answer_held() Answers every request held so far with a PNG tile.

Private member functions

Name Description
accept() Takes every pending connection and reads its requests as they arrive.
read() Reads the complete requests buffered on a connection and answers each one.

Private static member functions

Name Description
png_response() Returns a complete HTTP response carrying a PNG tile.

Private data members

Name Description
answer_ How every request is answered.
server_ The listening socket; owns the accepted connections.
buffers_ Bytes received on each connection that do not yet form a complete request.
headers_ Header block of every request received, oldest first.
held_ Connections with a request waiting for answer_held.

Public types

Answer

enum class Answer

How the server answers a request.

Enumerator Value Description
NotFound HTTP/1.1 404 Not Found with an empty body; the connection stays open.
Close Closes the connection without an answer, a network error for the client.
Hold Keeps the request unanswered until answer_held is called.
Png HTTP/1.1 200 OK with a 256-pixel square PNG tile.

Declared in tests/app/tile_cache_test.cpp:52

Public member functions

TileServer()

explicit TileServer(Answer answer)

Starts listening.

The test fails if no port can be opened.

Parameters

Name Type Description
answer Answer How every request is answered.

Declared in tests/app/tile_cache_test.cpp:64

url_template()

QString url_template() const

Returns the tile URL template that points at this server.

Returns QString: http://127.0.0.1:<port>/{z}/{x}/{y}.png.

Declared in tests/app/tile_cache_test.cpp:72

requests()

int requests() const

Returns the number of requests received so far.

Returns int: The request count, over all connections.

Declared in tests/app/tile_cache_test.cpp:79

headers()

const QList<QByteArray>& headers() const

Returns the header block of every request received so far, oldest first.

Returns const QList<QByteArray>&: The request line and header lines of each request, as received.

Declared in tests/app/tile_cache_test.cpp:84

answer_held()

void answer_held()

Answers every request held so far with a PNG tile.

Declared in tests/app/tile_cache_test.cpp:87

Private member functions

accept()

void accept()

Takes every pending connection and reads its requests as they arrive.

Declared in tests/app/tile_cache_test.cpp:98

read()

void read(QTcpSocket* socket)

Reads the complete requests buffered on a connection and answers each one.

Parameters

Name Type Description
socket QTcpSocket* Connection with data to read; owned by the server.

Declared in tests/app/tile_cache_test.cpp:108

Private static member functions

png_response()

static QByteArray png_response()

Returns a complete HTTP response carrying a PNG tile.

Returns QByteArray: Status line, headers and a white 256-pixel square PNG as the body.

Declared in tests/app/tile_cache_test.cpp:136

Private data members

answer_

Answer answer_

How every request is answered.

Declared in tests/app/tile_cache_test.cpp:148

server_

QTcpServer server_

The listening socket; owns the accepted connections.

Declared in tests/app/tile_cache_test.cpp:150

buffers_

QHash<QTcpSocket* , QByteArray> buffers_

Bytes received on each connection that do not yet form a complete request.

Declared in tests/app/tile_cache_test.cpp:152

headers_

QList<QByteArray> headers_

Header block of every request received, oldest first.

Declared in tests/app/tile_cache_test.cpp:154

held_

QList<QTcpSocket *> held_

Connections with a request waiting for answer_held.

Declared in tests/app/tile_cache_test.cpp:156