appinstall_plat/sifui_api/tsrc/src/sifuitestcases.cpp
branchRCL_3
changeset 25 7333d7932ef7
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
       
     1 /*
       
     2 * Copyright (c) 2010 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: This file contains hardcoded module implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <badesca.h>                    // CDesCArray, StifUnitMacros.h needs this
       
    19 #include <StifUnitMacros.h>             // STIF_ASSERT_NULL, STIF_ASSERT_NOT_NULL
       
    20 #include <sifui.h>                      // CSifUi
       
    21 #include <sifuiappinfo.h>               // CSifUiAppInfo
       
    22 #include <sifuicertificateinfo.h>       // CSifUiCertificateInfo
       
    23 #include <s32file.h>                    // RFileReadStream
       
    24 #include <s32mem.h>                     // RDesReadStream
       
    25 #include <apgcli.h>                     // RApaLsSession
       
    26 #include <swi/msisuihandlers.h>         // Swi::CCertificateInfo
       
    27 #include "sifuitest.h"                  // CSifUiTest
       
    28 #include "sifuitestcleanuputils.h"      // CleanupResetAndDestroyPushL
       
    29 
       
    30 _LIT( KX509TestCertFile, "\\testing\\data\\test_x509_cert.cer" );
       
    31 
       
    32 _LIT( KEnter, "Enter" );
       
    33 _LIT( KStepFormat, "Step %d" );
       
    34 _LIT( KExit, "Exit" );
       
    35 
       
    36 const TInt KBufferGranularity = 1024;
       
    37 
       
    38 
       
    39 // Internal structure containing test case name and pointer to test function
       
    40 class TCaseInfoInternal
       
    41     {
       
    42     public:
       
    43         const TText*    iCaseName;
       
    44         TestFunction    iMethod;
       
    45         TBool           iIsOOMTest;
       
    46         TInt            iFirstMemoryAllocation;
       
    47         TInt            iLastMemoryAllocation;
       
    48     };
       
    49 
       
    50 
       
    51 // ======== MEMBER FUNCTIONS ========
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CSifUiTest::Case
       
    55 // Returns a test case by number.
       
    56 //
       
    57 // This function contains an array of all available test cases
       
    58 // i.e pair of case name and test function. If case specified by parameter
       
    59 // aCaseNumber is found from array, then that item is returned.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 const TCaseInfo CSifUiTest::Case ( const TInt aCaseNumber ) const
       
    63      {
       
    64     /**
       
    65     * When adding new test cases, implement new test case function and add new
       
    66     * line to KCases array specifing the name of the case and the function.
       
    67     *
       
    68     * ENTRY macro takes two parameters: test case name and test case
       
    69     * function name.
       
    70     *
       
    71     * FUNCENTRY macro takes only test case function name as a parameter and
       
    72     * uses that as a test case name and test case function name.
       
    73     *
       
    74     */
       
    75 
       
    76     static TCaseInfoInternal const KCases[] =
       
    77         {
       
    78         ENTRY( "CreateLowMemTest", CSifUiTest::CreateLowMemTest ),
       
    79         ENTRY( "MemorySelectionTest", CSifUiTest::MemorySelectionTest ),
       
    80         ENTRY( "CertificateInfoTest", CSifUiTest::CertificateInfoTest ),
       
    81         ENTRY( "AppInfoTest", CSifUiTest::AppInfoTest ),
       
    82         ENTRY( "ProgressDialogsTest", CSifUiTest::ProgressDialogsTest )
       
    83         };
       
    84 
       
    85     if( (TUint) aCaseNumber >= sizeof( KCases ) / sizeof( TCaseInfoInternal ) )
       
    86         {
       
    87         TCaseInfo emptyObject( KNullDesC );
       
    88         emptyObject.iMethod = NULL;
       
    89         emptyObject.iIsOOMTest = EFalse;
       
    90         emptyObject.iFirstMemoryAllocation = 0;
       
    91         emptyObject.iLastMemoryAllocation = 0;
       
    92         return emptyObject;
       
    93         }
       
    94 
       
    95     TPtrC caseName( static_cast<const TUint16*>( KCases[ aCaseNumber ].iCaseName ) );
       
    96     TCaseInfo caseInfo( caseName );
       
    97     caseInfo.iMethod = KCases[ aCaseNumber ].iMethod;
       
    98     caseInfo.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest;
       
    99     caseInfo.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation;
       
   100     caseInfo.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation;
       
   101     return caseInfo;
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CSifUiTest::ReadCertificateL()
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CX509Certificate* CSifUiTest::ReadCertificateL( const TDesC& aFileName )
       
   109     {
       
   110     TFindFile findFile( iFs );
       
   111     User::LeaveIfError( findFile.FindByDir( aFileName, KNullDesC ) );
       
   112 
       
   113     RFile file;
       
   114     User::LeaveIfError( file.Open( iFs, findFile.File(), EFileRead ) );
       
   115     CleanupClosePushL( file );
       
   116 
       
   117     TInt fileSize = 0;
       
   118     User::LeaveIfError( file.Size( fileSize ) );
       
   119 
       
   120     HBufC8* buffer = HBufC8::NewLC( fileSize );
       
   121     TPtr8 ptr( buffer->Des() );
       
   122     User::LeaveIfError( file.Read( ptr ) );
       
   123 
       
   124     CX509Certificate* x509cert = CX509Certificate::NewL( *buffer );
       
   125 
       
   126     CleanupStack::PopAndDestroy( buffer );
       
   127     CleanupStack::PopAndDestroy( &file );
       
   128     return x509cert;
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CSifUiTest::CreateTest()
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 TInt CSifUiTest::CreateLowMemTest( TTestResult& aResult )
       
   136     {
       
   137     _LIT( KTestName, "CreateLowMemTest" );
       
   138     TestModuleIf().Printf( 0, KTestName, KEnter );
       
   139 
       
   140     TInt count = 0;
       
   141     TInt error = KErrNoMemory;
       
   142     CSifUi* sifUi = NULL;
       
   143     while( error == KErrNoMemory )
       
   144         {
       
   145         User::__DbgSetAllocFail( EFalse, RHeap::EDeterministic, ++count );
       
   146         TRAP( error, sifUi = CSifUi::NewL() );
       
   147         User::__DbgSetAllocFail( EFalse, RHeap::ENone, count );
       
   148         if( !error )
       
   149             {
       
   150             delete sifUi;
       
   151             sifUi = NULL;
       
   152             }
       
   153         }
       
   154     TestModuleIf().Printf( 1, KTestName, _L("count %d, last error %d"), count, error );
       
   155     SetResult( aResult, error );
       
   156 
       
   157     TestModuleIf().Printf( 0, KTestName, KExit );
       
   158     return KErrNone;
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CSifUiTest::MemorySelectionTest()
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 TInt CSifUiTest::MemorySelectionTest( TTestResult& aResult )
       
   166     {
       
   167     TRAPD( result, DoMemorySelectionTestL( aResult ) );
       
   168     SetResult( aResult, result );
       
   169     return KErrNone;
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CSifUiTest::DoMemorySelectionTestL()
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CSifUiTest::DoMemorySelectionTestL( TTestResult& aResult )
       
   177     {
       
   178     _LIT( KTestName, "MemorySelectionTest" );
       
   179     TestModuleIf().Printf( 0, KTestName, KEnter );
       
   180 
       
   181     enum TTestSteps
       
   182         {
       
   183         EFirstStep,
       
   184         EGetSelectedWhenNotSet,
       
   185         ESetNoDrivesStep,
       
   186         ESetThreeDriveStep,
       
   187         ESetOneDriveStep,
       
   188         EGetSelectedWhenSetButNotAskedStep,
       
   189         ELastStep,
       
   190         EAllDone
       
   191         };
       
   192 
       
   193     CSifUi* sifUi = NULL;
       
   194     RArray<TInt> driveNumbers;
       
   195     CleanupClosePushL( driveNumbers );
       
   196     TInt drive = 0;
       
   197     TInt errorCode = KErrNone;
       
   198 
       
   199     TInt error = KErrNone;
       
   200     for( TInt step = EFirstStep; step < EAllDone && !error; ++step )
       
   201         {
       
   202         TestModuleIf().Printf( 1, KTestName, KStepFormat, step );
       
   203         switch( step )
       
   204             {
       
   205             case EFirstStep:
       
   206                 STIF_ASSERT_NULL( sifUi );
       
   207                 TRAP( error, sifUi = CSifUi::NewL() );
       
   208                 if( !error )
       
   209                     {
       
   210                     CleanupStack::PushL( sifUi );
       
   211                     }
       
   212                 break;
       
   213 
       
   214             case EGetSelectedWhenNotSet:
       
   215                 STIF_ASSERT_NOT_NULL( sifUi );
       
   216                 TRAP( error, errorCode = sifUi->SelectedDrive( drive ) );
       
   217                 if( error == KErrNone && errorCode == KErrNotFound )
       
   218                     {
       
   219                     error = KErrNone;
       
   220                     }
       
   221                 else
       
   222                     {
       
   223                     error = KErrGeneral;
       
   224                     }
       
   225                 break;
       
   226 
       
   227             case ESetNoDrivesStep:
       
   228                 STIF_ASSERT_NOT_NULL( sifUi );
       
   229                 TRAP( error, sifUi->SetMemorySelectionL( driveNumbers ) );
       
   230                 break;
       
   231 
       
   232             case ESetThreeDriveStep:
       
   233                 STIF_ASSERT_NOT_NULL( sifUi );
       
   234                 driveNumbers.Append( EDriveC );
       
   235                 driveNumbers.Append( EDriveE );
       
   236                 driveNumbers.Append( EDriveF );
       
   237                 TRAP( error, sifUi->SetMemorySelectionL( driveNumbers ) );
       
   238                 break;
       
   239 
       
   240             case ESetOneDriveStep:
       
   241                 STIF_ASSERT_NOT_NULL( sifUi );
       
   242                 driveNumbers.Append( EDriveC );
       
   243                 TRAP( error, sifUi->SetMemorySelectionL( driveNumbers ) );
       
   244                 break;
       
   245 
       
   246             case EGetSelectedWhenSetButNotAskedStep:
       
   247                 STIF_ASSERT_NOT_NULL( sifUi );
       
   248                 TRAP( error, errorCode = sifUi->SelectedDrive( drive ) );
       
   249                 if( error == KErrNone && errorCode == KErrNotFound )
       
   250                     {
       
   251                     error = KErrNone;
       
   252                     }
       
   253                 else
       
   254                     {
       
   255                     error = KErrGeneral;
       
   256                     }
       
   257                 break;
       
   258 
       
   259             case ELastStep:
       
   260                 STIF_ASSERT_NOT_NULL( sifUi );
       
   261                 CleanupStack::PopAndDestroy( sifUi );
       
   262                 sifUi = NULL;
       
   263                 break;
       
   264 
       
   265             default:
       
   266                 User::Leave( KErrGeneral );
       
   267                 break;
       
   268             }
       
   269         }
       
   270     User::LeaveIfError( error );
       
   271 
       
   272     CleanupStack::PopAndDestroy( &driveNumbers );
       
   273     TestModuleIf().Printf( 0, KTestName, KExit );
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CSifUiTest::CertificateInfoTest()
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 TInt CSifUiTest::CertificateInfoTest( TTestResult& aResult )
       
   281     {
       
   282     TRAPD( result, DoCertificateInfoTestL( aResult ) );
       
   283     SetResult( aResult, result );
       
   284     return KErrNone;
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CSifUiTest::DoCertificateInfoTestL()
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void CSifUiTest::DoCertificateInfoTestL( TTestResult& aResult )
       
   292     {
       
   293     _LIT( KTestName, "CertificateInfoTest" );
       
   294     TestModuleIf().Printf( 0, KTestName, KEnter );
       
   295 
       
   296     enum TTestSteps
       
   297         {
       
   298         EFirstStep,
       
   299         ESetNoCertificates,
       
   300         EReadAndSetCertificate,
       
   301         ELastStep,
       
   302         EAllDone
       
   303         };
       
   304 
       
   305     CSifUi* sifUi = NULL;
       
   306     RPointerArray<CSifUiCertificateInfo> certificates;
       
   307     CleanupResetAndDestroyPushL( certificates );
       
   308 
       
   309     TInt error = KErrNone;
       
   310     for( TInt step = EFirstStep; step < EAllDone && !error; ++step )
       
   311         {
       
   312         TestModuleIf().Printf( 1, KTestName, KStepFormat, step );
       
   313         switch( step )
       
   314             {
       
   315             case EFirstStep:
       
   316                 STIF_ASSERT_NULL( sifUi );
       
   317                 TRAP( error, sifUi = CSifUi::NewL() );
       
   318                 if( !error )
       
   319                     {
       
   320                     CleanupStack::PushL( sifUi );
       
   321                     }
       
   322                 break;
       
   323 
       
   324             case ESetNoCertificates:
       
   325                 STIF_ASSERT_NOT_NULL( sifUi );
       
   326                 TRAP( error, sifUi->SetCertificateInfoL( certificates ) );
       
   327                 break;
       
   328 
       
   329             case EReadAndSetCertificate:
       
   330                 {
       
   331                 STIF_ASSERT_NOT_NULL( sifUi );
       
   332                 CX509Certificate* x509cert = ReadCertificateL( KX509TestCertFile );
       
   333                 CleanupStack::PushL( x509cert );
       
   334 
       
   335                 Swi::CCertificateInfo* swiCert = Swi::CCertificateInfo::NewLC( *x509cert );
       
   336                 CSifUiCertificateInfo* testCert = CSifUiCertificateInfo::NewLC( *swiCert );
       
   337 
       
   338                 CBufBase* buf = CBufFlat::NewL( KBufferGranularity );
       
   339                 CleanupStack::PushL( buf );
       
   340                 RBufWriteStream writeStream( *buf );
       
   341                 CleanupClosePushL( writeStream );
       
   342                 STIF_ASSERT_TRUE( buf->Size() == 0 );
       
   343                 testCert->ExternalizeL( writeStream );
       
   344                 STIF_ASSERT_TRUE( buf->Size() > 0 );
       
   345                 CleanupStack::PopAndDestroy( 2, buf );      // writeStream, buf
       
   346 
       
   347                 CleanupStack::PopAndDestroy( testCert );
       
   348                 testCert = NULL;
       
   349 
       
   350                 testCert = CSifUiCertificateInfo::NewL( *swiCert );
       
   351                 CleanupStack::PushL( testCert );
       
   352                 certificates.AppendL( testCert );
       
   353                 CleanupStack::Pop( testCert );
       
   354                 TRAP( error, sifUi->SetCertificateInfoL( certificates ) );
       
   355 
       
   356                 CleanupStack::PopAndDestroy( 2, x509cert );     // swiCert, x509cert
       
   357                 }
       
   358                 break;
       
   359 
       
   360             case ELastStep:
       
   361                 STIF_ASSERT_NOT_NULL( sifUi );
       
   362                 CleanupStack::PopAndDestroy( sifUi );
       
   363                 sifUi = NULL;
       
   364                 break;
       
   365 
       
   366             default:
       
   367                 User::Leave( KErrGeneral );
       
   368                 break;
       
   369             }
       
   370         }
       
   371     User::LeaveIfError( error );
       
   372 
       
   373     CleanupStack::PopAndDestroy( &certificates );
       
   374     TestModuleIf().Printf( 0, KTestName, KExit );
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CSifUiTest::AppInfoTest()
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 TInt CSifUiTest::AppInfoTest( TTestResult& aResult )
       
   382     {
       
   383     TRAPD( result, DoAppInfoTestL( aResult ) );
       
   384     SetResult( aResult, result );
       
   385     return KErrNone;
       
   386     }
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // CSifUiTest::DoAppInfoTestL()
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 void CSifUiTest::DoAppInfoTestL( TTestResult& aResult )
       
   393     {
       
   394     _LIT( KTestName, "AppInfoTest" );
       
   395     TestModuleIf().Printf( 0, KTestName, KEnter );
       
   396 
       
   397     enum TTestSteps
       
   398         {
       
   399         EFirstStep,
       
   400         EAppInfoTests,
       
   401         EAppInfoIconTest,
       
   402         EShowConfirmation,
       
   403         EShowError,
       
   404         ELastStep,
       
   405         EAllDone
       
   406         };
       
   407 
       
   408     CSifUi* sifUi = NULL;
       
   409 
       
   410     _LIT( KAppName, "TestApplication" );
       
   411     _LIT( KAppVendor, "TestSupplier" );
       
   412     const TVersion KAppVersion( 1, 2, 3 );
       
   413     const TInt KAppSize = 0x1234;
       
   414 
       
   415     TInt error = KErrNone;
       
   416     for( TInt step = EFirstStep; step < EAllDone && !error; ++step )
       
   417         {
       
   418         TestModuleIf().Printf( 1, KTestName, KStepFormat, step );
       
   419         switch( step )
       
   420             {
       
   421             case EFirstStep:
       
   422                 STIF_ASSERT_NULL( sifUi );
       
   423                 TRAP( error, sifUi = CSifUi::NewL() );
       
   424                 if( !error )
       
   425                     {
       
   426                     CleanupStack::PushL( sifUi );
       
   427                     }
       
   428                 break;
       
   429 
       
   430             case EAppInfoTests:
       
   431                 {
       
   432                 STIF_ASSERT_NOT_NULL( sifUi );
       
   433                 CSifUiAppInfo* appInfo = NULL;
       
   434                 appInfo = CSifUiAppInfo::NewLC( KAppName, KAppVendor, KAppVersion, KAppSize, NULL );
       
   435 
       
   436                 STIF_ASSERT_TRUE( appInfo->Name().Compare( KAppName ) == 0 );
       
   437                 STIF_ASSERT_TRUE( appInfo->Vendor().Compare( KAppVendor ) == 0 );
       
   438 
       
   439                 STIF_ASSERT_TRUE( appInfo->Version().iMajor == KAppVersion.iMajor );
       
   440                 STIF_ASSERT_TRUE( appInfo->Version().iMinor == KAppVersion.iMinor );
       
   441                 STIF_ASSERT_TRUE( appInfo->Version().iBuild == KAppVersion.iBuild );
       
   442 
       
   443                 STIF_ASSERT_TRUE( appInfo->Size() == KAppSize );
       
   444                 STIF_ASSERT_TRUE( appInfo->Bitmaps() == NULL );
       
   445 
       
   446                 CBufBase* buf = CBufFlat::NewL( KBufferGranularity );
       
   447                 CleanupStack::PushL( buf );
       
   448                 RBufWriteStream writeStream( *buf );
       
   449                 CleanupClosePushL( writeStream );
       
   450                 STIF_ASSERT_TRUE( buf->Size() == 0 );
       
   451                 appInfo->ExternalizeL( writeStream );
       
   452                 STIF_ASSERT_TRUE( buf->Size() > 0 );
       
   453                 CleanupStack::PopAndDestroy( &writeStream );
       
   454                 CleanupStack::PopAndDestroy( buf );
       
   455 
       
   456                 CleanupStack::PopAndDestroy( appInfo );
       
   457                 }
       
   458                 break;
       
   459 
       
   460             case EAppInfoIconTest:
       
   461                 {
       
   462                 STIF_ASSERT_NOT_NULL( sifUi );
       
   463                 CSifUiAppInfo* appInfo = NULL;
       
   464 
       
   465                 // TODO: proper icon test needed
       
   466                 CApaMaskedBitmap* appBitmap = NULL;
       
   467                 appInfo = CSifUiAppInfo::NewLC( KAppName, KAppVendor, KAppVersion, KAppSize, appBitmap );
       
   468 
       
   469                 CBufBase* buf = CBufFlat::NewL( KBufferGranularity );
       
   470                 CleanupStack::PushL( buf );
       
   471                 RBufWriteStream writeStream( *buf );
       
   472                 CleanupClosePushL( writeStream );
       
   473                 STIF_ASSERT_TRUE( buf->Size() == 0 );
       
   474                 appInfo->ExternalizeL( writeStream );
       
   475                 STIF_ASSERT_TRUE( buf->Size() > 0 );
       
   476                 CleanupStack::PopAndDestroy( &writeStream );
       
   477                 CleanupStack::PopAndDestroy( buf );
       
   478 
       
   479                 CleanupStack::PopAndDestroy( appInfo );
       
   480                 }
       
   481                 break;
       
   482 
       
   483             case EShowConfirmation:
       
   484                 {
       
   485                 STIF_ASSERT_NOT_NULL( sifUi );
       
   486                 CSifUiAppInfo* appInfo = NULL;
       
   487                 appInfo = CSifUiAppInfo::NewL( KAppName, KAppVendor, KAppVersion, KAppSize, NULL );
       
   488                 CleanupStack::PushL( appInfo );
       
   489 
       
   490                 CBufBase* buf = CBufFlat::NewL( KBufferGranularity );
       
   491                 CleanupStack::PushL( buf );
       
   492                 RBufWriteStream writeStream( *buf );
       
   493                 CleanupClosePushL( writeStream );
       
   494                 STIF_ASSERT_TRUE( buf->Size() == 0 );
       
   495                 appInfo->ExternalizeL( writeStream );
       
   496                 STIF_ASSERT_TRUE( buf->Size() > 0 );
       
   497                 CleanupStack::PopAndDestroy( &writeStream );
       
   498                 CleanupStack::PopAndDestroy( buf );
       
   499 
       
   500                 TBool result = EFalse;
       
   501                 // TODO: how to close opened dialog automatically?
       
   502                 TRAP( error, result = sifUi->ShowConfirmationL( *appInfo ) );
       
   503                 if( result )
       
   504                     {
       
   505                     _LIT( KAccepted, "Accepted" );
       
   506                     TestModuleIf().Printf( 1, KTestName, KAccepted );
       
   507                     }
       
   508                 else
       
   509                     {
       
   510                     _LIT( KCancelled, "Cancelled" );
       
   511                     TestModuleIf().Printf( 1, KTestName, KCancelled );
       
   512                     }
       
   513                 CleanupStack::PopAndDestroy( appInfo );
       
   514                 }
       
   515                 break;
       
   516 
       
   517             case EShowError:
       
   518                 {
       
   519                 STIF_ASSERT_NOT_NULL( sifUi );
       
   520                 _LIT( KErrorMessage, "Test error" );
       
   521                 _LIT( KErrorDetails, "Test error details" );
       
   522                 // TODO: how to close opened dialog automatically?
       
   523                 TRAP( error, sifUi->ShowFailedL( KErrNotFound, KErrorMessage, KErrorDetails ) );
       
   524                 }
       
   525                 break;
       
   526 
       
   527             case ELastStep:
       
   528                 STIF_ASSERT_NOT_NULL( sifUi );
       
   529                 CleanupStack::PopAndDestroy( sifUi );
       
   530                 sifUi = NULL;
       
   531                 break;
       
   532 
       
   533             default:
       
   534                 User::Leave( KErrGeneral );
       
   535                 break;
       
   536             }
       
   537         }
       
   538     User::LeaveIfError( error );
       
   539 
       
   540     TestModuleIf().Printf( 0, KTestName, KExit );
       
   541     }
       
   542 
       
   543 // -----------------------------------------------------------------------------
       
   544 // CSifUiTest::ProgressDialogsTest()
       
   545 // -----------------------------------------------------------------------------
       
   546 //
       
   547 TInt CSifUiTest::ProgressDialogsTest( TTestResult& aResult )
       
   548     {
       
   549     TRAPD( result, DoProgressDialogsTestL( aResult ) );
       
   550     SetResult( aResult, result );
       
   551     return KErrNone;
       
   552     }
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // CSifUiTest::DoProgressDialogsTestL()
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 void CSifUiTest::DoProgressDialogsTestL( TTestResult& aResult )
       
   559     {
       
   560     _LIT( KTestName, "ProgressDlgsTest" );
       
   561     TestModuleIf().Printf( 0, KTestName, KEnter );
       
   562 
       
   563     enum TTestSteps
       
   564         {
       
   565         EFirstStep,
       
   566         EShowProgress,
       
   567         EUpdateProgress,
       
   568         EShowComplete,
       
   569         ELastStep,
       
   570         EAllDone
       
   571         };
       
   572 
       
   573     CSifUi* sifUi = NULL;
       
   574 
       
   575     _LIT( KAppName, "NoitaCilppa" );
       
   576     _LIT( KAppVendor, "Rodnev" );
       
   577     const TVersion KAppVersion( 3, 2, 1 );
       
   578     const TInt KAppSize = 0x4321;
       
   579 
       
   580     const TInt KMaxProgress = 150;
       
   581     const TInt KUpdateStarts = -10;
       
   582     const TInt KUpdateEnds = KMaxProgress + 10;
       
   583     const TInt KUpdateStep = 4;
       
   584 
       
   585     TInt error = KErrNone;
       
   586     for( TInt step = EFirstStep; step < EAllDone && !error; ++step )
       
   587         {
       
   588         TestModuleIf().Printf( 1, KTestName, KStepFormat, step );
       
   589         switch( step )
       
   590             {
       
   591             case EFirstStep:
       
   592                 STIF_ASSERT_NULL( sifUi );
       
   593                 TRAP( error, sifUi = CSifUi::NewL() );
       
   594                 if( !error )
       
   595                     {
       
   596                     CleanupStack::PushL( sifUi );
       
   597                     }
       
   598                 break;
       
   599 
       
   600             case EShowProgress:
       
   601                 {
       
   602                 STIF_ASSERT_NOT_NULL( sifUi );
       
   603                 CSifUiAppInfo* appInfo = NULL;
       
   604                 appInfo = CSifUiAppInfo::NewL( KAppName, KAppVendor, KAppVersion, KAppSize, NULL );
       
   605                 CleanupStack::PushL( appInfo );
       
   606                 TRAP( error, sifUi->ShowProgressL( *appInfo, KMaxProgress ) );
       
   607                 CleanupStack::PopAndDestroy( appInfo );
       
   608                 }
       
   609                 break;
       
   610 
       
   611             case EUpdateProgress:
       
   612                 {
       
   613                 STIF_ASSERT_NOT_NULL( sifUi );
       
   614                 for( TInt i = KUpdateStarts; i < KUpdateEnds; i += KUpdateStep )
       
   615                     {
       
   616                     TRAP( error, sifUi->IncreaseProgressBarValueL( KUpdateStep ) );
       
   617                     }
       
   618                 }
       
   619                 break;
       
   620 
       
   621             case EShowComplete:
       
   622                 STIF_ASSERT_NOT_NULL( sifUi );
       
   623                 TRAP( error, sifUi->ShowCompleteL() );
       
   624                 break;
       
   625 
       
   626             case ELastStep:
       
   627                 STIF_ASSERT_NOT_NULL( sifUi );
       
   628                 CleanupStack::PopAndDestroy( sifUi );
       
   629                 sifUi = NULL;
       
   630                 break;
       
   631 
       
   632             default:
       
   633                 User::Leave( KErrGeneral );
       
   634                 break;
       
   635             }
       
   636         }
       
   637     User::LeaveIfError( error );
       
   638 
       
   639     TestModuleIf().Printf( 0, KTestName, KExit );
       
   640     }
       
   641