LeechCraft  0.6.70-15082-g543737046d
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 
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 }
LC::Util::DummyObject::EmitSignal
void EmitSignal()
Definition: slotclosuretest.cpp:31
LC::Util::ChoiceDeletePolicy::Delete::Yes
@ Yes
Delete SlotClosure after this invocation.
slotclosure.h
slotclosuretest.h
LC::Util::SlotClosureTest
Definition: slotclosuretest.h:38
LC::Util::ChoiceDeletePolicy::Delete::No
@ No
Do not delete SlotClosure after this invocation.
LC
Definition: constants.h:14
LC::Util::DummyObject::someSignal
void someSignal()