File: structuretest.cpp

package info (click to toggle)
qt-gstreamer 0.10.2-2.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,012 kB
  • ctags: 2,868
  • sloc: cpp: 17,352; yacc: 156; lex: 125; makefile: 23
file content (133 lines) | stat: -rw-r--r-- 3,900 bytes parent folder | download | duplicates (2)
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
/*
    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/Structure>
#include <QGst/Buffer>
#include <QGst/Caps>

class StructureTest : public QGstTest
{
    Q_OBJECT
private Q_SLOTS:
    void bindingsTest();
    void copyTest();
    void valueTest();
    void sharedStructureTest();
};

void StructureTest::bindingsTest()
{
    QGst::Structure s("mystructure");

    QVERIFY(s.isValid());
    QCOMPARE(s.name(), QString("mystructure"));
    QCOMPARE(s.numberOfFields(), static_cast<unsigned int>(0));

    s.setValue("intfield", 20);
    QCOMPARE(s.numberOfFields(), static_cast<unsigned int>(1));
    QVERIFY(s.hasField("intfield"));
    QCOMPARE(s.fieldName(0), QString("intfield"));
    QCOMPARE(s.value("intfield").get<int>(), 20);
    QCOMPARE(s.fieldType("intfield"), QGlib::Type(QGlib::Type::Int));

    s.setValue("strfield", QString("hello world"));
    QCOMPARE(s.numberOfFields(), static_cast<unsigned int>(2));

    qDebug() << s;

    s.removeField("intfield");
    QCOMPARE(s.numberOfFields(), static_cast<unsigned int>(1));

    s.removeAllFields();
    QCOMPARE(s.numberOfFields(), static_cast<unsigned int>(0));
}

void StructureTest::copyTest()
{
    QGst::Structure s("mystructure");
    s.setValue("intfield", 10);

    QGst::Structure ss(s);
    QVERIFY(ss.isValid());
    QCOMPARE(ss.value("intfield").get<int>(), 10);

    ss.setValue("intfield", 20);
    QCOMPARE(s.value("intfield").get<int>(), 10);

    {
        QGst::Structure s2(ss);
        QVERIFY(s2.isValid());
        QCOMPARE(s2.value("intfield").get<int>(), 20);

        s2.setValue("intfield", 30);
        QCOMPARE(s.value("intfield").get<int>(), 10);
        QCOMPARE(ss.value("intfield").get<int>(), 20);
        QCOMPARE(s2.value("intfield").get<int>(), 30);

        s2 = s;
        QCOMPARE(s2.value("intfield").get<int>(), 10);
    }

}

void StructureTest::valueTest()
{
    QGlib::Value v;

    {
        QGst::Structure s("mystructure");
        s.setValue("foo", 1);
        v = QGlib::Value::create(s);
        QVERIFY(v.isValid());
    }

    {
        QGst::Structure s = v.get<QGst::Structure>();
        QVERIFY(s.isValid());
        QCOMPARE(s.name(), QString("mystructure"));
        QCOMPARE(s.value("foo").toInt(), 1);
    }
}

void StructureTest::sharedStructureTest()
{
    QGst::BufferPtr buffer = QGst::Buffer::create(10);
    {
        QGst::CapsPtr caps = QGst::Caps::createSimple("video/x-raw-yuv");
        caps->setValue("width", 320);
        caps->setValue("height", 240);
        buffer->setCaps(caps);
    }

    QGst::StructurePtr structure = buffer->caps()->internalStructure(0);
    QCOMPARE(structure->name(), QString("video/x-raw-yuv"));
    QCOMPARE(structure->value("width").toInt(), 320);
    QCOMPARE(structure->value("height").toInt(), 240);

    QGst::Structure s = structure->copy();
    QCOMPARE(s.name(), QString("video/x-raw-yuv"));
    QCOMPARE(s.value("width").toInt(), 320);
    QCOMPARE(s.value("height").toInt(), 240);
}


QTEST_APPLESS_MAIN(StructureTest)

#include "moc_qgsttest.cpp"
#include "structuretest.moc"