LeechCraft 0.6.70-16373-g319c272718
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 {
22 }
23
24 void SlotClosureTest::testDeleteLater ()
25 {
27
28 bool hasRun = false;
30 {
31 [&hasRun]
32 {
33 hasRun = true;
34 },
35 &obj,
36 SIGNAL (someSignal ()),
37 nullptr
38 };
39
40 obj.EmitSignal ();
41
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;
58 {
59 [&hasRun]
60 {
61 hasRun = true;
62 },
63 &obj,
64 SIGNAL (someSignal ()),
65 nullptr
66 };
67
68 obj.EmitSignal ();
69
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 delete closure;
80 }
81
82 void SlotClosureTest::testChoiceDelete ()
83 {
84 DummyObject obj;
85
86 bool hasRun = false;
88 {
89 [&hasRun]
90 {
91 if (hasRun)
93
94 hasRun = true;
96 },
97 &obj,
98 SIGNAL (someSignal ()),
99 nullptr
100 };
102
103 obj.EmitSignal ();
104
105 QCOMPARE (hasRun, true);
106 QCOMPARE (closurePtr.isNull (), false);
107
108 QCoreApplication::sendPostedEvents (nullptr, QEvent::DeferredDelete);
109
110 QCOMPARE (closurePtr.isNull (), false);
111
112 obj.EmitSignal ();
113 QCoreApplication::sendPostedEvents (nullptr, QEvent::DeferredDelete);
114
115 QCOMPARE (closurePtr.isNull (), true);
116 }
117}
118}
@ 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
Container< T > Filter(const Container< T > &c, F f)
Definition prelude.h:118
Definition constants.h:15