From 5b78e0da1d64b6096829f54b29f14ec5643b5ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Fri, 15 May 2015 16:00:32 +0200 Subject: Async: rename Async namespace to KAsync --- async/autotests/asynctest.cpp | 192 +++++++++++++++++++++--------------------- async/autotests/kjobtest.cpp | 4 +- 2 files changed, 98 insertions(+), 98 deletions(-) (limited to 'async/autotests') diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp index 9bc9f6b..ffc732c 100644 --- a/async/autotests/asynctest.cpp +++ b/async/autotests/asynctest.cpp @@ -82,7 +82,7 @@ private: template class AsyncSimulator { public: - AsyncSimulator(Async::Future &future, const T &result) + AsyncSimulator(KAsync::Future &future, const T &result) : mFuture(future) , mResult(result) { @@ -99,7 +99,7 @@ private: mTimer.start(200); } - AsyncSimulator(Async::Future &future, std::function&)> callback) + AsyncSimulator(KAsync::Future &future, std::function&)> callback) : mFuture(future) , mCallback(callback) { @@ -116,8 +116,8 @@ private: } private: - Async::Future mFuture; - std::function&)> mCallback; + KAsync::Future mFuture; + std::function&)> mCallback; T mResult; QTimer mTimer; }; @@ -127,7 +127,7 @@ private: template<> class AsyncTest::AsyncSimulator { public: - AsyncSimulator(Async::Future &future) + AsyncSimulator(KAsync::Future &future) : mFuture(future) { QObject::connect(&mTimer, &QTimer::timeout, @@ -143,7 +143,7 @@ public: } private: - Async::Future mFuture; + KAsync::Future mFuture; QTimer mTimer; }; @@ -151,24 +151,24 @@ private: void AsyncTest::testSyncPromises() { - auto baseJob = Async::start( - [](Async::Future &f) { + auto baseJob = KAsync::start( + [](KAsync::Future &f) { f.setValue(42); f.setFinished(); }) .then( - [](int v, Async::Future &f) { - f.setValue("Result is " + QString::number(v)); + [](int v, KAsync::Future &f) { + f.setValue(QLatin1String("Result is ") + QString::number(v)); f.setFinished(); }); auto job = baseJob.then( - [](const QString &v, Async::Future &f) { + [](const QString &v, KAsync::Future &f) { f.setValue(v.toUpper()); f.setFinished(); }); - Async::Future future = job.exec(); + KAsync::Future future = job.exec(); QVERIFY(future.isFinished()); QCOMPARE(future.value(), QString::fromLatin1("RESULT IS 42")); @@ -176,12 +176,12 @@ void AsyncTest::testSyncPromises() void AsyncTest::testAsyncPromises() { - auto job = Async::start( - [](Async::Future &future) { + auto job = KAsync::start( + [](KAsync::Future &future) { new AsyncSimulator(future, 42); }); - Async::Future future = job.exec(); + KAsync::Future future = job.exec(); future.waitForFinished(); QCOMPARE(future.value(), 42); @@ -191,11 +191,11 @@ void AsyncTest::testAsyncPromises2() { bool done = false; - auto job = Async::start( - [](Async::Future &future) { + auto job = KAsync::start( + [](KAsync::Future &future) { new AsyncSimulator(future, 42); } - ).then([&done](int result, Async::Future &future) { + ).then([&done](int result, KAsync::Future &future) { done = true; future.setValue(result); future.setFinished(); @@ -210,17 +210,17 @@ void AsyncTest::testNestedAsync() { bool done = false; - auto job = Async::start( - [](Async::Future &future) { - auto innerJob = Async::start([](Async::Future &innerFuture) { + auto job = KAsync::start( + [](KAsync::Future &future) { + auto innerJob = KAsync::start([](KAsync::Future &innerFuture) { new AsyncSimulator(innerFuture, 42); - }).then([&future](Async::Future &innerThenFuture) { + }).then([&future](KAsync::Future &innerThenFuture) { future.setFinished(); innerThenFuture.setFinished(); }); innerJob.exec().waitForFinished(); } - ).then([&done](int result, Async::Future &future) { + ).then([&done](int result, KAsync::Future &future) { done = true; future.setValue(result); future.setFinished(); @@ -232,8 +232,8 @@ void AsyncTest::testNestedAsync() void AsyncTest::testStartValue() { - auto job = Async::start( - [](int in, Async::Future &future) { + auto job = KAsync::start( + [](int in, KAsync::Future &future) { future.setValue(in); future.setFinished(); }); @@ -249,8 +249,8 @@ void AsyncTest::testStartValue() void AsyncTest::testAsyncThen() { - auto job = Async::start( - [](Async::Future &future) { + auto job = KAsync::start( + [](KAsync::Future &future) { new AsyncSimulator(future, 42); }); @@ -264,7 +264,7 @@ void AsyncTest::testAsyncThen() void AsyncTest::testSyncThen() { - auto job = Async::start( + auto job = KAsync::start( []() -> int { return 42; }) @@ -280,13 +280,13 @@ void AsyncTest::testSyncThen() void AsyncTest::testJoinedThen() { - auto job1 = Async::start( - [](int in, Async::Future &future) { + auto job1 = KAsync::start( + [](int in, KAsync::Future &future) { new AsyncSimulator(future, in * 2); }); - auto job2 = Async::start( - [](Async::Future &future) { + auto job2 = KAsync::start( + [](KAsync::Future &future) { new AsyncSimulator(future, 42); }) .then(job1); @@ -302,13 +302,13 @@ void AsyncTest::testVoidThen() { int check = 0; - auto job = Async::start( - [&check](Async::Future &future) { + auto job = KAsync::start( + [&check](KAsync::Future &future) { new AsyncSimulator(future); ++check; }) .then( - [&check](Async::Future &future) { + [&check](KAsync::Future &future) { new AsyncSimulator(future); ++check; }) @@ -328,12 +328,12 @@ void AsyncTest::testVoidThen() void AsyncTest::testAsyncEach() { - auto job = Async::start>( - [](Async::Future> &future) { + auto job = KAsync::start>( + [](KAsync::Future> &future) { new AsyncSimulator>(future, { 1, 2, 3, 4 }); }) .each, int>( - [](const int &v, Async::Future> &future) { + [](const int &v, KAsync::Future> &future) { new AsyncSimulator>(future, { v + 1 }); }); @@ -347,7 +347,7 @@ void AsyncTest::testAsyncEach() void AsyncTest::testSyncEach() { - auto job = Async::start>( + auto job = KAsync::start>( []() -> QList { return { 1, 2, 3, 4 }; }) @@ -356,7 +356,7 @@ void AsyncTest::testSyncEach() return { v + 1 }; }); - Async::Future> future = job.exec(); + KAsync::Future> future = job.exec(); const QList expected({ 2, 3, 4, 5 }); QVERIFY(future.isFinished()); @@ -365,12 +365,12 @@ void AsyncTest::testSyncEach() void AsyncTest::testJoinedEach() { - auto job1 = Async::start, int>( - [](int v, Async::Future> &future) { + auto job1 = KAsync::start, int>( + [](int v, KAsync::Future> &future) { new AsyncSimulator>(future, { v * 2 }); }); - auto job = Async::start>( + auto job = KAsync::start>( []() -> QList { return { 1, 2, 3, 4 }; }) @@ -387,7 +387,7 @@ void AsyncTest::testJoinedEach() void AsyncTest::testVoidEachThen() { QList check; - auto job = Async::start>( + auto job = KAsync::start>( []() -> QList { return { 1, 2, 3, 4 }; }).each( @@ -406,14 +406,14 @@ void AsyncTest::testAsyncVoidEachThen() { bool completedJob = false; QList check; - auto job = Async::start>( - [](Async::Future > &future) { + auto job = KAsync::start>( + [](KAsync::Future > &future) { new AsyncSimulator>(future, { 1, 2, 3, 4 }); }).each( - [&check](const int &v, Async::Future &future) { + [&check](const int &v, KAsync::Future &future) { check << v; new AsyncSimulator(future); - }).then([&completedJob](Async::Future &future) { + }).then([&completedJob](KAsync::Future &future) { completedJob = true; future.setFinished(); }); @@ -433,14 +433,14 @@ void AsyncTest::testAsyncVoidEachThen() void AsyncTest::testAsyncReduce() { - auto job = Async::start>( - [](Async::Future> &future) { + auto job = KAsync::start>( + [](KAsync::Future> &future) { new AsyncSimulator>(future, { 1, 2, 3, 4 }); }) .reduce>( - [](const QList &list, Async::Future &future) { + [](const QList &list, KAsync::Future &future) { new AsyncSimulator(future, - [list](Async::Future &future) { + [list](KAsync::Future &future) { int sum = 0; for (int i : list) sum += i; future.setValue(sum); @@ -449,7 +449,7 @@ void AsyncTest::testAsyncReduce() ); }); - Async::Future future = job.exec(); + KAsync::Future future = job.exec(); future.waitForFinished(); QVERIFY(future.isFinished()); @@ -458,7 +458,7 @@ void AsyncTest::testAsyncReduce() void AsyncTest::testSyncReduce() { - auto job = Async::start>( + auto job = KAsync::start>( []() -> QList { return { 1, 2, 3, 4 }; }) @@ -469,7 +469,7 @@ void AsyncTest::testSyncReduce() return sum; }); - Async::Future future = job.exec(); + KAsync::Future future = job.exec(); QVERIFY(future.isFinished()); QCOMPARE(future.value(), 10); @@ -478,14 +478,14 @@ void AsyncTest::testSyncReduce() void AsyncTest::testJoinedReduce() { - auto job1 = Async::start>( - [](const QList &list, Async::Future &future) { + auto job1 = KAsync::start>( + [](const QList &list, KAsync::Future &future) { int sum = 0; for (int i : list) sum += i; new AsyncSimulator(future, sum); }); - auto job = Async::start>( + auto job = KAsync::start>( []() -> QList { return { 1, 2, 3, 4 }; }) @@ -502,7 +502,7 @@ void AsyncTest::testVoidReduce() { // This must not compile (reduce with void result makes no sense) #ifdef TEST_BUILD_FAIL - auto job = Async::start>( + auto job = KAsync::start>( []() -> QList { return { 1, 2, 3, 4 }; }) @@ -522,8 +522,8 @@ void AsyncTest::testProgressReporting() static int progress; progress = 0; - auto job = Async::start( - [](Async::Future &f) { + auto job = KAsync::start( + [](KAsync::Future &f) { QTimer *timer = new QTimer(); connect(timer, &QTimer::timeout, [&f, timer]() { @@ -538,8 +538,8 @@ void AsyncTest::testProgressReporting() }); int progressCheck = 0; - Async::FutureWatcher watcher; - connect(&watcher, &Async::FutureWatcher::futureProgress, + KAsync::FutureWatcher watcher; + connect(&watcher, &KAsync::FutureWatcher::futureProgress, [&progressCheck](qreal progress) { progressCheck++; // FIXME: Don't use Q_ASSERT in unit tests @@ -556,9 +556,9 @@ void AsyncTest::testErrorHandler() { { - auto job = Async::start( - [](Async::Future &f) { - f.setError(1, "error"); + auto job = KAsync::start( + [](KAsync::Future &f) { + f.setError(1, QLatin1String("error")); }); auto future = job.exec(); @@ -569,9 +569,9 @@ void AsyncTest::testErrorHandler() { int error = 0; - auto job = Async::start( - [](Async::Future &f) { - f.setError(1, "error"); + auto job = KAsync::start( + [](KAsync::Future &f) { + f.setError(1, QLatin1String("error")); }, [&error](int errorCode, const QString &errorMessage) { error += errorCode; @@ -590,12 +590,12 @@ void AsyncTest::testErrorPropagation() { int error = 0; bool called = false; - auto job = Async::start( - [](Async::Future &f) { - f.setError(1, "error"); + auto job = KAsync::start( + [](KAsync::Future &f) { + f.setError(1, QLatin1String("error")); }) .then( - [&called](int v, Async::Future &f) { + [&called](int v, KAsync::Future &f) { called = true; f.setFinished(); }, @@ -614,11 +614,11 @@ void AsyncTest::testErrorPropagation() void AsyncTest::testErrorHandlerAsync() { { - auto job = Async::start( - [](Async::Future &f) { + auto job = KAsync::start( + [](KAsync::Future &f) { new AsyncSimulator(f, - [](Async::Future &f) { - f.setError(1, "error"); + [](KAsync::Future &f) { + f.setError(1, QLatin1String("error")); } ); } @@ -634,11 +634,11 @@ void AsyncTest::testErrorHandlerAsync() { int error = 0; - auto job = Async::start( - [](Async::Future &f) { + auto job = KAsync::start( + [](KAsync::Future &f) { new AsyncSimulator(f, - [](Async::Future &f) { - f.setError(1, "error"); + [](KAsync::Future &f) { + f.setError(1, QLatin1String("error")); } ); }, @@ -661,16 +661,16 @@ void AsyncTest::testErrorPropagationAsync() { int error = 0; bool called = false; - auto job = Async::start( - [](Async::Future &f) { + auto job = KAsync::start( + [](KAsync::Future &f) { new AsyncSimulator(f, - [](Async::Future &f) { - f.setError(1, "error"); + [](KAsync::Future &f) { + f.setError(1, QLatin1String("error")); } ); }) .then( - [&called](int v, Async::Future &f) { + [&called](int v, KAsync::Future &f) { called = true; f.setFinished(); }, @@ -692,9 +692,9 @@ void AsyncTest::testErrorPropagationAsync() void AsyncTest::testNestedErrorPropagation() { int error = 0; - auto job = Async::start([](){}) - .then(Async::error(1, "error")) //Nested job that throws error - .then([](Async::Future &future) { + auto job = KAsync::start([](){}) + .then(KAsync::error(1, QLatin1String("error"))) //Nested job that throws error + .then([](KAsync::Future &future) { //We should never get here Q_ASSERT(false); }, @@ -719,8 +719,8 @@ void AsyncTest::testChainingRunningJob() { int check = 0; - auto job = Async::start( - [&check](Async::Future &future) { + auto job = KAsync::start( + [&check](KAsync::Future &future) { QTimer *timer = new QTimer(); QObject::connect(timer, &QTimer::timeout, [&future, &check]() { @@ -763,7 +763,7 @@ void AsyncTest::testChainingFinishedJob() { int check = 0; - auto job = Async::start( + auto job = KAsync::start( [&check]() -> int { ++check; return 42; @@ -799,7 +799,7 @@ void AsyncTest::testLifetimeWithoutHandle() { bool done = false; { - auto job = Async::start([&done](Async::Future &future) { + auto job = KAsync::start([&done](KAsync::Future &future) { QTimer *timer = new QTimer(); QObject::connect(timer, &QTimer::timeout, [&future, &done]() { @@ -823,9 +823,9 @@ void AsyncTest::testLifetimeWithoutHandle() */ void AsyncTest::testLifetimeWithHandle() { - Async::Future future; + KAsync::Future future; { - auto job = Async::start([](Async::Future &future) { + auto job = KAsync::start([](KAsync::Future &future) { QTimer *timer = new QTimer(); QObject::connect(timer, &QTimer::timeout, [&future]() { @@ -844,7 +844,7 @@ void AsyncTest::testLifetimeWithHandle() void AsyncTest::benchmarkSyncThenExecutor() { - auto job = Async::start( + auto job = KAsync::start( []() -> int { return 0; }); diff --git a/async/autotests/kjobtest.cpp b/async/autotests/kjobtest.cpp index be92d68..15e50de 100644 --- a/async/autotests/kjobtest.cpp +++ b/async/autotests/kjobtest.cpp @@ -43,7 +43,7 @@ private Q_SLOTS: void KJobTest::testSingleKJob() { - auto job = Async::start(); + auto job = KAsync::start(); auto future = job.exec(42); future.waitForFinished(); @@ -54,7 +54,7 @@ void KJobTest::testSingleKJob() void KJobTest::testKJobChain() { - auto job = Async::start() + auto job = KAsync::start() .then(); auto future = job.exec(42); -- cgit v1.2.3