os/ossrv/lowlevellibsandfws/pluginfw/TestExecute/EComSWITests/src/installstep.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// SWIS test step implementation
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
/**
sl@0
    19
 @file
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "installStep.h"
sl@0
    23
#include "common.h"
sl@0
    24
#include "tui.h"
sl@0
    25
#include <e32std.h>
sl@0
    26
#include <test/testexecutelog.h>
sl@0
    27
#include <swi/launcher.h>
sl@0
    28
#include <bautils.h>
sl@0
    29
#include "swi/sisregistrysession.h"
sl@0
    30
#include "swi/sisregistrypackage.h"
sl@0
    31
#include "swi/sisregistryentry.h"
sl@0
    32
#include "cleanuputils.h"
sl@0
    33
sl@0
    34
using namespace Swi;
sl@0
    35
sl@0
    36
//
sl@0
    37
// CinstallStep
sl@0
    38
//
sl@0
    39
sl@0
    40
CinstallStep::~CinstallStep()
sl@0
    41
    {
sl@0
    42
    delete iUi;
sl@0
    43
    }
sl@0
    44
    
sl@0
    45
sl@0
    46
CinstallStep::CinstallStep(TInstallType aInstallType, TBool aDoCancelTest)
sl@0
    47
    : iInstallType(aInstallType), iDoCancelTest(aDoCancelTest),
sl@0
    48
	  iInstallSuccess(EFalse)
sl@0
    49
    {
sl@0
    50
    // Call base class method to set up the human readable name for logging
sl@0
    51
    
sl@0
    52
    switch (aInstallType)
sl@0
    53
        {
sl@0
    54
        case EUseFileHandle:
sl@0
    55
            SetTestStepName(KInstallFHStep);
sl@0
    56
            break;
sl@0
    57
        
sl@0
    58
        case EUseMemory:
sl@0
    59
            SetTestStepName(KInstallMemStep);
sl@0
    60
            break;
sl@0
    61
sl@0
    62
        case EUseFileName:
sl@0
    63
            SetTestStepName(KInstallStep);
sl@0
    64
            break;
sl@0
    65
        
sl@0
    66
        case EUseCAF:
sl@0
    67
            SetTestStepName(KInstallCAFStep);
sl@0
    68
            break;
sl@0
    69
sl@0
    70
        case EUseOpenFileName:
sl@0
    71
            SetTestStepName(KInstallOpenFileStep);
sl@0
    72
            break;
sl@0
    73
            
sl@0
    74
        case ECheckExitValue:
sl@0
    75
            SetTestStepName(KCheckedInstallStep);
sl@0
    76
            break;     
sl@0
    77
            
sl@0
    78
        }
sl@0
    79
    }
sl@0
    80
sl@0
    81
/**
sl@0
    82
 * Override of base class virtual. Prepares for the test run of SWIS
sl@0
    83
 * @return TVerdict code
sl@0
    84
 */
sl@0
    85
TVerdict CinstallStep::doTestStepPreambleL()
sl@0
    86
    {
sl@0
    87
    SetTestStepResult(EPass);
sl@0
    88
    // get step parameters
sl@0
    89
    TPtrC str;
sl@0
    90
    if (!GetStringFromConfig(ConfigSection(), _L("sis"), str))
sl@0
    91
        {
sl@0
    92
        INFO_PRINTF1(HTML_RED);
sl@0
    93
        ERR_PRINTF1(_L("FAIL: Missing SIS file name"));
sl@0
    94
        INFO_PRINTF1(HTML_RED_OFF);
sl@0
    95
        SetTestStepResult(EFail);
sl@0
    96
        return TestStepResult();
sl@0
    97
        }
sl@0
    98
    iSisFileName.Copy(str);
sl@0
    99
    INFO_PRINTF2(_L("Installing '%S'"), &iSisFileName);
sl@0
   100
            
sl@0
   101
    // create UI handler and populate the answers from XML file
sl@0
   102
    iUi = new(ELeave) TUI();
sl@0
   103
   
sl@0
   104
	return TestStepResult();
sl@0
   105
    }
