4
0
mirror of https://github.com/QuasarApp/CMakeProject.git synced 2025-04-26 05:34:34 +00:00
CMakeProject/tests/units/testutils.cpp
EndrII 1c06bf8477 major template update
* fix copyright
* fix library structure of the source codes
* added support version value of the library
* fix source location of the generated gocumentatio (powered by doxygen)
2022-01-19 11:05:03 +03:00

54 lines
1.5 KiB
C++

//#
//# Copyright (C) 2020-2022 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#include "testutils.h"
#include <QCoreApplication>
#include <QDateTime>
#include <QVariantMap>
bool TestUtils::funcPrivateConnect(const std::function<bool()> &requestFunc,
const std::function<bool()> &checkFunc,
const std::function<QMetaObject::Connection()> &connectFunction) const {
QMetaObject::Connection m_connection = connectFunction();
if (requestFunc && !requestFunc()) {
QObject::disconnect(m_connection);
return false;
}
bool return_value = TestUtils::wait(checkFunc, 10000);
QObject::disconnect(m_connection);
return return_value;
}
bool TestUtils::funcPrivateConnect(const std::function<bool ()> &requestFunc,
const std::function<bool ()> &checkFunc) const {
return funcPrivateConnect(requestFunc, checkFunc, [](){return QMetaObject::Connection();});
}
TestUtils::TestUtils()
{
}
TestUtils::~TestUtils() {
}
bool TestUtils::wait(const std::function<bool()> &forWait, int msec) const {
auto curmsec = QDateTime::currentMSecsSinceEpoch() + msec;
while (curmsec > QDateTime::currentMSecsSinceEpoch() && !forWait()) {
QCoreApplication::processEvents();
}
QCoreApplication::processEvents();
return forWait();
}