Verified Commit 2abcb75b authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Fix build

parent 8e61c1c4
/*
Copyright (c) 2020 Daniel Vrátil <dvratil@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "async.h"
#include <QObject>
#include <QTest>
#include <QTimer>
using namespace Akonadi::Async;
class AsyncTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testSimpleTask()
{
Task<int> task;
QVERIFY(!task.isFinished());
task.setResult(42);
QVERIFY(task.isFinished());
QCOMPARE(task.result(), 42);
}
void testSimpleTaskExec()
{
Task<int> task;
QTimer::singleShot(std::chrono::milliseconds{100}, [&task]() mutable {
task.setResult(42);
});
task.wait();
QVERIFY(task.isFinished());
QCOMPARE(task.result(), 42);
}
void testSimpleThen()
{
Task<int> task;
auto res = task.then([](int val) { return QString::number(val); });
QVERIFY(!task.isFinished());
QVERIFY(!res.isFinished());
task.setResult(42);
QVERIFY(task.isFinished());
QVERIFY(res.isFinished());
QCOMPARE(res.result(), QStringLiteral("42"));
}
void testTemporarySyncTask()
{
const auto func = []() {
Task<int> task;
task.setResult(42);
return task;
};
const auto res = func().then([](int val) { return QString::number(val); });
QVERIFY(res.isFinished());
QCOMPARE(res.result(), QStringLiteral("42"));
}
void testTemporaryAsyncTask()
{
const auto func = []() {
Task<int> task;
QTimer::singleShot(std::chrono::milliseconds{100}, [task]() mutable {
task.setResult(42);
});
return task;
};
const auto res = func().then([](int val) { return QString::number(val);} );
QVERIFY(!res.isFinished());
res.wait();
QVERIFY(res.isFinished());
QCOMPARE(res.result(), QStringLiteral("42"));
}
void testSyncContinuationChain()
{
const auto f1 = [](int val) { return QString::number(val); };
const auto f2 = [](const QString &val) { return val.toInt() * 2; };
Task<int> t;
auto task = t.then(f1).then(f2);
QVERIFY(!t.isFinished());
QVERIFY(!task.isFinished());
t.setResult(42);
QVERIFY(t.isFinished());
QVERIFY(task.isFinished());
QCOMPARE(task.result(), 84);
}
void testAsyncContinuationChain()
{
const auto f1 = [](int val) {
Task<QString> task;
QTimer::singleShot(std::chrono::milliseconds{100}, [val, task]() mutable { task.setResult(QString::number(val)); });
return task;
};
const auto f2 = [](const QString &val) {
Task<int> task;
QTimer::singleShot(std::chrono::milliseconds{100}, [val, task]() mutable { task.setResult(val.toInt() * 2); });
return task;
};
Task<int> task;
Task<QString> = task.then(f1);
Task<int> result = task.then(f1).then(f2);
QTimer::singleShot(std::chrono::milliseconds{100}, [task]() mutable { task.setResult(42); });
QVERIFY(!task.isFinished());
QVERIFY(!result.isFinished());
task.wait();
QVERIFY(task.isFinished());
QVERIFY(!result.isFinished());
result.wait();
QVERIFY(result.isFinished());
QCOMPARE(result.result(), 84);
}
};
QTEST_GUILESS_MAIN(AsyncTest)
#include "asynctest.moc"
......@@ -19,6 +19,7 @@
#include "itemfetchtest.h"
#include "testattribute.h"
#include "test_utils.h"
#include <attributefactory.h>
#include <itemcreatejob.h>
......@@ -42,7 +43,7 @@ void ItemFetchTest::initTestCase()
void ItemFetchTest::testFetch()
{
const int colId = AkonadiTest::collectionIdFromPath(QStringLiteral("res1"));
const int colId = collectionIdFromPath(QStringLiteral("res1"));
QVERIFY(colId > -1);
// listing of an empty folder
......@@ -50,7 +51,7 @@ void ItemFetchTest::testFetch()
AKVERIFYEXEC(job);
QVERIFY(job->items().isEmpty());
const int colId2 = AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo"));
const int colId2 = collectionIdFromPath(QStringLiteral("res1/foo"));
QVERIFY(colId > -1);
// listing of a non-empty folder
......@@ -183,7 +184,7 @@ void ItemFetchTest::testMultipartFetch()
QFETCH(bool, fetchSinglePayload);
QFETCH(bool, fetchSingleAttr);
int colId = AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo"));
int colId = collectionIdFromPath(QStringLiteral("res1/foo"));
QVERIFY(colId >= 0);
Item item;
......@@ -275,7 +276,7 @@ void ItemFetchTest::testAncestorRetrieval()
void ItemFetchTest::testRetrievalOfAttributeWithEmptyBody()
{
const auto colId = AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo"));
const auto colId = collectionIdFromPath(QStringLiteral("res1/foo"));
QVERIFY(colId > -1);
auto testFetch = new ItemFetchJob(Collection(colId), this);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment