summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHonglei Zhang <honglei.zhang@nokia.com>2011-07-03 17:22:41 (GMT)
committerHonglei Zhang <honglei.zhang@nokia.com>2011-07-03 17:22:41 (GMT)
commit3b6a61953bcd319a6df55d66116ce92f7525ec00 (patch)
tree4642541a9ab510546b1bc77bd4c0790a8eaedfec /tests
parent2d930fdabccad6bfbbd0075610a302027c8d499b (diff)
downloadQt-3b6a61953bcd319a6df55d66116ce92f7525ec00.zip
Qt-3b6a61953bcd319a6df55d66116ce92f7525ec00.tar.gz
Qt-3b6a61953bcd319a6df55d66116ce92f7525ec00.tar.bz2
Enable key capture and RemCon interfaces for Qt apps on Symbian
The volume and other multimedia keys in Symbian are not delivered through the normal key events, but through a seperate API called CRemConCoreApiTarget. The commit implements the feature that multimedia key events are delivered via normal key events to Qt Application, if the Qt::AA_CaptureMultimediaKeys is defined. Task-number: QTBUG-4415 Reviewed-by: Sami Merila Reviewed-by: Miikka Heikkinen
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qs60mainapplication/qs60mainapplication.pro1
-rw-r--r--tests/auto/qs60mainapplication/tst_qs60mainapplication.cpp259
2 files changed, 260 insertions, 0 deletions
diff --git a/tests/auto/qs60mainapplication/qs60mainapplication.pro b/tests/auto/qs60mainapplication/qs60mainapplication.pro
index bbd6c30..de3f59d 100644
--- a/tests/auto/qs60mainapplication/qs60mainapplication.pro
+++ b/tests/auto/qs60mainapplication/qs60mainapplication.pro
@@ -2,3 +2,4 @@ load(qttest_p4)
SOURCES += tst_qs60mainapplication.cpp
symbian:LIBS += -lapparc -leikcore -lcone -lavkon
+symbian:LIBS += -lremconcoreapi -lremconinterfacebase \ No newline at end of file
diff --git a/tests/auto/qs60mainapplication/tst_qs60mainapplication.cpp b/tests/auto/qs60mainapplication/tst_qs60mainapplication.cpp
index 069fd14..967ce4e 100644
--- a/tests/auto/qs60mainapplication/tst_qs60mainapplication.cpp
+++ b/tests/auto/qs60mainapplication/tst_qs60mainapplication.cpp
@@ -59,6 +59,8 @@ public slots:
void cleanup();
private slots:
void customQS60MainApplication();
+ void testMultimediaKeys_data();
+ void testMultimediaKeys();
};
void tst_QS60MainApplication::initTestCase()
@@ -115,6 +117,201 @@ CApaApplication *factory()
{
return new (ELeave) CustomMainApplication;
}
+
+#include <remconcoreapicontrollerobserver.h>
+#include <remconcoreapicontroller.h>
+#include <remconinterfaceselector.h>
+#include <QTimer>
+#include <QSignalSpy>
+
+class KeyGenerator : public QObject,
+ public MRemConCoreApiControllerObserver
+{
+ Q_OBJECT
+public:
+ KeyGenerator(QObject *parent = 0);
+ ~KeyGenerator();
+ void MrccacoResponse(TRemConCoreApiOperationId operationId, TInt error);
+
+ void simulateKey(int qtKey);
+
+private:
+ void init();
+ void cleanup();
+
+ CRemConInterfaceSelector *interfaceSelector;
+ CRemConCoreApiController *coreController;
+};
+
+KeyGenerator::KeyGenerator(QObject *parent) : QObject(parent)
+{
+ init();
+}
+
+KeyGenerator::~KeyGenerator()
+{
+ cleanup();
+}
+
+void KeyGenerator::MrccacoResponse(TRemConCoreApiOperationId operationId, TInt error)
+{
+ Q_UNUSED(operationId);
+ Q_UNUSED(error);
+}
+
+/*
+ * Generates keyPress and keyRelease events for given key
+ */
+void KeyGenerator::simulateKey(int qtKey)
+{
+ if (!coreController)
+ return;
+
+ TRemConCoreApiButtonAction action = ERemConCoreApiButtonClick;
+ TUint numRemotes = 0;
+ TRequestStatus status;
+ bool wait = true;
+
+ switch (qtKey) {
+ // media keys
+ case Qt::Key_VolumeUp:
+ coreController->VolumeUp(status, numRemotes, action);
+ break;
+ case Qt::Key_VolumeDown:
+ coreController->VolumeDown(status, numRemotes, action);
+ break;
+ case Qt::Key_MediaStop:
+ coreController->Stop(status, numRemotes, action);
+ break;
+ case Qt::Key_MediaTogglePlayPause:
+ coreController->PausePlayFunction(status, numRemotes, action);
+ break;
+ case Qt::Key_MediaNext:
+ coreController->Forward(status, numRemotes, action);
+ break;
+ case Qt::Key_MediaPrevious:
+ coreController->Backward(status, numRemotes, action);
+ break;
+ case Qt::Key_AudioForward:
+ coreController->FastForward(status, numRemotes, action);
+ break;
+ case Qt::Key_AudioRewind:
+ coreController->Rewind(status, numRemotes, action);
+ break;
+ // accessory keys
+ case Qt::Key_Select:
+ coreController->Select(status, numRemotes, action);
+ break;
+ case Qt::Key_Enter:
+ coreController->Enter(status, numRemotes, action);
+ break;
+ case Qt::Key_PageUp:
+ coreController->PageUp(status, numRemotes, action);
+ break;
+ case Qt::Key_PageDown:
+ coreController->PageDown(status, numRemotes, action);
+ break;
+ case Qt::Key_Left:
+ coreController->Left(status, numRemotes, action);
+ break;
+ case Qt::Key_Right:
+ coreController->Right(status, numRemotes, action);
+ break;
+ case Qt::Key_Up:
+ coreController->Up(status, numRemotes, action);
+ break;
+ case Qt::Key_Down:
+ coreController->Down(status, numRemotes, action);
+ break;
+ case Qt::Key_Help:
+ coreController->Help(status, numRemotes, action);
+ break;
+ case Qt::Key_F1:
+ coreController->F1(status, numRemotes, action);
+ break;
+ case Qt::Key_F2:
+ coreController->F2(status, numRemotes, action);
+ break;
+ case Qt::Key_F3:
+ coreController->F3(status, numRemotes, action);
+ break;
+ case Qt::Key_F4:
+ coreController->F4(status, numRemotes, action);
+ break;
+ case Qt::Key_F5:
+ coreController->F5(status, numRemotes, action);
+ break;
+ default:
+ wait = false;
+ break;
+ }
+
+ if (wait)
+ User::WaitForRequest(status);
+}
+
+void KeyGenerator::init()
+{
+ try {
+ QT_TRAP_THROWING(interfaceSelector = CRemConInterfaceSelector::NewL());
+ QT_TRAP_THROWING(coreController = CRemConCoreApiController::NewL(*interfaceSelector, *this));
+ QT_TRAP_THROWING(interfaceSelector->OpenControllerL());
+ } catch (const std::exception &e) {
+ cleanup();
+ }
+}
+
+void KeyGenerator::cleanup()
+{
+ delete interfaceSelector;
+ interfaceSelector = 0;
+ coreController = 0;
+}
+
+const int keyEventTimeout = 2000; // 2secs
+
+class TestWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ TestWidget(QWidget *parent = 0);
+ ~TestWidget();
+
+signals:
+ void keyPress(int key);
+ void keyRelease(int key);
+
+protected:
+ void keyPressEvent(QKeyEvent *event);
+ void keyReleaseEvent(QKeyEvent *event);
+
+private:
+ QTimer exitTimer;
+};
+
+TestWidget::TestWidget(QWidget *parent) : QWidget(parent)
+{
+ // quit if no events are received
+ exitTimer.setSingleShot(true);
+ exitTimer.start(keyEventTimeout);
+ connect(&exitTimer, SIGNAL(timeout()), qApp, SLOT(quit()));
+}
+
+TestWidget::~TestWidget()
+{
+}
+
+void TestWidget::keyPressEvent(QKeyEvent *event)
+{
+ emit keyPress(event->key());
+}
+
+void TestWidget::keyReleaseEvent(QKeyEvent *event)
+{
+ emit keyRelease(event->key());
+ qApp->quit(); // test is done so quit immediately
+}
+
#endif // Q_WS_S60
void tst_QS60MainApplication::customQS60MainApplication()
@@ -129,5 +326,67 @@ void tst_QS60MainApplication::customQS60MainApplication()
#endif
}
+void tst_QS60MainApplication::testMultimediaKeys_data()
+{
+ QTest::addColumn<int>("key");
+
+ QTest::newRow("Key_VolumeUp") << (int)Qt::Key_VolumeUp;
+ QTest::newRow("Key_VolumeDown") << (int)Qt::Key_VolumeDown;
+ QTest::newRow("Key_MediaStop") << (int)Qt::Key_MediaStop;
+ QTest::newRow("Key_MediaTogglePlayPause") << (int)Qt::Key_MediaTogglePlayPause;
+ QTest::newRow("Key_MediaNext") << (int)Qt::Key_MediaNext;
+ QTest::newRow("Key_MediaPrevious") << (int)Qt::Key_MediaPrevious;
+ QTest::newRow("Key_AudioForward") << (int)Qt::Key_AudioForward;
+ QTest::newRow("Key_AudioRewind") << (int)Qt::Key_AudioRewind;
+
+ QTest::newRow("Key_Select") << (int)Qt::Key_Select;
+ QTest::newRow("Key_Enter") << (int)Qt::Key_Enter;
+ QTest::newRow("Key_PageUp") << (int)Qt::Key_PageUp;
+ QTest::newRow("Key_PageDown") << (int)Qt::Key_PageDown;
+ QTest::newRow("Key_Left") << (int)Qt::Key_Left;
+ QTest::newRow("Key_Right") << (int)Qt::Key_Right;
+ QTest::newRow("Key_Up") << (int)Qt::Key_Up;
+ QTest::newRow("Key_Down") << (int)Qt::Key_Down;
+ QTest::newRow("Key_Help") << (int)Qt::Key_Help;
+ QTest::newRow("Key_F1") << (int)Qt::Key_F1;
+ QTest::newRow("Key_F2") << (int)Qt::Key_F2;
+ QTest::newRow("Key_F3") << (int)Qt::Key_F3;
+ QTest::newRow("Key_F4") << (int)Qt::Key_F4;
+ QTest::newRow("Key_F5") << (int)Qt::Key_F5;
+}
+
+void tst_QS60MainApplication::testMultimediaKeys()
+{
+#ifndef Q_WS_S60
+ QSKIP("This is an S60-only test", SkipAll);
+#elif __WINS__
+ QSKIP("S60 emulator not supported", SkipAll);
+#else
+ QApplication::setAttribute(Qt::AA_CaptureMultimediaKeys);
+ int argc = 1;
+ char *argv = "tst_qs60mainapplication";
+ QApplication app(argc, &argv);
+
+ QFETCH(int, key);
+ KeyGenerator keyGen;
+ keyGen.simulateKey(key);
+
+ TestWidget widget;
+ QSignalSpy keyPressSpy(&widget, SIGNAL(keyPress(int)));
+ QSignalSpy keyReleaseSpy(&widget, SIGNAL(keyRelease(int)));
+
+ widget.show();
+ app.exec();
+
+ QCOMPARE(keyPressSpy.count(), 1);
+ QList<QVariant> arguments = keyPressSpy.takeFirst();
+ QVERIFY(arguments.at(0).toInt() == key);
+
+ QCOMPARE(keyReleaseSpy.count(), 1);
+ arguments = keyReleaseSpy.takeFirst();
+ QVERIFY(arguments.at(0).toInt() == key);
+#endif
+}
+
QTEST_APPLESS_MAIN(tst_QS60MainApplication)
#include "tst_qs60mainapplication.moc"