File indexing completed on 2024-03-24 15:24:59

0001 /*
0002     SPDX-FileCopyrightText: 2012 Dario Freddi <drf@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #include "TestHelper.h"
0008 
0009 #include <helpersupport.h>
0010 
0011 #include <QDebug>
0012 #include <QEventLoop>
0013 #include <QFile>
0014 #include <QTextStream>
0015 #include <QThread>
0016 #include <qplatformdefs.h>
0017 
0018 ActionReply TestHelper::echoaction(QVariantMap args)
0019 {
0020     qDebug() << "Echo action running";
0021     ActionReply reply = ActionReply::SuccessReply();
0022     reply.setData(args);
0023 
0024     return reply;
0025 }
0026 
0027 ActionReply TestHelper::standardaction(QVariantMap args)
0028 {
0029     qDebug() << "Standard action running";
0030     if (args.contains(QLatin1String("fail")) && args[QLatin1String("fail")].toBool()) {
0031         return ActionReply::HelperErrorReply();
0032     }
0033 
0034     return ActionReply::SuccessReply();
0035 }
0036 
0037 ActionReply TestHelper::longaction(QVariantMap args)
0038 {
0039     Q_UNUSED(args);
0040     qDebug() << "Long action running. Don't be scared, this action takes 2 seconds to complete";
0041 
0042     for (int i = 1; i <= 100; i++) {
0043         if (HelperSupport::isStopped()) {
0044             break;
0045         }
0046         if (i == 50) {
0047             QVariantMap map;
0048             map.insert(QLatin1String("Answer"), 42);
0049             HelperSupport::progressStep(map);
0050         }
0051         HelperSupport::progressStep(i);
0052         QThread::usleep(20000);
0053     }
0054 
0055     return ActionReply::SuccessReply();
0056 }
0057 
0058 ActionReply TestHelper::failingaction(QVariantMap args)
0059 {
0060     Q_UNUSED(args)
0061     return ActionReply::HelperErrorReply();
0062 }
0063 
0064 #include "moc_TestHelper.cpp"