summaryrefslogtreecommitdiffstats
path: root/tests/auto/qmediaobject/tst_qmediaobject_xa.cpp
blob: 810a414b8bf631b627abb1e74ba87520ca4ed8eb (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "tst_qmediaobject_xa.h"

QT_USE_NAMESPACE

#define WAIT_FOR_CONDITION(a,e)            \
    for (int _i = 0; _i < 500; _i += 1) {  \
        if ((a) == (e)) break;             \
        QTest::qWait(10);}


#define WAIT_LONG_FOR_CONDITION(a,e)        \
    for (int _i = 0; _i < 1800; _i += 1) {  \
        if ((a) == (e)) break;              \
        QTest::qWait(100);}

Q_DECLARE_METATYPE(QtMultimediaKit::MetaData)

void tst_QMetadata_xa::initTestCase_data()
{
    QTest::addColumn<QMediaContent>("mediaContent");
    QTest::addColumn<int>("count");
    QTest::addColumn<QtMultimediaKit::MetaData>("key");
    QTest::addColumn<qint64>("intValue");
    QTest::addColumn<QString>("strValue");

    QTest::newRow("testmp3.mp3 - No Metadata")
    << QMediaContent(QUrl("file:///C:/data/testfiles/test.mp3")) // mediaContent
    << 0 //count
    << QtMultimediaKit::Title //key - irrelavant when count 0
    << qint64(-1) //intValue
    << QString(); //strValue

    QTest::newRow("JapJap.mp3 - Title")
    << QMediaContent(QUrl("file:///C:/data/testfiles/JapJap.mp3")) // mediaContent
    << -1 //count - ignore
    << QtMultimediaKit::Title //key
    << qint64(-1) //intValue
    << QString("JapJap");//strValue

    QTest::newRow("JapJap.mp3 - Artist")
    << QMediaContent(QUrl("file:///C:/data/testfiles/JapJap.mp3")) // mediaContent
    << -1 //count - ignore
    << QtMultimediaKit::AlbumArtist //key
    << qint64(-1) //intValue
    << QString("Screaming trees");//strValue

    QTest::newRow("JapJap.mp3 - Album")
    << QMediaContent(QUrl("file:///C:/data/testfiles/JapJap.mp3")) // mediaContent
    << -1 //count - ignore
    << QtMultimediaKit::AlbumTitle //key
    << qint64(-1) //intValue
    << QString("Sweet oblivion"); //strValue

    QTest::newRow("JapJap.mp3 - CoverArt")
    << QMediaContent(QUrl("file:///C:/data/testfiles/JapJap.mp3")) // mediaContent
    << -1 //count - ignore
    << QtMultimediaKit::CoverArtImage //key
    << qint64(28521) //intValue
    << QString("C:/data/testfiles/JapJapCoverArt.jpeg"); //strValue
}

void tst_QMetadata_xa::initTestCase()
{
    m_player = new QMediaPlayer();

    // Symbian back end needs coecontrol for creation.
    m_widget = new QVideoWidget();
    //m_widget->setMediaObject(m_player);
    m_widget->show();
    runonce = false;
}

void tst_QMetadata_xa::cleanupTestCase()
{
    delete m_player;
    delete m_widget;
}

void tst_QMetadata_xa::init()
{
    qRegisterMetaType<QMediaContent>("QMediaContent");
    qRegisterMetaType<QtMultimediaKit::MetaData>("QtMultimediaKit::MetaData");
}

void tst_QMetadata_xa::cleanup()
{
}

void tst_QMetadata_xa::testMetadata()
{
    QFETCH_GLOBAL(QMediaContent, mediaContent);
    QFETCH_GLOBAL(int, count);
    QFETCH_GLOBAL(QtMultimediaKit::MetaData, key);
    QFETCH_GLOBAL(QString, strValue);
    QFETCH_GLOBAL(qint64, intValue);

    QSignalSpy spy(m_player, SIGNAL(metaDataAvailableChanged(bool)));
    m_player->setMedia(mediaContent);

    WAIT_FOR_CONDITION(spy.count(), 1);
    //get metadata count
    QList<QtMultimediaKit::MetaData> mdList = m_player->availableMetaData ();
    QStringList amdList = m_player->availableExtendedMetaData();

    int numMetadataItems = mdList.size() + amdList.size();
    if (count>=0) //-1 indicate ignore count
        QVERIFY(count==numMetadataItems);

    if (numMetadataItems>0 && !strValue.isEmpty()) {
        QVariant val = m_player->metaData(key);

        if(key == QtMultimediaKit::CoverArtImage)
            val.value<QImage>().save(strValue);
        else
            QVERIFY(strValue == val.toString());
    }
}