LeechCraft 0.6.70-19424-g027e980fd1
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
slotclosuretest.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 "slotclosuretest.h"
10#include <QPointer>
11#include <QTest>
12#include "slotclosure.h"
13
14QTEST_GUILESS_MAIN (LC::Util::SlotClosureTest)
15
16namespace LC
17{
18namespace Util
19{
21 {
22 emit someSignal ();
23 }
24
25 void SlotClosureTest::testDeleteLater ()
26 {
27 DummyObject obj;
28
29 bool hasRun = false;
30 const auto closure = new SlotClosure<DeleteLaterPolicy>
31 {
32 [&hasRun]
33 {
34 hasRun = true;
35 },
36 &obj,
37 SIGNAL (someSignal ()),
38 nullptr
39 };
40
41 obj.EmitSignal ();
42
43 const QPointer<QObject> closurePtr { closure };
44
45 QCOMPARE (hasRun, true);
46 QCOMPARE (closurePtr.isNull (), false);
47
48 QCoreApplication::sendPostedEvents (nullptr, QEvent::DeferredDelete);
49
50 QCOMPARE (closurePtr.isNull (), true);
51 }
52
53 void SlotClosureTest::testNoDelete ()
54 {
55 DummyObject obj;
56
57 bool hasRun = false;
58 const auto closure = new SlotClosure<NoDeletePolicy>
59 {
60 [&hasRun]
61 {
62 hasRun = true;
63 },
64 &obj,
65 SIGNAL (someSignal ()),
66 nullptr
67 };
68
69 obj.EmitSignal ();
70
71 const QPointer<QObject> closurePtr { closure };
72
73 QCOMPARE (hasRun, true);
74 QCOMPARE (closurePtr.isNull (), false);
75
76 QCoreApplication::sendPostedEvents (nullptr, QEvent::DeferredDelete);
77
78 QCOMPARE (closurePtr.isNull (), false);
79
80 delete closure;
81 }
82
83 void SlotClosureTest::testChoiceDelete ()
84 {
85 DummyObject obj;
86
87 bool hasRun = false;
88 const auto closure = new SlotClosure<ChoiceDeletePolicy>
89 {
90 [&hasRun]
91 {
92 if (hasRun)
94
95 hasRun = true;
97 },
98 &obj,
99 SIGNAL (someSignal ()),
100 nullptr
101 };
102 const QPointer<QObject> closurePtr { closure };
103
104 obj.EmitSignal ();
105
106 QCOMPARE (hasRun, true);
107 QCOMPARE (closurePtr.isNull (), false);
108
109 QCoreApplication::sendPostedEvents (nullptr, QEvent::DeferredDelete);
110
111 QCOMPARE (closurePtr.isNull (), false);
112
113 obj.EmitSignal ();
114 QCoreApplication::sendPostedEvents (nullptr, QEvent::DeferredDelete);
115
116 QCOMPARE (closurePtr.isNull (), true);
117 }
118}
119}
@ Yes
Delete SlotClosure after this invocation.
@ No
Do not delete SlotClosure after this invocation.
Executes a given functor upon a signal (or a list of signals).
Definition slotclosure.h:81
Definition constants.h:15