2 * This file is part of QMAFW
4 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights
7 * Contact: Visa Smolander <visa.smolander@nokia.com>
9 * This software, including documentation, is protected by copyright controlled
10 * by Nokia Corporation. All rights are reserved. Copying, including
11 * reproducing, storing, adapting or translating, any or all of this material
12 * requires the prior written consent of Nokia Corporation. This material also
13 * contains confidential information which may not be disclosed to others
14 * without the prior written consent of Nokia.
18 #include <MafwInternalRegistry.h>
19 #include <MafwRenderer.h>
21 #include <QtTest/QtTest>
22 #include <glib-object.h>
25 #include "Ut_MafwGstRendererPlugin.h"
26 #include "MafwGstRendererPlugin.h"
27 #include "MafwGstRenderer.h"
28 #include "MafwGstRendererVolume.h"
29 #include "MafwGstRendererDolby.h"
30 #include "../common/MafwStubHelper.h"
32 Q_DECLARE_METATYPE(MafwRenderer*)
34 extern void setStubHelper(MafwStubHelper* stubHlp);
35 QMap<QString,QString> renderers;
36 int renderer_index = 0;
38 void Ut_MafwGstRendererPlugin::initTestCase()
40 qRegisterMetaType<MafwRenderer*>();
41 m_stubHelper = new MafwStubHelper;
42 setStubHelper(m_stubHelper);
44 m_plugin = new MafwGstRendererPlugin();
47 void Ut_MafwGstRendererPlugin::testInProcess()
49 QSignalSpy addedSpy( MafwRegistry::instance(), SIGNAL(rendererAdded(const QString&, const QString&)) );
50 QSignalSpy removedSpy( MafwRegistry::instance(), SIGNAL(rendererRemoved(const QString&, const QString&)) );
51 //MafwBasicRenderer::initialize is called twice:
52 //from its own constructor and from MafwGstRenderer::initialize
54 //Basic renderer initialize fails
55 m_stubHelper->expect("initialize", false);
56 m_stubHelper->expect("initialize", false);
57 m_plugin->initialize( MafwInternalRegistry::internalInstance() );
58 QCOMPARE( addedSpy.size(), 0 );
62 m_stubHelper->expect("initialize", true);
63 m_stubHelper->expect("initialize", true);
64 m_plugin->initialize( MafwInternalRegistry::internalInstance() );
65 QCOMPARE( addedSpy.size(), 1 );
66 QCOMPARE( removedSpy.size(), 0 );
67 QVariantList arguments = addedSpy.takeFirst();
69 QString uuid = arguments.at(0).toString();
70 QCOMPARE(uuid, QString("mafw_gst_renderer"));
71 QCOMPARE(arguments.at(1).toString(), QString("QMAFW GStreamer Renderer"));
73 MafwRenderer* rnd = MafwRegistry::instance()->renderer(uuid);
75 QCOMPARE(rnd->pluginName(), m_plugin->name());
77 MafwInternalRegistry::internalInstance()->removeExtension(uuid);
78 QCOMPARE( removedSpy.size(), 1 );
81 void Ut_MafwGstRendererPlugin::testOutProcess()
83 QCoreApplication::setApplicationName("qmafw-dbus-wrapper");
84 //TODO empty settings case
86 renderers.insert("mafw-gst-renderer", "Mafw-GStreamer-Renderer");
87 renderers.insert("mafw-gst-video-suite-renderer", "Mafw-GStreamer-Renderer-For-Video");
89 QSignalSpy addedSpy( MafwRegistry::instance(), SIGNAL(rendererAdded(const QString&, const QString&)) );
90 QSignalSpy removedSpy( MafwRegistry::instance(), SIGNAL(rendererRemoved(const QString&, const QString&)) );
91 //MafwBasicRenderer::initialize is called twice:
92 //from its own constructor and from MafwGstRenderer::initialize
94 //Basic renderer initialize fails
95 m_stubHelper->expect("initialize", false);
96 m_stubHelper->expect("initialize", false);
97 m_stubHelper->expect("initialize", false);
98 m_stubHelper->expect("initialize", false);
99 m_plugin->initialize( MafwInternalRegistry::internalInstance() );
100 QCOMPARE( addedSpy.size(), 0 );
104 m_stubHelper->expect("initialize", true);
105 m_stubHelper->expect("initialize", true);
106 m_stubHelper->expect("initialize", true);
107 m_stubHelper->expect("initialize", true);
108 m_plugin->initialize( MafwInternalRegistry::internalInstance() );
109 QCOMPARE( addedSpy.size(), 2 );
110 QCOMPARE( removedSpy.size(), 0 );
112 QVariantList arguments = addedSpy.takeFirst();
113 QString uuid1 = arguments.at(0).toString();
114 QString name1 = arguments.at(1).toString();
115 arguments = addedSpy.takeFirst();
116 QString uuid2 = arguments.at(0).toString();
117 QString name2 = arguments.at(1).toString();
119 MafwRenderer* rnd1 = MafwRegistry::instance()->renderer(uuid1);
121 QCOMPARE(rnd1->pluginName(), m_plugin->name());
122 MafwRenderer* rnd2 = MafwRegistry::instance()->renderer(uuid2);
124 QCOMPARE(rnd2->pluginName(), m_plugin->name());
126 QCOMPARE(uuid1, rnd1->uuid());
127 QCOMPARE(name1, rnd1->name());
128 QCOMPARE(uuid2, rnd2->uuid());
129 QCOMPARE(name2, rnd2->name());
131 MafwInternalRegistry::internalInstance()->removeExtension(uuid1);
132 MafwInternalRegistry::internalInstance()->removeExtension(uuid2);
134 // Test huge amount of renderers
138 for(int i = 0; i < 100; i++)
140 QString rndId = QString("rndId %1").arg(i);
141 QString rndName = QString("rndName %1").arg(i);
142 renderers.insert(rndId, rndName);
143 m_stubHelper->expect("initialize", true);
144 m_stubHelper->expect("initialize", true);
146 m_plugin->initialize( MafwInternalRegistry::internalInstance());
147 QCOMPARE(removedSpy.size(), 0);
148 QCOMPARE(addedSpy.size(), 100);
150 // Let's only remove 99 renderers
151 for(int i = 0; i < 99; i++)
153 QString rndId = QString("rndId %1").arg(i);
154 MafwInternalRegistry::internalInstance()->removeExtension(rndId);
156 QCOMPARE(removedSpy.size(), 99);
157 // Check that there is still one renderer left
158 MafwRenderer* rnd99 = MafwRegistry::instance()->renderer("rndId 99");
160 MafwInternalRegistry::internalInstance()->removeExtension("rndId 99");
167 m_plugin->initialize(MafwInternalRegistry::internalInstance());
168 QCOMPARE(addedSpy.size(), 0);
170 //Test 2 renderers with same uuid and name
171 renderers.insert("rndId1", "rndName1");
172 renderers.insert("rndId1", "rndName1");
173 m_stubHelper->expect("initialize", true);
174 m_stubHelper->expect("initialize", true);
175 m_stubHelper->expect("initialize", false);
176 m_stubHelper->expect("initialize", false);
177 m_plugin->initialize( MafwInternalRegistry::internalInstance());
178 QCOMPARE(addedSpy.size(), 1);
182 void Ut_MafwGstRendererPlugin::cleanupTestCase()
185 while(QCoreApplication::hasPendingEvents())
187 QCoreApplication::sendPostedEvents();
188 QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
189 QCoreApplication::processEvents();
193 void gst_init(int *argc, char **argv[])
199 QTEST_MAIN(Ut_MafwGstRendererPlugin)
202 MafwGstRendererVolume::MafwGstRendererVolume()
204 qDebug() << "Volume stub ctor";
207 void MafwGstRendererVolume::connectToPulseAudio()
211 MafwGstRendererVolume::~MafwGstRendererVolume()
215 uint MafwGstRendererVolume::getVolume()
217 qDebug(__PRETTY_FUNCTION__);
221 bool MafwGstRendererVolume::setVolume (uint value)
228 QSettings::QSettings( const QString&, const QString&, QObject* ){}
229 //Hope we will never need below ctor stub, because it is used somehow by unit test framework.
230 //QSettings::QSettings(QSettings::Scope, const QString&, const QString&, QObject*){}
231 QSettings::QSettings(QSettings::Format, QSettings::Scope, const QString&, const QString&, QObject*){}
232 QSettings::QSettings(const QString&, QSettings::Format, QObject*){}
233 QSettings::QSettings(QObject*){}
234 QSettings::~QSettings(){}
236 QVariant QSettings::value(const QString& key, const QVariant& ) const
238 if(renderers.size() == 0)
242 QMap<QString, QString>::const_iterator renderers_iterator = renderers.constBegin();
243 for(int i = 0; i < renderer_index; i++)
245 renderers_iterator++;
250 return renderers_iterator.key();
254 return renderers_iterator.value();
258 int QSettings::beginReadArray(const QString&)
260 return renderers.count();
263 void QSettings::setArrayIndex(int i)
268 void QSettings::endArray()
272 void QSettings::beginGroup(const QString &prefix)
277 void QSettings::endGroup()
282 bool QSettings::contains(const QString &key) const