LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
workerthreadtest.cpp
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#include "
workerthreadtest.h
"
10
#include <QtTest>
11
#include <
workerthreadbase.h
>
12
13
QTEST_MAIN (
LC::Util::WorkerThreadTest
)
14
15
namespace
LC::Util
16
{
17
struct
Worker
18
{
19
QThread *
const
Main_
;
20
int
&
Val_
;
21
22
explicit
Worker
(
int
*val, QThread *main)
23
:
Main_
{ main }
24
,
Val_
{ *val }
25
{
26
}
27
28
void
Increment
(
int
n)
29
{
30
qDebug () << QThread::currentThread ();
31
QVERIFY (QThread::currentThread () !=
Main_
);
32
33
Val_
+= n;
34
}
35
36
void
Quit
(QEventLoop& loop)
37
{
38
QTimer::singleShot (0, &loop, &QEventLoop::quit);
39
}
40
};
41
42
void
WorkerThreadTest::testWorkerThread ()
43
{
44
QEventLoop loop;
45
auto
spin = [&loop]
46
{
47
QTimer::singleShot (100, &loop, &QEventLoop::quit);
48
loop.exec ();
49
};
50
51
qDebug () << Q_FUNC_INFO << QThread::currentThread ();
52
53
int
val = 0;
54
WorkerThread<Worker> worker { &val, QThread::currentThread () };
55
worker.SetQuitWait (1000);
56
worker.start ();
57
58
worker.SetPaused (
true
);
59
worker.ScheduleImpl (&
Worker::Increment
, 1);
60
worker.ScheduleImpl (&
Worker::Increment
, 2);
61
worker.ScheduleImpl (&
Worker::Increment
, 3);
62
63
spin ();
64
QCOMPARE (val, 0);
65
66
worker.SetPaused (
false
);
67
68
spin ();
69
QCOMPARE (val, 6);
70
71
worker.ScheduleImpl (&
Worker::Increment
, 10);
72
73
spin ();
74
QCOMPARE (val, 16);
75
}
76
}
LC::Util::WorkerThreadTest
Definition
workerthreadtest.h:16
LC::Util
Definition
icoreproxy.h:34
LC::Util::Worker::Worker
Worker(int *val, QThread *main)
Definition
workerthreadtest.cpp:22
LC::Util::Worker::Increment
void Increment(int n)
Definition
workerthreadtest.cpp:28
LC::Util::Worker::Main_
QThread *const Main_
Definition
workerthreadtest.cpp:19
LC::Util::Worker::Quit
void Quit(QEventLoop &loop)
Definition
workerthreadtest.cpp:36
LC::Util::Worker::Val_
int & Val_
Definition
workerthreadtest.cpp:20
workerthreadbase.h
workerthreadtest.h
src
util
threads
tests
workerthreadtest.cpp
Generated by
1.17.0