summaryrefslogtreecommitdiff
path: root/tests/auto/capstest.cpp
blob: 6db1d4c2cc6ce024f19c27a6ca269aaddf4932b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
    Copyright (C) 2010 George Kiagiadakis <kiagiadakis.george@gmail.com>
    Copyright (C) 2011 Collabora Ltd.
      @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>

    This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published
    by the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "qgsttest.h"
#include <QGst/Caps>
#include <QGst/Structure>
#include <QGst/Bin>

class CapsTest : public QGstTest
{
    Q_OBJECT
private Q_SLOTS:
    void simpleTest();
    void anyTest();
    void fullTest();
    void writabilityTest();
    void setValueTest();
};

void CapsTest::simpleTest()
{
    QGst::CapsPtr caps = QGst::Caps::createSimple("video/x-raw");
    QVERIFY(caps->isSimple());
    QVERIFY(!caps->isEmpty());
    QVERIFY(!caps->isAny());
    QVERIFY(caps->size() == 1);

    caps->setValue("width", 320);
    caps->setValue("height", 240);
    qDebug() << caps;

    QGst::StructurePtr ss = caps->internalStructure(0);
    QVERIFY(ss->isValid());
    qDebug() << ss;
    ss->setValue("width", 400);
    qDebug() << caps;

    //Check access with temporaries
    caps->internalStructure(0)->setValue("width", 800);
    QCOMPARE(caps->internalStructure(0)->value("width").get<int>(), 800);

    //Note: GStreamer will thrown an assertion on the line below, this is expected
    QVERIFY(!caps->internalStructure(1)->isValid());
}

void CapsTest::anyTest()
{
    QGst::CapsPtr caps = QGst::Caps::createAny();
    QVERIFY(!caps->isSimple());
    QVERIFY(!caps->isEmpty());
    QVERIFY(caps->isAny());
    QVERIFY(caps->size() == 0);
}

void CapsTest::fullTest()
{
    QGst::Structure s("video/x-raw");
    s.setValue("width", 320);
    s.setValue("height", 240);

    QGst::CapsPtr caps = QGst::Caps::createEmpty();
    QVERIFY(!caps->isSimple());
    QVERIFY(caps->isEmpty());
    QVERIFY(!caps->isAny());
    QVERIFY(caps->size() == 0);

    caps->appendStructure(s);
    QVERIFY(caps->isSimple());
    QVERIFY(!caps->isEmpty());
    QVERIFY(!caps->isAny());
    QVERIFY(caps->size() == 1);

    QGst::CapsPtr caps2 = QGst::Caps::createSimple("video/x-raw");
    caps2->setValue("width", 320);
    caps2->setValue("height", 240);

    QVERIFY(caps->equals(caps2));
}

void CapsTest::writabilityTest()
{
    QGst::CapsPtr caps = QGst::Caps::createSimple("video/x-raw");
    QVERIFY(GST_CAPS_REFCOUNT_VALUE(static_cast<GstCaps *>(caps)) == 1);

    {
        QGst::CapsPtr caps2 = caps;
        QCOMPARE(GST_CAPS_REFCOUNT_VALUE(static_cast<GstCaps *>(caps)), 1);
        QVERIFY(static_cast<GstCaps*>(caps2) == static_cast<GstCaps*>(caps));
    }

    GstCaps *oldPtr = caps;
    QVERIFY(GST_CAPS_REFCOUNT_VALUE(static_cast<GstCaps *>(caps)) == 1);
    //Increase external refcount to lock it
    gst_caps_ref(oldPtr);
    QVERIFY(oldPtr == static_cast<GstCaps*>(caps));
    QVERIFY(GST_CAPS_REFCOUNT_VALUE(static_cast<GstCaps *>(caps)) == 2);
    QVERIFY(!caps->isWritable());

    caps = caps->makeWritable(); //creates a copy
    QVERIFY(caps->isWritable());
    QVERIFY(oldPtr != static_cast<GstCaps*>(caps)); //no longer same gstcaps object
}

void CapsTest::setValueTest()
{
    QGst::CapsPtr caps = QGst::Caps::createSimple("video/x-raw");

    QGst::BinPtr bin = QGst::Bin::create();

    {
        caps->setValue("binptr", bin);
        QGlib::Value v = caps->internalStructure(0)->value("binptr");
        QCOMPARE(v.type(), QGlib::GetType<QGst::Bin>());
        QVERIFY(v.get<QGst::BinPtr>() == bin);
    }

    {
        QGlib::Value v = QGlib::Value::create(bin);
        caps->setValue("binptr2", v);
        v = caps->internalStructure(0)->value("binptr2");
        QCOMPARE(v.type(), QGlib::GetType<QGst::Bin>());
        QVERIFY(v.get<QGst::BinPtr>() == bin);
    }
}

QTEST_APPLESS_MAIN(CapsTest)

#include "moc_qgsttest.cpp"
#include "capstest.moc"