sl@0
   106
sl@0
   107
sl@0
   108
sl@0
   109
sl@0
   110
/**
sl@0
   111
 * Override of base class pure virtual
sl@0
   112
 * Demonstrates reading configuration parameters fom an ini file section
sl@0
   113
 * @return TVerdict code
sl@0
   114
 */
sl@0
   115
TVerdict CinstallStep::doTestStepL()
sl@0
   116
    {
sl@0
   117
    INFO_PRINTF1(KInstallStep);
sl@0
   118
sl@0
   119
    // Try to set up a repository object, we'll need this if any
sl@0
   120
    // NotifyRequests are listed. Only open the repository if there are
sl@0
   121
    // notifys.
sl@0
   122
  	
sl@0
   123
 	TInt bRet;
sl@0
   124
sl@0
   125
    // First find out if the install step is supposed to be successful.
sl@0
   126
    TInt insterr=KErrNone;
sl@0
   127
    bRet = GetIntFromConfig(ConfigSection(), KExpectedError, insterr );
sl@0
   128
    if(bRet!=1) insterr=KErrNone;
sl@0
   129
sl@0
   130
    CInstallPrefs* prefs = CInstallPrefs::NewLC();
sl@0
   131
    TInt err = DoInstallL(*prefs);        
sl@0
   132
	iInstallSuccess = (err == KErrNone);
sl@0
   133
    
sl@0
   134
    // Expected error?
sl@0
   135
    if(insterr != err)
sl@0
   136
        {
sl@0
   137
        INFO_PRINTF1(HTML_RED);
sl@0
   138
        ERR_PRINTF3( _L("Installation return wrong error code, expected %d, got %d."), insterr, err );
sl@0
   139
        INFO_PRINTF1(HTML_RED_OFF);
sl@0
   140
        SetTestStepResult(EFail);
sl@0
   141
        }
sl@0
   142
   else
sl@0
   143
        {
sl@0
   144
        INFO_PRINTF2( _L("Installation error code %d (expected)."), err );
sl@0
   145
        }
sl@0
   146
 
sl@0
   147
 
sl@0
   148
    CleanupStack::PopAndDestroy(prefs);
sl@0
   149
sl@0
   150
    return TestStepResult();
sl@0
   151
    
sl@0
   152
    }
sl@0
   153
sl@0
   154
