LeechCraft 0.6.70-14794-g33744ae6ce
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 <QtTest>
11#include "slotclosure.h"
12
14
15namespace LC
16{
17namespace Util
18{
20 {
21 emit someSignal ();
22 }
23
24 void SlotClosureTest::testDeleteLater ()
25 {
26 DummyObject obj;
27
28 bool hasRun = false;
29 const auto closure = new SlotClosure<DeleteLaterPolicy>
30 {
31 [&hasRun]
32 {
33 hasRun = true;
34 },
35 &obj,
36 SIGNAL (someSignal ()),
37 nullptr
38 };
39
40 obj.EmitSignal ();
41
42 const QPointer<QObject> closurePtr { closure };
43
44 QCOMPARE (hasRun, true);
45 QCOMPARE (closurePtr.isNull (), false);
46
47 QCoreApplication::sendPostedEvents (nullptr, QEvent::DeferredDelete);
48
49 QCOMPARE (closurePtr.isNull (), true);
50 }
51
52 void SlotClosureTest::testNoDelete ()
53 {
54 DummyObject obj;
55
56 bool hasRun = false;
57 const auto closure = new SlotClosure<NoDeletePolicy>
58 {
59 [&hasRun]
60 {
61 hasRun = true;
62 },
63 &obj,
64 SIGNAL (someSignal ()),
65 nullptr
66 };
67
68 obj.EmitSignal ();
69
70 const QPointer<QObject> closurePtr { closure };
71
72 QCOMPARE (hasRun, true);
73 QCOMPARE (closurePtr.isNull (), false);
74
75 QCoreApplication::sendPostedEvents (nullptr, QEvent::DeferredDelete);
76
77 QCOMPARE (closurePtr.isNull (), false);
78 }
79
80 void SlotClosureTest::testChoiceDelete ()
81 {
82 DummyObject obj;
83
84 bool hasRun = false;
85 const auto closure = new SlotClosure<ChoiceDeletePolicy>
86 {
87 [&hasRun]
88 {
89 if (hasRun)
91
92 hasRun = true;
94 },
95 &obj,
96 SIGNAL (someSignal ()),
97 nullptr
98 };
99 const QPointer<QObject> closurePtr { closure };
100
101 obj.EmitSignal ();
102
103 QCOMPARE (hasRun, true);
104 QCOMPARE (closurePtr.isNull (), false);
105
106 QCoreApplication::sendPostedEvents (nullptr, QEvent::DeferredDelete);
107
108 QCOMPARE (closurePtr.isNull (), false);
109
110 obj.EmitSignal ();
111 QCoreApplication::sendPostedEvents (nullptr, QEvent::DeferredDelete);
112
113 QCOMPARE (closurePtr.isNull (), true);
114 }
115}
116}
@ 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