Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+148
@@ -0,0 +1,148 @@
|
||||
#include "dev_ftcmock.h"
|
||||
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsWidgets/lts_global_wait_dialog.h>
|
||||
|
||||
#include <QTimer>
|
||||
#include <QRandomGenerator>
|
||||
#include <QLabel>
|
||||
#include <QEventLoop>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace DeveloperTools
|
||||
{
|
||||
FtcMock::FtcMock(LtsSession::LtsSession *session, int min, int max, int timers)
|
||||
: m_session(session)
|
||||
, m_exmFtc(ExerciseManagement::Interface::Ftc::create(m_session->ddsConnector()))
|
||||
, m_gen(QRandomGenerator::global())
|
||||
, m_min(min)
|
||||
, m_max(max)
|
||||
{
|
||||
for (int i = 0; i <= timers; i++)
|
||||
{
|
||||
auto *t = new QTimer(this);
|
||||
t->setSingleShot(true);
|
||||
t->setInterval(m_gen->bounded(min, max));
|
||||
QObject::connect(t, &QTimer::timeout, this, &FtcMock::mock, Qt::QueuedConnection);
|
||||
t->start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FtcMock::mock()
|
||||
{
|
||||
QPointer<QTimer> t(static_cast<QTimer *>(sender()));
|
||||
|
||||
uint32_t bit = 32;
|
||||
#define CHANCE(x) (((flags >> (bit-=x)) & x) == x)
|
||||
const uint32_t flags = m_gen->generate();
|
||||
auto exmFtc = m_exmFtc;
|
||||
|
||||
auto go = [this, flags, &bit, &exmFtc]()
|
||||
{
|
||||
bool useOwnFtc = CHANCE(0b111);
|
||||
|
||||
if (useOwnFtc)
|
||||
{
|
||||
fprintf(stderr, "ftcmock: use own, new ftc\n");
|
||||
exmFtc = ExerciseManagement::Interface::Ftc::create(m_session->ddsConnector(), true /*don't reuse*/);
|
||||
}
|
||||
|
||||
exmFtc->enableGetExerciseImage();
|
||||
auto req = ExerciseManagement::GetExerciseImageRequest();
|
||||
req.exerciseId(42);
|
||||
ExerciseManagement::GetExerciseImageReply rep;
|
||||
try
|
||||
{
|
||||
//Waiter _;
|
||||
rep = exmFtc->getExerciseImageRequest(req);
|
||||
}
|
||||
catch(const std::runtime_error &ex)
|
||||
{
|
||||
qWarning() << "!!!!!!!!!!!!!!!!! getExerciseImageRequest error: " << ex.what();
|
||||
//Q_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (useOwnFtc && CHANCE(0b11))
|
||||
{
|
||||
// wait for thread to time out & die
|
||||
auto *l = new QLabel;
|
||||
QEventLoop x;
|
||||
QObject::connect(l, &QLabel::linkActivated, &x, &QEventLoop::quit);
|
||||
QTimer::singleShot(13000, l, [l](){ emit l->linkActivated({}); });
|
||||
fprintf(stderr, "ftcmock: WAITING FOR THREAD TO TIME OUT & DIE....\n");
|
||||
x.exec();
|
||||
fprintf(stderr, "ftcmock: DONE!\n");
|
||||
l->deleteLater();
|
||||
|
||||
|
||||
// ... then get again to start the thread again
|
||||
ExerciseManagement::GetExerciseImageReply rep;
|
||||
try
|
||||
{
|
||||
//Waiter _;
|
||||
rep = exmFtc->getExerciseImageRequest(req);
|
||||
}
|
||||
catch(const std::runtime_error &ex)
|
||||
{
|
||||
qWarning() << "!!!!!!!!!!!!!!!!! getExerciseImageRequest #2 error: " << ex.what();
|
||||
//Q_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
exmFtc->enableExerciseImageModify();
|
||||
auto req2 = ExerciseManagement::ExerciseImageModifyRequest(42, rep.imageData());
|
||||
try
|
||||
{
|
||||
//Waiter _;
|
||||
auto id = exmFtc->exerciseImageModifyRequest(req2);
|
||||
if (id < 1)
|
||||
{
|
||||
qWarning() << "id < 1";
|
||||
Q_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(const std::runtime_error &ex)
|
||||
{
|
||||
qWarning() << "!!!!!!!!!!!!!!!!! exerciseImageModifyRequest error: " << ex.what();
|
||||
//Q_ASSERT(false);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
go();
|
||||
|
||||
if (CHANCE(0b11))
|
||||
{
|
||||
fprintf(stderr, "ftcmock: again #1\n");
|
||||
go(); // again
|
||||
}
|
||||
|
||||
if (CHANCE(0b11))
|
||||
{
|
||||
fprintf(stderr, "ftcmock: again #2\n");
|
||||
go(); // again
|
||||
}
|
||||
|
||||
|
||||
if (!t)
|
||||
return;
|
||||
|
||||
t->setInterval(m_gen->bounded(m_min, m_max));
|
||||
fprintf(stderr, "ftcmock: in %d ms\n", t->interval());
|
||||
t->start();
|
||||
}
|
||||
|
||||
|
||||
FtcMock::~FtcMock()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace DeveloperTools
|
||||
Reference in new issue
Block a user