TInt CinstallStep::DoInstallL(CInstallPrefs& aInstallPrefs)
sl@0
   155
    {
sl@0
   156
    TInt err=KErrNone;
sl@0
   157
    RFs fs;
sl@0
   158
    RFile file;
sl@0
   159
    switch (iInstallType)
sl@0
   160
        {
sl@0
   161
        case EUseFileName:
sl@0
   162
            err = Launcher::Install(*iUi, iSisFileName, aInstallPrefs);
sl@0
   163
            INFO_PRINTF2(_L("EUseFileName: Install return code was %d"), err);
sl@0
   164
            return err;
sl@0
   165
sl@0
   166
        case EUseOpenFileName:
sl@0
   167
        // open the file as a shared for readers only
sl@0
   168
            {
sl@0
   169
            User::LeaveIfError(fs.Connect());
sl@0
   170
            fs.ShareProtected();
sl@0
   171
            CleanupClosePushL(fs);
sl@0
   172
            RFile file;
sl@0
   173
            User::LeaveIfError(file.Open(fs, iSisFileName, EFileShareReadersOnly));
sl@0
   174
            CleanupClosePushL(file);
sl@0
   175
            TInt error = Launcher::Install(*iUi, iSisFileName, aInstallPrefs);
sl@0
   176
            CleanupStack::PopAndDestroy(2, &fs);
sl@0
   177
            return error;            
sl@0
   178
            }
sl@0
   179
sl@0
   180
        case EUseFileHandle:
sl@0
   181
            {
sl@0
   182
            RFs fs;
sl@0
   183
            User::LeaveIfError(fs.Connect());
sl@0
   184
            fs.ShareProtected();
sl@0
   185
            CleanupClosePushL(fs);
sl@0
   186
            RFile file;
sl@0
   187
            User::LeaveIfError(file.Open(fs, iSisFileName, 0));
sl@0
   188
            CleanupClosePushL(file);
sl@0
   189
            TInt error=Launcher::Install(*iUi, file, aInstallPrefs);
sl@0
   190
            CleanupStack::PopAndDestroy(2, &fs);
sl@0
   191
            return error;
sl@0
   192
            }
sl@0
   193
sl@0
   194
        case ECheckExitValue:
sl@0
   195
            {
sl@0
   196
            // This test case does an install and checks for pass or failure
sl@0
   197
            // TInt err = Launcher::Install(*iUi, iSisFileName, *prefs);
sl@0
   198
            TInt err = Launcher::Install(*iUi, iSisFileName, aInstallPrefs);
sl@0
   199
            INFO_PRINTF2(_L("Install return code was %d"), err);
sl@0
   200
            
sl@0
   201
            TPtrC expected;
sl@0
   202
            if (!GetStringFromConfig(ConfigSection(), _L("result"), expected))
sl@0
   203
                {
sl@0
   204
                return ETestSuiteError;
sl@0
   205
                }
sl@0
   206
            else 
sl@0
   207
                {
sl@0
   208
                _LIT(KSucess, "sucess");
sl@0
   209
                _LIT(KFailure, "failure");
sl@0
   210
                
sl@0
   211
                TVerdict result;
sl@0
   212
                
sl@0
   213
                if (expected.CompareF(KSucess) == 0)
sl@0
   214
                    {
sl@0
   215
                    result = (err == KErrNone ? EPass : EFail);
sl@0
   216
                    }
sl@0
   217
                else if (expected.CompareF(KFailure) == 0)
sl@0
   218
                    {
sl@0
   219
                    result = (err != KErrNone ? EPass : EFail);
sl@0
   220
                    }
sl@0
   221
                else 
sl@0
   222
                    {
sl@0
   223
                    result = ETestSuiteError;
sl@0
   224
                    }
sl@0
   225
                return result;
sl@0
   226
                }
sl@0
   227
            }
sl@0
   228
            // Unreachable.
sl@0
   229
//          break;    
sl@0
   230
        }
sl@0
   231
    
sl@0
   232
    // Shouldn't get here
sl@0
   233
    return KErrGeneral;
sl@0
   234
    }
sl@0
   235
sl@0
   236
/**
sl@0
   237
 * Override of base class virtual
sl@0
   238
 * @return TVerdict code
sl@0
   239
 */
sl@0
   240
TVerdict CinstallStep::doTestStepPostambleL()
sl@0
   241
    {
sl@0
   242
    CheckFilesExistL();
sl@0
   243
    CheckFilesNonExistL();
sl@0
   244
    return TestStepResult();
sl@0
   245
    }
sl@0
   246
sl@0
   247
/** Need to wait a few seconds for ECOM to
sl@0
   248
discover the change. Otherwise the next step may fail.
sl@0
   249
@pre caller has checked the install/uninstall
sl@0
   250
is successful. Otherwise will waste 30 s.
sl@0
   251
*/
sl@0
   252
