contentstorage/cahandler/tapp/tsrc/t_catapphandler/src/t_catapphandler.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Main test class for test library.
       
    15  *
       
    16  */
       
    17 
       
    18 //#include <QStateMachine>
       
    19 //#include <QSignalSpy>
       
    20 //#include <QDir>
       
    21 
       
    22 #include <qservicemanager.h>
       
    23 #include <apgtask.h>
       
    24 
       
    25 #include "t_catapphandler.h"
       
    26 #include "catapphandlerplugin.h"
       
    27 #include "catapphandler.h"
       
    28 #include "caentry.h"
       
    29 #include "waitactive.h"
       
    30 
       
    31 QTM_USE_NAMESPACE
       
    32 
       
    33 //const QString xmlPath = "./resource/qt/plugins/stateplugins/"
       
    34 #ifdef Q_OS_SYMBIAN
       
    35 //  const QString mockedStatePluginsXml = "mockstateplugins.s60xml";
       
    36 #else
       
    37 //  const QString mockedStatePluginsXml = "mockstateplugins.xml";
       
    38 #endif
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 void CaTappHandlerPluginTest::testConstruction()
       
    44 {
       
    45     CaTappHandler* tappHandler = new CaTappHandler();
       
    46 
       
    47     QVERIFY(tappHandler);
       
    48 
       
    49     delete tappHandler;
       
    50 }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CaTappHandlerPluginTest::testExecute()
       
    56 {
       
    57     const TInt KAppUid(0x20022EF9); // contacts
       
    58 
       
    59     CaTappHandler* tAppHandler = new CaTappHandler();
       
    60 
       
    61     CaEntry* entry = new CaEntry();
       
    62     entry->setAttribute("item:launchuri","appto://20022EF9?");
       
    63     CWaitActive* wait = CWaitActive::NewL();
       
    64 
       
    65     RWsSession wsSession;
       
    66 
       
    67     CleanupClosePushL(wsSession);
       
    68     User::LeaveIfError(wsSession.Connect());
       
    69 
       
    70     TApaTaskList taskList(wsSession);
       
    71     TApaTask taskBefore = taskList.FindApp(TUid::Uid(KAppUid));
       
    72     if (taskBefore.Exists()) {
       
    73         taskBefore.EndTask(); // close task if exists
       
    74     }
       
    75 
       
    76     tAppHandler->execute(*entry, QString("open")); // run task
       
    77     wait->Wait(15000000);
       
    78     
       
    79     TApaTask taskAfter = taskList.FindApp(TUid::Uid(KAppUid));
       
    80 
       
    81     QVERIFY(taskAfter.Exists());
       
    82     taskAfter.EndTask();
       
    83     CleanupStack::PopAndDestroy(&wsSession);
       
    84     delete wait;
       
    85     delete entry;
       
    86     delete tAppHandler;
       
    87 }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CaTappHandlerPluginTest::tAppHandlerCreateInstance()
       
    94 {
       
    95     QServiceManager serviceManager;
       
    96     CaTappHandlerPlugin plugin;
       
    97     QServiceFilter serviceFilter("com.nokia.homescreen.ICommandHandler");
       
    98     serviceFilter.setCustomAttribute("entryTypeName", "templatedApplication");
       
    99     QList<QServiceInterfaceDescriptor> serviceInterfaceDescriptorList =
       
   100         serviceManager.findInterfaces(serviceFilter);
       
   101     int len = serviceInterfaceDescriptorList.size();
       
   102     QVERIFY(len>0);
       
   103     QServiceInterfaceDescriptor serviceInterfaceDescriptor =
       
   104         serviceInterfaceDescriptorList[0];
       
   105     QScopedPointer<QObject> handler(plugin.createInstance(
       
   106         serviceInterfaceDescriptor, NULL, NULL));
       
   107     QVERIFY(!handler.isNull());
       
   108 }
       
   109 // ---------------------------------------------------------------------------
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CaTappHandlerPluginTest::init()
       
   113 {
       
   114 }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CaTappHandlerPluginTest::cleanup()
       
   120 {
       
   121 }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CaTappHandlerPluginTest::initTestCase()
       
   127 {
       
   128     QStringList pluginPaths;
       
   129     QString xmlName("catapphandlerplugin.xml");
       
   130 
       
   131     pluginPaths.append("c:/resource/qt/plugins/commandhandler");
       
   132     pluginPaths.append("z:/resource/qt/plugins/commandhandler");
       
   133 
       
   134     QServiceManager serviceManager;
       
   135     foreach (QString path, pluginPaths) {
       
   136         QApplication::addLibraryPath(path);
       
   137         QDir dir(path);
       
   138         if (dir.exists(xmlName)) {
       
   139             serviceManager.addService(dir.absoluteFilePath(xmlName));
       
   140         }
       
   141     }
       
   142 }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CaTappHandlerPluginTest::cleanupTestCase()
       
   148 {
       
   149 
       
   150 }
       
   151 
       
   152 QTEST_MAIN(CaTappHandlerPluginTest)