contentstorage/cahandler/tapp/tsrc/t_catapphandler/src/t_catapphandler.cpp
changeset 117 c63ee96dbe5f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contentstorage/cahandler/tapp/tsrc/t_catapphandler/src/t_catapphandler.cpp	Thu Sep 16 12:11:40 2010 +0100
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:  Main test class for test library.
+ *
+ */
+
+//#include <QStateMachine>
+//#include <QSignalSpy>
+//#include <QDir>
+
+#include <qservicemanager.h>
+#include <apgtask.h>
+
+#include "t_catapphandler.h"
+#include "catapphandlerplugin.h"
+#include "catapphandler.h"
+#include "caentry.h"
+#include "waitactive.h"
+
+QTM_USE_NAMESPACE
+
+//const QString xmlPath = "./resource/qt/plugins/stateplugins/"
+#ifdef Q_OS_SYMBIAN
+//  const QString mockedStatePluginsXml = "mockstateplugins.s60xml";
+#else
+//  const QString mockedStatePluginsXml = "mockstateplugins.xml";
+#endif
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void CaTappHandlerPluginTest::testConstruction()
+{
+    CaTappHandler* tappHandler = new CaTappHandler();
+
+    QVERIFY(tappHandler);
+
+    delete tappHandler;
+}
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void CaTappHandlerPluginTest::testExecute()
+{
+    const TInt KAppUid(0x20022EF9); // contacts
+
+    CaTappHandler* tAppHandler = new CaTappHandler();
+
+    CaEntry* entry = new CaEntry();
+    entry->setAttribute("item:launchuri","appto://20022EF9?");
+    CWaitActive* wait = CWaitActive::NewL();
+
+    RWsSession wsSession;
+
+    CleanupClosePushL(wsSession);
+    User::LeaveIfError(wsSession.Connect());
+
+    TApaTaskList taskList(wsSession);
+    TApaTask taskBefore = taskList.FindApp(TUid::Uid(KAppUid));
+    if (taskBefore.Exists()) {
+        taskBefore.EndTask(); // close task if exists
+    }
+
+    tAppHandler->execute(*entry, QString("open")); // run task
+    wait->Wait(15000000);
+    
+    TApaTask taskAfter = taskList.FindApp(TUid::Uid(KAppUid));
+
+    QVERIFY(taskAfter.Exists());
+    taskAfter.EndTask();
+    CleanupStack::PopAndDestroy(&wsSession);
+    delete wait;
+    delete entry;
+    delete tAppHandler;
+}
+
+// ---------------------------------------------------------------------------
+//
+// ---------------------------------------------------------------------------
+//
+void CaTappHandlerPluginTest::tAppHandlerCreateInstance()
+{
+    QServiceManager serviceManager;
+    CaTappHandlerPlugin plugin;
+    QServiceFilter serviceFilter("com.nokia.homescreen.ICommandHandler");
+    serviceFilter.setCustomAttribute("entryTypeName", "templatedApplication");
+    QList<QServiceInterfaceDescriptor> serviceInterfaceDescriptorList =
+        serviceManager.findInterfaces(serviceFilter);
+    int len = serviceInterfaceDescriptorList.size();
+    QVERIFY(len>0);
+    QServiceInterfaceDescriptor serviceInterfaceDescriptor =
+        serviceInterfaceDescriptorList[0];
+    QScopedPointer<QObject> handler(plugin.createInstance(
+        serviceInterfaceDescriptor, NULL, NULL));
+    QVERIFY(!handler.isNull());
+}
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void CaTappHandlerPluginTest::init()
+{
+}
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void CaTappHandlerPluginTest::cleanup()
+{
+}
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void CaTappHandlerPluginTest::initTestCase()
+{
+    QStringList pluginPaths;
+    QString xmlName("catapphandlerplugin.xml");
+
+    pluginPaths.append("c:/resource/qt/plugins/commandhandler");
+    pluginPaths.append("z:/resource/qt/plugins/commandhandler");
+
+    QServiceManager serviceManager;
+    foreach (QString path, pluginPaths) {
+        QApplication::addLibraryPath(path);
+        QDir dir(path);
+        if (dir.exists(xmlName)) {
+            serviceManager.addService(dir.absoluteFilePath(xmlName));
+        }
+    }
+}
+
+// ---------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
+//
+void CaTappHandlerPluginTest::cleanupTestCase()
+{
+
+}
+
+QTEST_MAIN(CaTappHandlerPluginTest)