void Cinstallers::WaitForEComReDiscoveryL()
sl@0
   253
	{
sl@0
   254
    REComSession& ecomSession = REComSession::OpenL();
sl@0
   255
	CleanupClosePushL(ecomSession);
sl@0
   256
	TRequestStatus ecomstatus;
sl@0
   257
	ecomSession.NotifyOnChange(ecomstatus);
sl@0
   258
sl@0
   259
	RTimer timer;
sl@0
   260
	User::LeaveIfError(timer.CreateLocal());
sl@0
   261
	CleanupClosePushL(timer);
sl@0
   262
	const TInt KInterval = 30000000; // 30 s
sl@0
   263
	TRequestStatus timerstatus;
sl@0
   264
	timer.After(timerstatus, KInterval);
sl@0
   265
sl@0
   266
	User::WaitForRequest(ecomstatus, timerstatus);
sl@0
   267
sl@0
   268
	if (ecomstatus == KRequestPending)
sl@0
   269
		{
sl@0
   270
		ecomSession.CancelNotifyOnChange(ecomstatus);
sl@0
   271
		User::WaitForRequest(ecomstatus);
sl@0
   272
sl@0
   273
        INFO_PRINTF1(HTML_RED);
sl@0
   274
        ERR_PRINTF1(_L("No notification from ECOM"));
sl@0
   275
        INFO_PRINTF1(HTML_RED_OFF);
sl@0
   276
		// does not affect test result as this is the equivalent of
sl@0
   277
		// DELAY 30000 in the script.
sl@0
   278
		}
sl@0
   279
	else
sl@0
   280
		{
sl@0
   281
		timer.Cancel();
sl@0
   282
		User::WaitForRequest(timerstatus);
sl@0
   283
        INFO_PRINTF1(_L("ECOM has discovered the change"));
sl@0
   284
		}
sl@0
   285
sl@0
   286
	CleanupStack::PopAndDestroy(2); // ecomsession, RTimer
sl@0
   287
	REComSession::FinalClose();
sl@0
   288
	}
sl@0
   289
sl@0
   290
/** Resolver installation step */
sl@0
   291
sl@0
   292
/** constructor */
sl@0
   293
CResolverInstallStep::CResolverInstallStep(CinstallStep::TInstallType aInstallType)
sl@0
   294
	: CinstallStep(aInstallType)
sl@0
   295
	{
sl@0
   296
	}
sl@0
   297
sl@0
   298
/** destructor */
sl@0
   299
CResolverInstallStep::~CResolverInstallStep()
sl@0
   300
	{
sl@0
   301
	iLibrary.Close();
sl@0
   302
	}
sl@0
   303
sl@0
   304
/** uses CinstallStep::dotestStepL to do the install.
sl@0
   305
But adds an optional step of loading a DLL before, and
sl@0
   306
a step to wait for ECom rediscovery after.
sl@0
   307
*/
sl@0
   308
TVerdict CResolverInstallStep::doTestStepL()
sl@0
   309
	{
sl@0
   310
	TPtrC libraryPath;
sl@0
   311
    if (GetStringFromConfig(ConfigSection(), _L("loadresolver"), libraryPath))
sl@0
   312
		{
sl@0
   313
		TUidType nullUid;
sl@0
   314
		TInt err = iLibrary.Load(libraryPath, nullUid);
sl@0
   315
        if (err != KErrNone)
sl@0
   316
	        {
sl@0
   317
	        ERR_PRINTF2(_L("Preload resolver failed %d"), err);
sl@0
   318
	        return EFail;
sl@0
   319
	        }
sl@0
   320
		}
sl@0
   321
sl@0
   322
	// continue to do the actual install.
sl@0
   323
	TVerdict ret = CinstallStep::doTestStepL();
sl@0
   324
sl@0
   325
	if (iInstallSuccess)
sl@0
   326
		{
sl@0
   327
		WaitForEComReDiscoveryL();
sl@0
   328
		}
sl@0
   329
sl@0
   330
	return ret;
sl@0
   331
	}
sl@0
   332
sl@0
   333
/* *******************************************************************************
sl@0
   334
 *  Code below was copies from
sl@0
   335
 *       \master\common\generic\security\swi\test\tuiscriptadaptors\tswisstep.cpp
sl@0
   336
 *
sl@0
   337
 *  If there are any problems with this code, it may be worth contacting the
sl@0
   338
 *  Security team.
sl@0
   339
 * *******************************************************************************/
sl@0
   340
sl@0
   341
//
sl@0
   342
// CuninstallStep
sl@0
   343
//
sl@0
   344
sl@0
   345
CuninstallStep::~CuninstallStep()
sl@0
   346
    {
sl@0
   347
    delete iUi;
sl@0
   348
    }
sl@0
   349
sl@0
   350
