2
* This file is part of unity-2d
4
* Copyright 2011 Canonical Ltd.
7
* - Aurélien Gâteau <aurelien.gateau@canonical.com>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; version 3.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
#include <gconnector.h>
38
static void increase(GCancellable*, gpointer data)
40
CallbackSpy* spy = reinterpret_cast<CallbackSpy*>(data);
47
class GConnectorTest : public QObject
56
void testDisconnectAll()
58
// Create a cancellable object as it is easy to get it to emit a
60
GCancellable* object = g_cancellable_new();
64
connector.connect(object, "cancelled", G_CALLBACK(CallbackSpy::increase), &spy);
66
// Emit signal, check callback gets called
67
g_cancellable_cancel(object);
68
QCOMPARE(spy.count, 1);
70
// Disconnect and emit signal, check callback does *not* get called
71
connector.disconnectAll();
72
g_cancellable_reset(object);
73
g_cancellable_cancel(object);
74
QCOMPARE(spy.count, 1);
76
g_object_unref(object);
79
void testDeletedInstance()
81
GCancellable* object = g_cancellable_new();
83
// Create a dummy connection
86
connector.connect(object, "cancelled", G_CALLBACK(CallbackSpy::increase), &spy);
87
g_object_unref(object);
89
// Should not crash because connection should have been removed
90
connector.disconnectAll();
94
QTEST_MAIN(GConnectorTest)
96
#include "gconnectortest.moc"