LeechCraft  0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
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 
13 QTEST_MAIN (LC::Util::SlotClosureTest)
14 
15 namespace LC
16 {
17 namespace 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  delete closure;
80  }
81 
82  void SlotClosureTest::testChoiceDelete ()
83  {
84  DummyObject obj;
85 
86  bool hasRun = false;
87  const auto closure = new SlotClosure<ChoiceDeletePolicy>
88  {
89  [&hasRun]
90  {
91  if (hasRun)
93 
94  hasRun = true;
96  },
97  &obj,
98  SIGNAL (someSignal ()),
99  nullptr
100  };
101  const QPointer<QObject> closurePtr { closure };
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 }
Executes a given functor upon a signal (or a list of signals).
Definition: slotclosure.h:79
Delete SlotClosure after this invocation.
Do not delete SlotClosure after this invocation.