CuninstallStep::CuninstallStep(TUninstallType aType, TBool aDoCancelTest)
sl@0
   351
    : iType(aType), iDoCancelTest(aDoCancelTest)
sl@0
   352
    {
sl@0
   353
    // Call base class method to set up the human readable name for logging
sl@0
   354
    SetTestStepName(KUninstallStep);
sl@0
   355
    }
sl@0
   356
sl@0
   357
    
sl@0
   358
    
sl@0
   359
    
sl@0
   360
/**
sl@0
   361
 * Override of base class virtual. Prepares for the test run of SWIS
sl@0
   362
 * @return TVerdict code
sl@0
   363
 */
sl@0
   364
TVerdict CuninstallStep::doTestStepPreambleL()
sl@0
   365
    {
sl@0
   366
    // get step parameters
sl@0
   367
    TInt uid=0;
sl@0
   368
sl@0
   369
    TPtrC str;
sl@0
   370
sl@0
   371
    if (!GetHexFromConfig(ConfigSection(), _L("uid"), uid))
sl@0
   372
        {
sl@0
   373
        INFO_PRINTF1(HTML_RED);
sl@0
   374
        ERR_PRINTF1(_L("Missing uid"));
sl@0
   375
        INFO_PRINTF1(HTML_RED_OFF);
sl@0
   376
        SetTestStepResult(EFail);
sl@0
   377
        return TestStepResult();
sl@0
   378
        }
sl@0
   379
sl@0
   380
    iUid.iUid=uid;
sl@0
   381
        
sl@0
   382
    if (iType == EByPackage)
sl@0
   383
        {
sl@0
   384
        TPtrC vendorName;
sl@0
   385
        if (!GetStringFromConfig(ConfigSection(), _L("vendorName"), vendorName))
sl@0
   386
            {
sl@0
   387
            INFO_PRINTF1(HTML_RED);
sl@0
   388
            ERR_PRINTF1(_L("Missing Vendor Name"));
sl@0
   389
            INFO_PRINTF1(HTML_RED_OFF);
sl@0
   390
            SetTestStepResult(EFail);
sl@0
   391
            return TestStepResult();
sl@0
   392
            }
sl@0
   393
        iVendorName.Set(vendorName);
sl@0
   394
        
sl@0
   395
        TPtrC packageName;
sl@0
   396
        if (!GetStringFromConfig(ConfigSection(), _L("packageName"), packageName))
sl@0
   397
            {
sl@0
   398
            INFO_PRINTF1(HTML_RED);
sl@0
   399
            ERR_PRINTF1(_L("Missing Package Name"));
sl@0
   400
            INFO_PRINTF1(HTML_RED_OFF);
sl@0
   401
            SetTestStepResult(EFail);
sl@0
   402
            return TestStepResult();
sl@0
   403
            }
sl@0
   404
        iPackageName.Set(packageName);
sl@0
   405
            
sl@0
   406
        INFO_PRINTF4(_L("Uninstalling %D, %S, %S"), 
sl@0
   407
            iUid.iUid, &iPackageName, &iVendorName);
sl@0
   408
        // create UI handler and populate the answers from XML file
sl@0
   409
        iUi = new(ELeave) TUI;
sl@0
   410
        
sl@0
   411
        }
sl@0
   412
    else if (iType== EByUid)
sl@0
   413
        {
sl@0
   414
        INFO_PRINTF2(_L("Uninstalling '%D'"), iUid.iUid);
sl@0
   415
        // create UI handler and populate the answers from XML file
sl@0
   416
        iUi = new(ELeave) TUI;
sl@0
   417
        
sl@0
   418
        }
sl@0
   419
sl@0
   420
    return TestStepResult();
sl@0
   421
    }
sl@0
   422
sl@0
   423
/**
sl@0
   424
 * Override of base class pure virtual
sl@0
   425
 * Demonstrates reading configuration parameters fom an ini file section
sl@0
   426
 * @return TVerdict code
sl@0
   427
 */
sl@0
   428
sl@0
   429
