contentstorage/casrv/causifscanner/tsrc/t_causifscanner/src/T_caUsifScaner.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /*
       
     2 * Copyright (c) 2004 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <w32std.h>
       
    19 #include <apgtask.h>
       
    20 #include <usif/sif/sifcommon.h>
       
    21 #include <usif/sif/sif.h>
       
    22 
       
    23 //  CLASS HEADER
       
    24 #include "T_caUsifScaner.h"
       
    25 
       
    26 //  EXTERNAL INCLUDES
       
    27 
       
    28 #include <cadef.h>
       
    29 
       
    30 #include "castoragefactory.h"
       
    31 #include "castorageproxy.h"
       
    32 #include "casrvengutils.h"
       
    33 #include "causifscanner.h"
       
    34 #include "causifscanner.hrh"
       
    35 #include "cainnerentry.h"
       
    36 #include "cainnerquery.h"
       
    37 #include "caarraycleanup.inl"
       
    38 #include "casrvmmchistory.h"
       
    39 
       
    40 //  INTERNAL INCLUDES
       
    41 #include "casrvtestutils.h"
       
    42 #include "testconsts.h"
       
    43 
       
    44 #include "t_cainstaller.h"
       
    45 
       
    46 #ifdef COVERAGE_MEASUREMENT
       
    47 const unsigned int TIMEOUT_FACTOR = 2;
       
    48 #else
       
    49 const unsigned int TIMEOUT_FACTOR = 1;
       
    50 #endif
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 T_caUsifScaner::T_caUsifScaner():
       
    55     iTestUtils(NULL),
       
    56     iStorage(NULL),
       
    57     iSrvEngUtils(NULL)
       
    58 {
       
    59 }
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void T_caUsifScaner::initTestCase()
       
    63 {
       
    64     if (iTestUtils == NULL) {
       
    65         TRAPD(err, iTestUtils = CTestUtils::NewL());
       
    66         QCOMPARE(err, KErrNone);
       
    67     }
       
    68     QT_TRAP_THROWING(iInstaller = T_CaInstaller::NewL());
       
    69     TRAP_IGNORE(iInstaller->InstallL(KSapiPackageFileName));
       
    70     QTest::qWait(10000);
       
    71 
       
    72     delete iTestUtils;
       
    73     iTestUtils = NULL;
       
    74 }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void T_caUsifScaner::init()
       
    81 {
       
    82     TRAPD(err,
       
    83           iTestUtils = CTestUtils::NewL();
       
    84           iTestUtils->CopyDb();
       
    85 
       
    86           iStorage = CCaStorageProxy::NewL();
       
    87           iSrvEngUtils = CCaSrvEngUtils::NewL();
       
    88           
       
    89           iScr = new Usif::RSoftwareComponentRegistry;          
       
    90           User::LeaveIfError( iScr->Connect() );
       
    91 
       
    92           iPluginParams.storageProxy = iStorage;
       
    93           iPluginParams.engUtils = iSrvEngUtils;
       
    94           iPluginParams.softwareRegistry = iScr;
       
    95          );
       
    96     QCOMPARE(err, KErrNone);
       
    97 }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void T_caUsifScaner::cleanup()
       
   104 {
       
   105     iPluginParams.storageProxy = NULL;
       
   106     iPluginParams.engUtils = NULL;
       
   107     iScr->Close();
       
   108     iPluginParams.softwareRegistry = NULL;
       
   109     
       
   110     delete iSrvEngUtils;
       
   111     iSrvEngUtils = NULL;
       
   112     delete iStorage;
       
   113     iStorage = NULL;
       
   114     delete iTestUtils;
       
   115     iTestUtils = NULL;
       
   116     delete iScr;
       
   117     iScr = NULL;
       
   118 }
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void T_caUsifScaner::cleanupTestCase()
       
   122 {
       
   123     TRAPD(err, iInstaller->UninstallL(KSapiAppFileName));
       
   124     QCOMPARE(err, KErrNone);
       
   125 
       
   126     delete iTestUtils;
       
   127     iTestUtils = NULL;
       
   128     
       
   129     delete iInstaller;
       
   130     REComSession::FinalClose();
       
   131 }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void T_caUsifScaner::testNew()
       
   136 {
       
   137     bool result(false);
       
   138     TRAPD(err,
       
   139           CCaUsifScanner *usifScanner = CCaUsifScanner::NewL(&iPluginParams);
       
   140           result = usifScanner != NULL;
       
   141           QTest::qWait(5000);
       
   142           delete usifScanner;
       
   143          );
       
   144     QCOMPARE(err, KErrNone);
       
   145     QVERIFY(result);
       
   146 }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void T_caUsifScaner::testLoadPlugin()
       
   151 {
       
   152     bool result(false);
       
   153     TRAPD(err, CCaSrvPlugin *plug = iTestUtils->LoadPluginL(
       
   154             TUid::Uid(KCaSrvUsifScannerPlugin), iPluginParams);
       
   155           result = plug != NULL;
       
   156 
       
   157           QTest::qWait(5000);
       
   158           delete plug;
       
   159          );
       
   160     QCOMPARE(err, KErrNone);
       
   161     QVERIFY(result);
       
   162 }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void T_caUsifScaner::testInstalled()
       
   169 {
       
   170     bool flags(false);
       
   171     TRAPD(err,
       
   172         CCaUsifScanner *usifScaner = CCaUsifScanner::NewL(&iPluginParams);
       
   173         CleanupStack::PushL(usifScaner);
       
   174         QTest::qWait(5000);
       
   175         //visible flag update
       
   176         flags = ((iTestUtils->GetPackageFlagsL(KSapiApp, iStorage)
       
   177                 & (EVisible | ERemovable) ) != FALSE);
       
   178           CleanupStack::PopAndDestroy(usifScaner);
       
   179          );
       
   180     QCOMPARE(err, KErrNone);
       
   181     QVERIFY(flags);
       
   182 }
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 void T_caUsifScaner::testAddNewApp()
       
   188 {
       
   189     bool result(false);
       
   190     TRAPD(err,
       
   191           Setup_AddNewAppL();
       
   192           CCaUsifScanner *usifScaner = CCaUsifScanner::NewL(&iPluginParams);
       
   193           CleanupStack::PushL(usifScaner);
       
   194           QTest::qWait(5000);
       
   195           // new app added
       
   196           result = ((iTestUtils->GetPackageFlagsL(KSapiApp,iStorage)
       
   197                      & (EVisible | ERemovable)) != FALSE);
       
   198 
       
   199           CleanupStack::PopAndDestroy(usifScaner);
       
   200          );
       
   201     QCOMPARE(err, KErrNone);
       
   202     QVERIFY(result);
       
   203 }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 void T_caUsifScaner::testAddRemovable()
       
   210 {
       
   211     bool result(false);
       
   212     TRAPD(err,
       
   213         Setup_AddRemovableL();
       
   214         CCaUsifScanner *usifScaner = CCaUsifScanner::NewL(&iPluginParams);
       
   215         CleanupStack::PushL(usifScaner);
       
   216         QTest::qWait(5000 * TIMEOUT_FACTOR);
       
   217         //add removable flag to installed app
       
   218         result = ((iTestUtils->GetPackageFlagsL(KSapiApp, iStorage)
       
   219                 & (ERemovable | EVisible)) != FALSE);
       
   220 
       
   221         CleanupStack::PopAndDestroy(usifScaner);
       
   222     );
       
   223     QCOMPARE(err, KErrNone);
       
   224     QVERIFY(result);
       
   225 }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 void T_caUsifScaner::testInstallNotifier()
       
   232 {
       
   233     bool existsAfterInstall(false);
       
   234     TRAPD(err,
       
   235         CCaUsifScanner *usifScanner = CCaUsifScanner::NewL(&iPluginParams);
       
   236         CleanupStack::PushL(usifScanner);
       
   237         iInstaller->InstallL(KSapiPackageFileName);
       
   238         QTest::qWait(20000 * TIMEOUT_FACTOR);
       
   239         existsAfterInstall = iTestUtils->GetPackageFlagsL(KSapiApp, iStorage);
       
   240         CleanupStack::PopAndDestroy(usifScanner);
       
   241         );
       
   242     QCOMPARE(err, KErrNone);
       
   243     QVERIFY(existsAfterInstall);
       
   244 }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 void T_caUsifScaner::Setup_AddNewAppL()
       
   251 {
       
   252     TBool exists = iTestUtils->AppExistsInStorageL(installedUid, iStorage);
       
   253     if (exists) {
       
   254         iTestUtils->RemoveAppL(installedUid, iStorage);
       
   255         exists = iTestUtils->AppExistsInStorageL(installedUid, iStorage);
       
   256         if (exists) {
       
   257             User::Leave(KErrNotReady);
       
   258         }
       
   259     }
       
   260 }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 void T_caUsifScaner::Setup_AddRemovableL()
       
   267 {
       
   268     RBuf testName;
       
   269     testName.CleanupClosePushL();
       
   270     testName.CreateL(_L("Removable"));
       
   271     CCaInnerEntry *innerEntry = CCaInnerEntry::NewLC();
       
   272     innerEntry->SetEntryTypeNameL(KCaTypeApp);
       
   273     innerEntry->SetUid(installedUid);
       
   274     innerEntry->SetFlags(innerEntry->GetFlags() & ~ERemovable | EVisible);
       
   275     innerEntry->SetTextL(testName);
       
   276     innerEntry->AddAttributeL(KCaAttrComponentId, _L("10"));
       
   277 
       
   278     iStorage->AddL(innerEntry);
       
   279     CleanupStack::PopAndDestroy(innerEntry);
       
   280     CleanupStack::PopAndDestroy(&testName);
       
   281 }
       
   282 
       
   283 QTEST_MAIN(T_caUsifScaner);
       
   284 
       
   285 //  END OF FILE