20 void FuturesTest::testSequencer ()
28 .Then ([&loop, &res] (
int cnt)
36 QCoreApplication::processEvents ();
41 void FuturesTest::testHeterogeneousTypes ()
47 bool executed =
false;
48 Sequence (
nullptr,
MkWaiter () (50)) >>
49 [] (int) {
return MakeReadyFuture<Bar> ({}); } >>
50 [] (Bar) {
return MakeReadyFuture<Baz> ({}); } >>
51 [&executed, &loop] (Baz)
59 QCoreApplication::processEvents ();
61 QCOMPARE (executed,
true);
64 void FuturesTest::testDestruction ()
67 bool executed =
false;
71 Sequence (&obj, MakeReadyFuture (0)) >>
72 [&executed, &loop] (int)
79 QTimer::singleShot (100, &loop, SLOT (quit ()));
83 QCoreApplication::processEvents ();
85 QCOMPARE (executed,
false);
88 void FuturesTest::testDestructionHandler ()
90 const auto finished = 1;
91 const auto destructed = 2;
94 bool executed =
false;
100 future = Sequence (&obj,
MkWaiter () (100))
101 .DestructionValue ([] {
return destructed; }) >>
102 [=] (
int) {
return MakeReadyFuture (finished); };
104 Sequence (
nullptr, future) >>
105 [&executed, &value, &loop] (
int val)
112 QTimer::singleShot (10, &loop, SLOT (quit ()));
116 QCoreApplication::processEvents ();
118 QCOMPARE (executed,
true);
119 QCOMPARE (value, destructed);
122 void FuturesTest::testNoDestrHandler ()
128 bool executed =
false;
129 Sequence (
nullptr,
MkWaiter () (50))
130 .DestructionValue ([&executed] { executed =
true; }) >>
131 [] (
int) {
return MakeReadyFuture<Bar> ({}); } >>
132 [] (Bar) {
return MakeReadyFuture<Baz> ({}); } >>
133 [&loop] (Baz) { loop.quit (); };
137 QCoreApplication::processEvents ();
139 QCOMPARE (executed,
false);
142 void FuturesTest::testNoDestrHandlerSetBuildable ()
144 const auto finished = 1;
147 bool executed =
false;
150 QFuture<int> future = Sequence (
nullptr,
MkWaiter () (10)) >>
151 [=] (int) {
return MakeReadyFuture (finished); };
152 Sequence (
nullptr, future) >>
153 [&executed, &value, &loop] (
int val)
162 QCoreApplication::processEvents ();
164 QCOMPARE (executed,
true);
165 QCOMPARE (value, finished);
168 void FuturesTest::testMulti ()
172 QFutureInterface<int> iface;
176 Sequence (
nullptr, iface.future ())
177 .MultipleResults ([&] (
int sub)
182 [&] { loop.quit (); });
184 iface.reportStarted ();
185 iface.setExpectedResultCount (3);
186 while (iface.resultCount () < iface.expectedResultCount ())
187 iface.reportResult (iface.resultCount () + 1, iface.resultCount ());
188 iface.reportFinished ();
192 QCoreApplication::processEvents ();
198 void FuturesTest::testMultiRange ()
202 QFutureInterface<int> iface;
206 Sequence (
nullptr, iface.future ())
207 .MultipleResults ([&] (
int sub)
212 [&] { loop.quit (); });
214 iface.reportStarted ();
215 iface.setProgressRange (0, 2);
216 iface.reportResult (1, 0);
217 iface.reportResult (2, 1);
218 iface.reportResult (3, 2);
219 iface.reportFinished ();
223 QCoreApplication::processEvents ();
constexpr detail::AggregateType< detail::AggregateFunction::Count, Ptr > count