TInt CuninstallStep::DoUninstallL()
sl@0
   430
    {
sl@0
   431
    TInt err=0;
sl@0
   432
    
sl@0
   433
    INFO_PRINTF1(KUninstallStep);
sl@0
   434
sl@0
   435
    if (iType == EByUid)
sl@0
   436
        {
sl@0
   437
        // launch the installation
sl@0
   438
        err = Launcher::Uninstall(*iUi, iUid); 
sl@0
   439
        return err; 
sl@0
   440
        }
sl@0
   441
    else if (iType == EByPackage)
sl@0
   442
        {
sl@0
   443
        err = 0;
sl@0
   444
        
sl@0
   445
        // Go through list of packages from base package to get augmentations.
sl@0
   446
        CSisRegistryPackage* uninstallPackage=CSisRegistryPackage::NewLC(iUid, iPackageName, iVendorName);
sl@0
   447
        INFO_PRINTF3(_L("UnInstalling '%S', '%S'"), &iPackageName, &iVendorName);
sl@0
   448
        
sl@0
   449
        // err=Launcher::Uninstall(*iUi, *uninstallPackage);
sl@0
   450
         
sl@0
   451
		RSisRegistrySession registrySession;
sl@0
   452
        User::LeaveIfError(registrySession.Connect());
sl@0
   453
        CleanupClosePushL(registrySession);
sl@0
   454
sl@0
   455
        RSisRegistryEntry registryEntry;
sl@0
   456
    
sl@0
   457
        User::LeaveIfError(registryEntry.Open(registrySession, iUid));
sl@0
   458
        CleanupClosePushL(registryEntry);
sl@0
   459
sl@0
   460
        CSisRegistryPackage* package=registryEntry.PackageL();
sl@0
   461
        CleanupStack::PushL(package);
sl@0
   462
        
sl@0
   463
        if (*package == *uninstallPackage)
sl@0
   464
            {
sl@0
   465
            err=Launcher::Uninstall(*iUi, *package); 
sl@0
   466
            }
sl@0
   467
        else
sl@0
   468
            {
sl@0
   469
            // check augmenations
sl@0
   470
            RPointerArray<CSisRegistryPackage> augmentationPackages;
sl@0
   471
	        CleanupResetAndDestroy<RPointerArray<CSisRegistryPackage> >::PushL(augmentationPackages);
sl@0
   472
sl@0
   473
            registryEntry.AugmentationsL(augmentationPackages);
sl@0
   474
            
sl@0
   475
            for (TInt i=0; i < augmentationPackages.Count(); ++i)
sl@0
   476
                {
sl@0
   477
                if (*augmentationPackages[i] == *uninstallPackage)
sl@0
   478
                    {
sl@0
   479
                    err=User::LeaveIfError(Launcher::Uninstall(*iUi, *augmentationPackages[i])); 
sl@0
   480
                    break;
sl@0
   481
                    }
sl@0
   482
                }
sl@0
   483
                
sl@0
   484
            if (err != 0)
sl@0
   485
	        	{
sl@0
   486
	        	INFO_PRINTF1(HTML_RED);
sl@0
   487
	            ERR_PRINTF2(_L("Package Augmentation Not found for '%s' "), &iPackageName);
sl@0
   488
	            INFO_PRINTF1(HTML_RED_OFF);
sl@0
   489
	            SetTestStepResult(EFail);
sl@0
   490
	            return TestStepResult();
sl@0
   491
	        	}
sl@0
   492
sl@0
   493
            CleanupStack::PopAndDestroy(&augmentationPackages);
sl@0
   494
            }    
sl@0
   495
        
sl@0
   496
        CleanupStack::PopAndDestroy(3, &registrySession);
sl@0
   497
        CleanupStack::PopAndDestroy(uninstallPackage);
sl@0
   498
        }
sl@0
   499
    return err;
sl@0
   500
    }
sl@0
   501
sl@0
   502
/* ******************************************************************************
sl@0
   503
 *  End of copied code.
sl@0
   504
 * ******************************************************************************/
