Improve the Object properties api. Use QString and export the methods that get/return...
[qtgstreamer:qtgstreamer.git] / tests / signalstest.cpp
1 /*
2     Copyright (C) 2010  George Kiagiadakis <kiagiadakis.george@gmail.com>
3
4     This library is free software; you can redistribute it and/or modify
5     it under the terms of the GNU Lesser General Public License as published
6     by the Free Software Foundation; either version 2.1 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU Lesser General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "qgsttest.h"
18 #include <QGlib/Closure>
19 #include <QGst/Object>
20
21 class SignalsTest : public QGstTest
22 {
23     Q_OBJECT
24 private:
25     void closureTestClosure(QGst::ObjectPtr obj, QGst::ObjectPtr parentObj);
26 private slots:
27     void closureTest();
28 };
29
30 static bool closureCalled = false;
31
32 void SignalsTest::closureTestClosure(QGst::ObjectPtr obj, QGst::ObjectPtr parentObj)
33 {
34     qDebug() << "Closure called";
35     QCOMPARE(obj->property("name").get<QString>(), QString("mybin"));
36     QCOMPARE(parentObj->property("name").get<QString>(), QString("mypipeline"));
37     closureCalled = true;
38 }
39
40 void SignalsTest::closureTest()
41 {
42     GstObject *pipeline = GST_OBJECT(gst_pipeline_new("mypipeline"));
43     GstObject *bin = GST_OBJECT(gst_bin_new("mybin"));
44
45     closureCalled = false;
46     QGlib::ClosurePtr closure = QGlib::CppClosure::newCppClosure(&SignalsTest::closureTestClosure, this);
47     g_signal_connect_closure(bin, "parent-set", closure, FALSE);
48     gst_object_set_parent(bin, pipeline);
49     QCOMPARE(closureCalled, true);
50
51     gst_object_sink(bin);
52     gst_object_sink(pipeline);
53 }
54
55 QTEST_APPLESS_MAIN(SignalsTest)
56
57 #include "moc_qgsttest.cpp"
58 #include "signalstest.moc"