SecretService 0.13.2d47dfe
SecretService is base back end library for your c++ Qt projects.
testutils.cpp
Go to the documentation of this file.
1//#
2//# Copyright (C) 2024-2024 QuasarApp.
3//# Distributed under the GPLv3 software license, see the accompanying
4//# Everyone is permitted to copy and distribute verbatim copies
5//# of this license document, but changing it is not allowed.
6//#
7
8
9#include "testutils.h"
10
11#include <QCoreApplication>
12#include <QDateTime>
13#include <QVariantMap>
14
15namespace testcore {
16
17bool TestUtils::funcPrivateConnect(const std::function<bool()> &requestFunc,
18 const std::function<bool()> &checkFunc,
19 const std::function<QMetaObject::Connection()> &connectFunction) const {
20
21 QMetaObject::Connection m_connection = connectFunction();
22 if (requestFunc && !requestFunc()) {
23 QObject::disconnect(m_connection);
24 return false;
25 }
26
27 bool return_value = TestUtils::wait(checkFunc, 10000);
28 QObject::disconnect(m_connection);
29
30 return return_value;
31}
32
33bool TestUtils::funcPrivateConnect(const std::function<bool ()> &requestFunc,
34 const std::function<bool ()> &checkFunc) const {
35 return funcPrivateConnect(requestFunc, checkFunc, [](){return QMetaObject::Connection();});
36}
37
42
46
47bool TestUtils::wait(const std::function<bool()> &forWait, int msec) const {
48 auto curmsec = QDateTime::currentMSecsSinceEpoch() + msec;
49 while (curmsec > QDateTime::currentMSecsSinceEpoch() && !forWait()) {
50 QCoreApplication::processEvents();
51 }
52 QCoreApplication::processEvents();
53 return forWait();
54}
55}
bool wait(const std::function< bool()> &forWait, int msec) const
Definition testutils.cpp:47
bool funcPrivateConnect(const std::function< bool()> &requestFunc, const std::function< bool()> &checkFunc, const std::function< QMetaObject::Connection()> &connectFunction) const
Definition testutils.cpp:17