sl@0
   505
sl@0
   506
TVerdict CuninstallStep::doTestStepL()
sl@0
   507
    {
sl@0
   508
    INFO_PRINTF1(KUninstallStep);
sl@0
   509
sl@0
   510
sl@0
   511
sl@0
   512
    // Wait a fraction over a second. This is necessary because we may just
sl@0
   513
    // have been messing about with repository settings and if the install
sl@0
   514
    // happens really quickly we might not see a datestamp change (esp. on
sl@0
   515
    // hardware where the timestamp granularity is poor).
sl@0
   516
    User::After(1100000);
sl@0
   517
    User::LeaveIfError(DoUninstallL());
sl@0
   518
sl@0
   519
    return TestStepResult();
sl@0
   520
    }
sl@0
   521
sl@0
   522
/**
sl@0
   523
 * Override of base class virtual
sl@0
   524
 * @return TVerdict code
sl@0
   525
 */
sl@0
   526
TVerdict CuninstallStep::doTestStepPostambleL()
sl@0
   527
    {
sl@0
   528
    CheckFilesExistL();
sl@0
   529
    CheckFilesNonExistL();
sl@0
   530
    return TestStepResult();
sl@0
   531
    }
sl@0
   532
sl@0
   533
// CResolverUninstallStep class
sl@0
   534
sl@0
   535
/** constructor */
sl@0
   536
CResolverUninstallStep::CResolverUninstallStep(CuninstallStep::TUninstallType aType)
sl@0
   537
	: CuninstallStep(aType)
sl@0
   538
	{
sl@0
   539
	}
sl@0
   540
sl@0
   541
/** nothing to do in destructor */
sl@0
   542
CResolverUninstallStep::~CResolverUninstallStep()
sl@0
   543
	{
sl@0
   544
	}
sl@0
   545
sl@0
   546
/** runs CuninstallStep::doTestStepL and then
sl@0
   547
do a WaitForEComReDiscoveryL */
sl@0
   548
TVerdict CResolverUninstallStep::doTestStepL()
sl@0
   549
	{
sl@0
   550
	TVerdict ret = CuninstallStep::doTestStepL();
sl@0
   551
	if (ret == EPass)
sl@0
   552
		{
sl@0
   553
		WaitForEComReDiscoveryL();
sl@0
   554
		}
sl@0
   555
    return ret;
sl@0
   556
	}
sl@0
   557
sl@0
   558
Cinstallers::~Cinstallers()
sl@0
   559
/**
sl@0
   560
 * Destructor
sl@0
   561
 */
sl@0
   562
    {
sl@0
   563
    }
sl@0
   564
sl@0
   565
Cinstallers::Cinstallers()
sl@0
   566
/**
sl@0
   567
 * Constructor
sl@0
   568
 */
sl@0
   569
    {
sl@0
   570
    }
sl@0
   571
sl@0
   572
void Cinstallers::CheckFilesL(const TDesC& aNumEntries,
sl@0
   573
                                   const TDesC& aEntryBase, TBool aCheckExist)
