DuxReiNummariae 1.1.0-alpha.27
Simple and powerful budgeting application
Loading...
Searching...
No Matches
drn::networking::testing Namespace Reference

Classes

class  ReplyResponseMock
 A mock implementation of the networking::ReplyResponse interface for testing purposes. It is specifically designed to facilitate testing by simulating the behaviour of a network response. It enables controlled testing of network interactions without requiring actual network calls. It provides the mechanisms to mock common methods of a network reply, such as retrieving attributes, errors, URLs, error strings, and data content. Additionally, it includes functionality to simulate multiple consecutive network replies over a defined interval using timers. More...
struct  RequestSenderMock
 A mock implementation of the networking::RequestSender interface for testing purposes. It is designed to support unit testing of components that rely on sending network requests by mocking the functionality of the RequestSender interface. It eliminates the need for actual network communication during tests, enabling controlled and reproducible test environments. More...

Functions

DRN_NETWORKING_TESTING_EXPORT bool waitForSignal (const ::QSignalSpy &spy, std::chrono::milliseconds waitFor)
 Waits for a specific signal to be emitted within a given timeout duration. It is useful in testing scenarios to verify if a signal has been emitted within the specified time. It helps validate asynchronous behavior in components that rely on signals to notify changes or complete operations.
DRN_NETWORKING_TESTING_EXPORT bool waitForSignal (const ::QSignalSpy &spy, std::chrono::milliseconds waitFor, const ::qint32 minCount)
 Waits for a specific signal to be emitted within a given timeout duration. It is useful in testing scenarios to verify if a signal has been emitted within the specified time. It helps validate asynchronous behavior in components that rely on signals to notify changes or complete operations.
DRN_NETWORKING_TESTING_EXPORT bool waitUntil (const std::function< bool()> &waitCondition, const std::chrono::milliseconds &timeout)
 Provides a blocking wait until a condition is true or until a timeout occurs.
DRN_NETWORKING_TESTING_EXPORT bool waitWhile (const std::function< bool()> &waitCondition, const std::chrono::milliseconds &timeout)
 Provides a blocking wait while a condition is true or until a timeout occurs.

Function Documentation

◆ waitForSignal() [1/2]

DRN_NETWORKING_TESTING_EXPORT bool drn::networking::testing::waitForSignal ( const ::QSignalSpy & spy,
std::chrono::milliseconds waitFor )
nodiscard

Waits for a specific signal to be emitted within a given timeout duration. It is useful in testing scenarios to verify if a signal has been emitted within the specified time. It helps validate asynchronous behavior in components that rely on signals to notify changes or complete operations.

The signal is monitored using a QSignalSpy object, which tracks signal emissions. If the signal is emitted within the specified timeout, the function completes successfully. Otherwise, the function blocks until the timeout expires.

Parameters
spyThe QSignalSpy instance that observes the signal to be tested.
waitForThe maximum duration to wait for the signal to be emitted.

Usage:

  • Use this method in test cases involving asynchronous signal emissions.
  • Make sure the QSignalSpy is properly connected to the desired signal before calling this function.
Returns
Gives true when the signal has been emitted before the timeout, false otherwise.

◆ waitForSignal() [2/2]

DRN_NETWORKING_TESTING_EXPORT bool drn::networking::testing::waitForSignal ( const ::QSignalSpy & spy,
std::chrono::milliseconds waitFor,
const ::qint32 minCount )
nodiscard

Waits for a specific signal to be emitted within a given timeout duration. It is useful in testing scenarios to verify if a signal has been emitted within the specified time. It helps validate asynchronous behavior in components that rely on signals to notify changes or complete operations.

The signal is monitored using a QSignalSpy object, which tracks signal emissions. If the signal is emitted within the specified timeout, the function completes successfully. Otherwise, the function blocks until the timeout expires.

Parameters
spyThe QSignalSpy instance that observes the signal to be tested.
waitForThe maximum duration to wait for the signal to be emitted.
minCountThe minimum number of signal emissions required to stop waiting.

Usage:

  • Use this method in test cases involving asynchronous signal emissions.
  • Make sure the QSignalSpy is properly connected to the desired signal before calling this function.
Returns
Gives true when the signal has been emitted at least minCount times before the timeout, false otherwise.

◆ waitUntil()

DRN_NETWORKING_TESTING_EXPORT bool drn::networking::testing::waitUntil ( const std::function< bool()> & waitCondition,
const std::chrono::milliseconds & timeout )
nodiscard

Provides a blocking wait until a condition is true or until a timeout occurs.

Parameters
waitConditionA function that determines if a wait is over. The function should return false to keep waiting and /true/ when it should end.
timeoutThe amount of time to wait for a condition to be true.
Returns
Gives true when the wait completed before the timeout, false otherwise.

◆ waitWhile()

DRN_NETWORKING_TESTING_EXPORT bool drn::networking::testing::waitWhile ( const std::function< bool()> & waitCondition,
const std::chrono::milliseconds & timeout )
nodiscard

Provides a blocking wait while a condition is true or until a timeout occurs.

Parameters
waitConditionA function that determines if a wait is over. The function should return true to keep waiting and false when it should end.
timeoutThe amount of time to wait for a condition to be true.
Returns
Gives true when the wait completed before the timeout, false otherwise.