homescreensrv_plat/contentstorage_api/tsrc/t_contentstorage_api/src/t_caclient_executecommand.cpp
changeset 125 26079c1bb561
equal deleted inserted replaced
123:d1dadafc5584 125:26079c1bb561
       
     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 hspluginmodel library.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "t_caclient.h"
       
    19 #include "caservice.h"
       
    20 #include "caquery.h"
       
    21 
       
    22 #ifdef Q_OS_SYMBIAN
       
    23 //s60
       
    24 #include <e32base.h>
       
    25 
       
    26 #include <W32STD.H>
       
    27 #include <APGTASK.H>
       
    28 
       
    29 #include "t_cainstaller.h"
       
    30 
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 void TestCaClient::Test_executeCommand_ById()
       
    37 {
       
    38     {
       
    39         QSharedPointer<CaService> service = CaService::instance();
       
    40         QSharedPointer<CaEntry> entry;
       
    41         CaQuery query;
       
    42         query.setEntryRoles(ItemEntryRole);
       
    43         QList< QSharedPointer<CaEntry> > items = service->getEntries(query);
       
    44         int itemsCount = items.count();
       
    45         QVERIFY(itemsCount >0);
       
    46         for (int i=0; i< itemsCount; i++) {
       
    47             QString tmp = items[i]->text();
       
    48             if (items[i]->text() == "Contacts") {
       
    49                 entry=items[i];
       
    50                 break;
       
    51             }
       
    52         }
       
    53         QVERIFY(entry);
       
    54         bool result = service->executeCommand(entry->id(), "open") == 0;
       
    55         QTest::qWait(2500);
       
    56         QVERIFY2(result, "Command *open* failed");
       
    57         RWsSession session;
       
    58         TInt error = session.Connect();
       
    59         TApaTaskList taskList(session);
       
    60         TApaTask task = taskList.FindApp(_L("Contacts"));
       
    61         QTest::qWait(250);
       
    62         bool taskExists(false);
       
    63         if (task.Exists()) {
       
    64             taskExists = true;
       
    65             task.EndTask();
       
    66         }
       
    67         QTest::qWait(250);
       
    68         session.Close();
       
    69         QTest::qWait(250);
       
    70         QVERIFY(taskExists);
       
    71     }
       
    72 }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void TestCaClient::Test_executeCommand_ByEntry()
       
    79 {
       
    80     {
       
    81 
       
    82         _LIT(KAppTestFile, "c:\\testing\\data\\t_caclient\\installs\\sapiapp_S60_3_X_v_1_0_0.sisx");
       
    83         CaQuery query;
       
    84         QSharedPointer<CaService> service = CaService::instance();
       
    85         CaEntry *entry;
       
    86         CaEntry *entryPhonebook;
       
    87         QTest::qWait(250);
       
    88         QStringList list("application");
       
    89         query.setEntryTypeNames(list);
       
    90         query.setFlagsOn(VisibleEntryFlag);
       
    91         RFs TheFs;
       
    92         User::LeaveIfError(TheFs.Connect());
       
    93         
       
    94         QScopedPointer<T_CaInstaller> installer;
       
    95         QT_TRAP_THROWING(installer.reset(T_CaInstaller::NewL()));
       
    96         
       
    97         installer->InstallL( KAppTestFile );
       
    98 
       
    99         QTest::qWait(30000);
       
   100         
       
   101         QList< QSharedPointer<CaEntry> > items = service->getEntries(query);
       
   102         
       
   103         int itemsCountAndOne = items.count();
       
   104 
       
   105         for (int i=0; i< items.count(); i++) {
       
   106             QString tmp = items[i]->text();
       
   107             if (items[i]->text() == "Contacts") {
       
   108                 entryPhonebook=items[i].data();
       
   109                 break;
       
   110             }
       
   111         }
       
   112 
       
   113         for (int i=0; i< itemsCountAndOne; i++) {
       
   114             if (items[i]->text() == "sapiapp") {
       
   115                 entry=items[i].data();
       
   116                 break;
       
   117             }
       
   118         }
       
   119         //entry attribute will be removed by appscanner
       
   120         //after "sapiapp" entry is removed
       
   121         QVERIFY2(entry, "Sapi app has not installed");
       
   122         entryPhonebook->setAttribute("mmc_id","0x12345678");
       
   123         service->updateEntry(*entryPhonebook);
       
   124         bool result = false;
       
   125         if (entry->id() > 0) {
       
   126             result = service->executeCommand(*entry, "remove") == 0;
       
   127         }
       
   128         QVERIFY2(result, "Remove command returns false");
       
   129         QTest::qWait(40000);
       
   130         
       
   131         QList< QSharedPointer<CaEntry> > itemsNew = service->getEntries(query);
       
   132         int itemsCount = itemsNew.count();
       
   133 
       
   134         QVERIFY2(itemsCountAndOne == itemsCount +1 , "Remove unsuccessful");
       
   135 
       
   136     }
       
   137 }
       
   138 
       
   139 
       
   140 #endif //Q_OS_SYMBIAN