sl@0
   574
    {
sl@0
   575
    TInt numEntries=0;
sl@0
   576
    TInt nErr=0;
sl@0
   577
sl@0
   578
    _LIT(Report_CheckFiles, "CheckFilesL");
sl@0
   579
    INFO_PRINTF1(Report_CheckFiles);
sl@0
   580
sl@0
   581
    RFs fs;
sl@0
   582
    User::LeaveIfError(fs.Connect());
sl@0
   583
    fs.ShareProtected();
sl@0
   584
    CleanupClosePushL(fs);
sl@0
   585
sl@0
   586
    if (GetIntFromConfig(ConfigSection(), aNumEntries, numEntries) && numEntries!=0)
sl@0
   587
        {
sl@0
   588
        INFO_PRINTF1(Report_CheckFiles);
sl@0
   589
        TPtrC fname;
sl@0
   590
        for (TInt i=0; i<numEntries; i++)
sl@0
   591
            {
sl@0
   592
            // construct name of the key
sl@0
   593
            const TInt KKeyBufSize=64;
sl@0
   594
            TBuf<KKeyBufSize> keyBuf(aEntryBase);
sl@0
   595
            keyBuf.AppendNum(i);
sl@0
   596
            
sl@0
   597
            if (GetStringFromConfig(ConfigSection(), keyBuf, fname))
sl@0
   598
                {            
sl@0
   599
                TInt timeout=1e7;
sl@0
   600
                TInt wait=2.5e5;
sl@0
   601
                // check if the file (doesn't) exist. Give it some time if
sl@0
   602
                // we see a failure in case there's a race with the
sl@0
   603
                // (un)installer 
sl@0
   604
                
sl@0
   605
                if (aCheckExist)
sl@0
   606
                    {
sl@0
   607
                    TInt sec=timeout;
sl@0
   608
                    while (!BaflUtils::FileExists(fs, fname) && (sec>0))
sl@0
   609
                        {
sl@0
   610
                        User::After(wait);
sl@0
   611
                        sec -= wait;
sl@0
   612
                        };
sl@0
   613
                    if (!BaflUtils::FileExists(fs, fname))
sl@0
   614
                        {
sl@0
   615
                        INFO_PRINTF1(HTML_RED);
sl@0
   616
                        ERR_PRINTF2(_L("File missing: %S"), &fname);
sl@0
   617
                        INFO_PRINTF1(HTML_RED_OFF);
sl@0
   618
                        nErr++;
sl@0
   619
                        }
sl@0
   620
                    }
sl@0
   621
                else
sl@0
   622
                    {
sl@0
   623
                    TInt sec=timeout;
sl@0
   624
                    while (BaflUtils::FileExists(fs, fname) && (sec>0))
sl@0
   625
                        {
sl@0
   626
                        User::After(wait);
sl@0
   627
                        sec -= wait;
sl@0
   628
                        };
sl@0
   629
                    if (BaflUtils::FileExists(fs, fname))
sl@0
   630
                        {
sl@0
   631
                        INFO_PRINTF1(HTML_RED);
sl@0
   632
                        ERR_PRINTF2(_L("File exists (but shouldn't): %S"), &fname);
sl@0
   633
                        INFO_PRINTF1(HTML_RED_OFF);
sl@0
   634
                        nErr++;
sl@0
   635
                        }
sl@0
   636
                    }
sl@0
   637
                }
sl@0
   638
            else
sl@0
   639
                {
sl@0
   640
                // the string must exist, otherwise the config is invalid
sl@0
   641
                INFO_PRINTF1(HTML_RED);
sl@0
   642
                ERR_PRINTF2(_L("Missing file name for key '%S'"), &keyBuf);
sl@0
   643
                INFO_PRINTF1(HTML_RED_OFF);
sl@0
   644
                nErr++;
sl@0
   645
                }
sl@0
   646
            }
sl@0
   647
        }
sl@0
   648
sl@0
   649
        if (nErr)
sl@0
   650
            SetTestStepResult(EFail);
sl@0
   651
        CleanupStack::PopAndDestroy(1, &fs);
sl@0
   652
    }
sl@0
   653
sl@0
   654
void Cinstallers::CheckFilesExistL()
sl@0
   655
    {
sl@0
   656
    _LIT(KNumExist, "numexist"); // this specifies how many files to check for
sl@0
   657
    _LIT(KExistBase, "exist");   // + number (0-based) = file to check for
sl@0
   658
    CheckFilesL(KNumExist, KExistBase, ETrue);
sl@0
   659
    }
sl@0
   660
sl@0
   661
void Cinstallers::CheckFilesNonExistL()
sl@0
   662
    {
sl@0
   663
    _LIT(KNumNonExist, "numnonexist"); // this specifies how many files to check for
sl@0
   664
    _LIT(KNonExistBase, "nonexist"); // + number (0-based) = file to check for
sl@0
   665
    CheckFilesL(KNumNonExist, KNonExistBase, EFalse);
sl@0
   666
    }
sl@0
   667