Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
testsupport.cpp File Reference

Implementation of the test helpers in testsupport.h. More...

#include "testsupport.h"
#include <QtCore/QAtomicInt>
#include <algorithm>

Functions

void SondeTest::reportCrashesOnStderr ()
 For the tests' main(): on Windows, sends the C runtime's reports (qFatal() and failed assertions in a debug build) to stderr, and stops abort() from asking Windows Error Reporting, so a test that dies (a death test, or an assertion) ends at once instead of waiting for a click on a dialog.
bool SondeTest::waitUntil (const std::function< bool()> &predicate, int timeoutMs=5000)
 Runs the event loop until predicate is true or timeoutMs expires.
void SondeTest::spin (int ms)
 Runs the event loop for ms milliseconds.
QString SondeTest::uniqueName (const QString &prefix)
 Returns a process-unique name with the given prefix (for sockets).
QString SondeTest::resultText (const QJsonObject &toolResult)
 Concatenates the text blocks of a tool result's content array.
bool SondeTest::anonymous_namespace{testsupport.cpp}::parseResponse (QByteArray &buf, HttpResponse *out, bool closed)
 Tries to parse one complete response from the front of buf.
QList< HttpResponse > SondeTest::rawHttp (quint16 port, const QByteArray &request, int count=1, int timeoutMs=5000)
 Sends raw request bytes over a fresh connection and reads count responses.
HttpResponse SondeTest::http (quint16 port, const QByteArray &method, const QByteArray &path, const QList< QPair< QByteArray, QByteArray > > &headers={ }, const QByteArray &body={ }, int timeoutMs=5000)
 Sends one HTTP request and returns its response.

Detailed Description

Implementation of the test helpers in testsupport.h.

Function Documentation

◆ reportCrashesOnStderr()

void SondeTest::reportCrashesOnStderr ( )

For the tests' main(): on Windows, sends the C runtime's reports (qFatal() and failed assertions in a debug build) to stderr, and stops abort() from asking Windows Error Reporting, so a test that dies (a death test, or an assertion) ends at once instead of waiting for a click on a dialog.

Does nothing elsewhere.

◆ waitUntil()

bool SondeTest::waitUntil ( const std::function< bool()> & predicate,
int timeoutMs = 5000 )

Runs the event loop until predicate is true or timeoutMs expires.

Returns
Whether the predicate became true.