qtmobility/tests/auto/qmediaserviceprovider/tst_qmediaserviceprovider.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
child 15 1f895d8a5b2b
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    58 public:
    58 public:
    59     MockMediaService(const QString& name, QObject *parent = 0) : QMediaService(parent)
    59     MockMediaService(const QString& name, QObject *parent = 0) : QMediaService(parent)
    60     { setObjectName(name); }
    60     { setObjectName(name); }
    61     ~MockMediaService() {}
    61     ~MockMediaService() {}
    62 
    62 
    63     QMediaControl* control(const char *) const {return 0;}
    63     QMediaControl* requestControl(const char *) {return 0;}
       
    64     void releaseControl(QMediaControl *) {}
    64 };
    65 };
    65 
    66 
    66 class MockServicePlugin1 : public QMediaServiceProviderPlugin,
    67 class MockServicePlugin1 : public QMediaServiceProviderPlugin,
    67                            public QMediaServiceSupportedFormatsInterface,
    68                            public QMediaServiceSupportedFormatsInterface,
    68                            public QMediaServiceSupportedDevicesInterface
    69                            public QMediaServiceSupportedDevicesInterface
    88     void release(QMediaService *service)
    89     void release(QMediaService *service)
    89     {
    90     {
    90         delete service;
    91         delete service;
    91     }
    92     }
    92 
    93 
    93     QtMediaServices::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const
    94     QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const
    94     {        
    95     {
    95         if (codecs.contains(QLatin1String("mpeg4")))
    96         if (codecs.contains(QLatin1String("mpeg4")))
    96             return QtMediaServices::NotSupported;
    97             return QtMultimedia::NotSupported;
    97 
    98 
    98         if (mimeType == "audio/ogg") {            
    99         if (mimeType == "audio/ogg") {
    99             return QtMediaServices::ProbablySupported;
   100             return QtMultimedia::ProbablySupported;
   100         }
   101         }
   101 
   102 
   102         return QtMediaServices::MaybeSupported;
   103         return QtMultimedia::MaybeSupported;
   103     }
   104     }
   104 
   105 
   105     QStringList supportedMimeTypes() const
   106     QStringList supportedMimeTypes() const
   106     {
   107     {
   107         return QStringList("audio/ogg");
   108         return QStringList("audio/ogg");
   146     void release(QMediaService *service)
   147     void release(QMediaService *service)
   147     {
   148     {
   148         delete service;
   149         delete service;
   149     }
   150     }
   150 
   151 
   151     QtMediaServices::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const
   152     QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const
   152     {
   153     {
   153         Q_UNUSED(codecs);
   154         Q_UNUSED(codecs);
   154 
   155 
   155         if (mimeType == "audio/wav")
   156         if (mimeType == "audio/wav")
   156             return QtMediaServices::PreferredService;
   157             return QtMultimedia::PreferredService;
   157 
   158 
   158         return QtMediaServices::NotSupported;
   159         return QtMultimedia::NotSupported;
   159     }
   160     }
   160 
   161 
   161     QStringList supportedMimeTypes() const
   162     QStringList supportedMimeTypes() const
   162     {
   163     {
   163         return QStringList("audio/wav");
   164         return QStringList("audio/wav");
   241     void release(QMediaService *service)
   242     void release(QMediaService *service)
   242     {
   243     {
   243         delete service;
   244         delete service;
   244     }
   245     }
   245 
   246 
   246     QtMediaServices::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const
   247     QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const
   247     {
   248     {
   248         if (codecs.contains(QLatin1String("jpeg2000")))
   249         if (codecs.contains(QLatin1String("jpeg2000")))
   249             return QtMediaServices::NotSupported;
   250             return QtMultimedia::NotSupported;
   250 
   251 
   251         if (supportedMimeTypes().contains(mimeType))
   252         if (supportedMimeTypes().contains(mimeType))
   252             return QtMediaServices::ProbablySupported;
   253             return QtMultimedia::ProbablySupported;
   253 
   254 
   254         return QtMediaServices::MaybeSupported;
   255         return QtMultimedia::MaybeSupported;
   255     }
   256     }
   256 
   257 
   257     QStringList supportedMimeTypes() const
   258     QStringList supportedMimeTypes() const
   258     {
   259     {
   259         return QStringList() << "video/mp4" << "video/quicktime";
   260         return QStringList() << "video/mp4" << "video/quicktime";
   336 
   337 
   337 void tst_QMediaServiceProvider::testHasSupport()
   338 void tst_QMediaServiceProvider::testHasSupport()
   338 {
   339 {
   339     MockMediaServiceProvider mockProvider;
   340     MockMediaServiceProvider mockProvider;
   340     QCOMPARE(mockProvider.hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/ogv", QStringList()),
   341     QCOMPARE(mockProvider.hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/ogv", QStringList()),
   341              QtMediaServices::MaybeSupported);
   342              QtMultimedia::MaybeSupported);
   342 
   343 
   343     QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
   344     QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
   344 
   345 
   345     if (provider == 0)
   346     if (provider == 0)
   346         QSKIP("No default provider", SkipSingle);
   347         QSKIP("No default provider", SkipSingle);
   347 
   348 
   348     QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/ogv", QStringList()),
   349     QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/ogv", QStringList()),
   349              QtMediaServices::MaybeSupported);
   350              QtMultimedia::MaybeSupported);
   350 
   351 
   351     QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "audio/ogg", QStringList()),
   352     QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "audio/ogg", QStringList()),
   352              QtMediaServices::ProbablySupported);
   353              QtMultimedia::ProbablySupported);
   353 
   354 
   354     //while the service returns PreferredService, provider should return ProbablySupported
   355     //while the service returns PreferredService, provider should return ProbablySupported
   355     QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "audio/wav", QStringList()),
   356     QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "audio/wav", QStringList()),
   356              QtMediaServices::ProbablySupported);
   357              QtMultimedia::ProbablySupported);
   357 
   358 
   358     //even while all the plugins with "hasSupport" returned NotSupported,
   359     //even while all the plugins with "hasSupport" returned NotSupported,
   359     //MockServicePlugin3 has no "hasSupport" interface, so MaybeSupported
   360     //MockServicePlugin3 has no "hasSupport" interface, so MaybeSupported
   360     QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/avi",
   361     QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/avi",
   361                                   QStringList() << "mpeg4"),
   362                                   QStringList() << "mpeg4"),
   362              QtMediaServices::MaybeSupported);
   363              QtMultimedia::MaybeSupported);
   363 
   364 
   364     QCOMPARE(provider->hasSupport(QByteArray("non existing service"), "video/ogv", QStringList()),
   365     QCOMPARE(provider->hasSupport(QByteArray("non existing service"), "video/ogv", QStringList()),
   365              QtMediaServices::NotSupported);
   366              QtMultimedia::NotSupported);
   366 
   367 
   367     QCOMPARE(QMediaPlayer::hasSupport("video/ogv"), QtMediaServices::MaybeSupported);    
   368     QCOMPARE(QMediaPlayer::hasSupport("video/ogv"), QtMultimedia::MaybeSupported);    
   368     QCOMPARE(QMediaPlayer::hasSupport("audio/ogg"), QtMediaServices::ProbablySupported);
   369     QCOMPARE(QMediaPlayer::hasSupport("audio/ogg"), QtMultimedia::ProbablySupported);
   369     QCOMPARE(QMediaPlayer::hasSupport("audio/wav"), QtMediaServices::ProbablySupported);
   370     QCOMPARE(QMediaPlayer::hasSupport("audio/wav"), QtMultimedia::ProbablySupported);
   370 
   371 
   371     //test low latency flag support
   372     //test low latency flag support
   372     QCOMPARE(QMediaPlayer::hasSupport("audio/wav", QStringList(), QMediaPlayer::LowLatency),
   373     QCOMPARE(QMediaPlayer::hasSupport("audio/wav", QStringList(), QMediaPlayer::LowLatency),
   373              QtMediaServices::ProbablySupported);
   374              QtMultimedia::ProbablySupported);
   374     //plugin1 probably supports audio/ogg, it checked because it doesn't provide features iface
   375     //plugin1 probably supports audio/ogg, it checked because it doesn't provide features iface
   375     QCOMPARE(QMediaPlayer::hasSupport("audio/ogg", QStringList(), QMediaPlayer::LowLatency),
   376     QCOMPARE(QMediaPlayer::hasSupport("audio/ogg", QStringList(), QMediaPlayer::LowLatency),
   376              QtMediaServices::ProbablySupported);
   377              QtMultimedia::ProbablySupported);
   377     //Plugin4 is not checked here, sine it's known not support low latency
   378     //Plugin4 is not checked here, sine it's known not support low latency
   378     QCOMPARE(QMediaPlayer::hasSupport("video/quicktime", QStringList(), QMediaPlayer::LowLatency),
   379     QCOMPARE(QMediaPlayer::hasSupport("video/quicktime", QStringList(), QMediaPlayer::LowLatency),
   379              QtMediaServices::MaybeSupported);
   380              QtMultimedia::MaybeSupported);
   380 
   381 
   381     //test streaming flag support
   382     //test streaming flag support
   382     QCOMPARE(QMediaPlayer::hasSupport("video/quicktime", QStringList(), QMediaPlayer::StreamPlayback),
   383     QCOMPARE(QMediaPlayer::hasSupport("video/quicktime", QStringList(), QMediaPlayer::StreamPlayback),
   383              QtMediaServices::ProbablySupported);
   384              QtMultimedia::ProbablySupported);
   384     //Plugin2 is not checked here, sine it's known not support streaming
   385     //Plugin2 is not checked here, sine it's known not support streaming
   385     QCOMPARE(QMediaPlayer::hasSupport("audio/wav", QStringList(), QMediaPlayer::StreamPlayback),
   386     QCOMPARE(QMediaPlayer::hasSupport("audio/wav", QStringList(), QMediaPlayer::StreamPlayback),
   386              QtMediaServices::MaybeSupported);
   387              QtMultimedia::MaybeSupported);
   387 
   388 
   388     //ensure the correct media player plugin is choosen for mime type
   389     //ensure the correct media player plugin is choosen for mime type
   389     QMediaPlayer simplePlayer(0, QMediaPlayer::LowLatency);
   390     QMediaPlayer simplePlayer(0, QMediaPlayer::LowLatency);
   390     QCOMPARE(simplePlayer.service()->objectName(), QLatin1String("MockServicePlugin2"));
   391     QCOMPARE(simplePlayer.service()->objectName(), QLatin1String("MockServicePlugin2"));
   391 
   392