videoutils_plat/videoconnutility_api/tsrc/VCXTestCommon/src/VCXTestCommon.cpp
changeset 41 d88d70d98bbc
parent 34 814ba97beeb9
child 46 3bc36dbd63c2
equal deleted inserted replaced
34:814ba97beeb9 41:d88d70d98bbc
     1 /*
       
     2 * Copyright (c) 2008 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 the License "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 
       
    19 // INCLUDE FILES
       
    20 #include <e32Base.h>
       
    21 #include <tz.h>
       
    22 #include <badesca.h>
       
    23 #include <commdb.h>
       
    24 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    25 
       
    26 #include "VCXTestCommon.h"
       
    27 #include "IptvTestUtilALR.h"
       
    28 #include "CIptvTestVerifyData.h"
       
    29 #include "TestUtilConnectionWaiter.h"
       
    30 #include "VCXTestLog.h"
       
    31 
       
    32 // EXTERNAL DATA STRUCTURES
       
    33 
       
    34 // EXTERNAL FUNCTION PROTOTYPES
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 // MACROS
       
    39 
       
    40 // LOCAL CONSTANTS AND MACROS
       
    41 _LIT(KDummyfilePathFormat, "%S:\\data\\temp");
       
    42 _LIT(KDummyfileFormat, "%d.dat");
       
    43 _LIT(KDoubleBacklash, "\\");
       
    44 
       
    45 // MODULE DATA STRUCTURES
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 
       
    51 // ============================= LOCAL FUNCTIONS ===============================
       
    52 
       
    53 // ============================ MEMBER FUNCTIONS ===============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CVCXTestCommon::CVCXTestCommon
       
    57 // C++ default constructor can NOT contain any code, that
       
    58 // might leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CVCXTestCommon::CVCXTestCommon()
       
    62     {
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CVCXTestCommon::ConstructL
       
    67 // Symbian 2nd phase constructor can leave.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CVCXTestCommon::ConstructL()
       
    71     {
       
    72     VCXLOGLO1(">>>CVCXTestCommon::ConstructL");
       
    73 
       
    74     User::LeaveIfError( iFs.Connect() );
       
    75 
       
    76     PrintIaps(); 
       
    77 
       
    78     PrintDriveInfo( _L("C") );
       
    79     PrintDriveInfo( _L("E") );
       
    80     PrintDriveInfo( _L("D") );
       
    81     PrintDriveInfo( _L("F") );
       
    82 
       
    83     //ListDir( _L("C:\\"), 0 );
       
    84     //ListDir( _L("E:\\"), 0 );
       
    85 
       
    86     iIptvVerifyData = CIptvTestVerifyData::NewL();
       
    87     iVideoCreator = CIptvTestVideoCreator::NewL();
       
    88 
       
    89     VCXLOGLO1("<<<CVCXTestCommon::ConstructL");
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CIptvServicesFromFile::~CVCXTestCommon
       
    94 // Destructor
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CVCXTestCommon::~CVCXTestCommon()
       
    98     {
       
    99     VCXLOGLO1(">>>CVCXTestCommon::~CVCXTestCommon");
       
   100 
       
   101     delete iIptvVerifyData;
       
   102     iIptvVerifyData = NULL;
       
   103 
       
   104     delete iVideoCreator;
       
   105     iVideoCreator = NULL;
       
   106 
       
   107     iFs.Close();
       
   108 
       
   109     VCXLOGLO1("<<<CVCXTestCommon::~CVCXTestCommon");
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CVCXTestCommon::NewL
       
   114 // Two-phased constructor.
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C CVCXTestCommon* CVCXTestCommon::NewL()
       
   118     {
       
   119     VCXLOGLO1(">>>CVCXTestCommon::NewL");
       
   120     CVCXTestCommon* self = new( ELeave ) CVCXTestCommon;
       
   121 
       
   122     CleanupStack::PushL( self );
       
   123     self->ConstructL();
       
   124     CleanupStack::Pop();
       
   125     VCXLOGLO1("<<<CVCXTestCommon::NewL");
       
   126     return self;
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CVCXTestCommon::GetFileSize
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C TBool CVCXTestCommon::GetFileSize(TDesC& aFullPath, TUint32& aFileSize)
       
   134     {
       
   135     VCXLOGLO1(">>>CVCXTestCommon::GetFileSize");
       
   136     TBool rv = FALSE;
       
   137     TEntry entry;
       
   138     TInt err = KErrNone;
       
   139 
       
   140     aFileSize=0;
       
   141 
       
   142     err = iFs.Entry( aFullPath, entry );
       
   143 
       
   144     if(KErrNone == err && !entry.IsDir())
       
   145         {
       
   146         aFileSize = entry.iSize;
       
   147         rv = TRUE;
       
   148         }
       
   149 
       
   150     VCXLOGLO1("<<<CVCXTestCommon::GetFileSize");
       
   151     return rv;
       
   152     }
       
   153     
       
   154 // -----------------------------------------------------------------------------
       
   155 // CVCXTestCommon::GetIapIdL
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 EXPORT_C TBool CVCXTestCommon::GetIapIdL(const TDesC& aIapName, TUint32& aIapId)
       
   159     {
       
   160     VCXLOGLO1(">>>CVCXTestCommon::GetIapIdL");
       
   161 
       
   162     TBool found( EFalse );
       
   163 
       
   164 #ifdef __WINSCW__
       
   165     if( aIapName != KIptvTestBadIapName && aIapName != _L("invalidiap") )
       
   166         {
       
   167         _LIT(KEmulatorIap, "Ethernet with Daemon Dynamic IP");
       
   168         found = GetIapIdByNameL(KEmulatorIap, aIapId);
       
   169         VCXLOGLO1("<<<CVCXTestCommon::GetIapIdL");
       
   170         return found;
       
   171         }
       
   172 #endif
       
   173     
       
   174     if( aIapName == _L("default") )
       
   175         {
       
   176         VCXLOGLO1("CVCXTestCommon::GetIapIdL -- Searching default iap from cenrep");
       
   177         CIptvTestUtilALR* util = CIptvTestUtilALR::NewLC();
       
   178         aIapId = util->GetDefaultIapCenRep();
       
   179         CleanupStack::PopAndDestroy( util );
       
   180         if( aIapId != 0 )
       
   181             {
       
   182             VCXLOGLO2("CVCXTestCommon::GetIapIdL -- Got default from cenrep: %d", aIapId);
       
   183             return ETrue;
       
   184             }
       
   185         }
       
   186     
       
   187     if( aIapName == _L("default") )
       
   188         {
       
   189         VCXLOGLO1("CVCXTestCommon::GetIapIdL -- Getting default iap via ALR util");
       
   190         CIptvTestUtilALR* util = CIptvTestUtilALR::NewLC();
       
   191         aIapId = util->GetDefaultIap();
       
   192         CleanupStack::PopAndDestroy( util );
       
   193         if( aIapId != 0 )
       
   194             {
       
   195             VCXLOGLO2("CVCXTestCommon::GetIapIdL -- Got default: %d", aIapId);
       
   196             return ETrue;
       
   197             }
       
   198         }
       
   199     
       
   200     VCXLOGLO2("CVCXTestCommon:: Searching IAP: %S", &aIapName);
       
   201 
       
   202     found = GetIapIdByNameL(aIapName, aIapId);
       
   203 
       
   204     // Iap with exact name found
       
   205     if( found )
       
   206         {
       
   207         VCXLOGLO1("<<<CVCXTestCommon::GetIapIdL");
       
   208         return found;
       
   209         }
       
   210     else
       
   211     if(aIapName == KIptvTestBadIapName) // Search bad iap only for a name.
       
   212         {
       
   213         VCXLOGLO2("CVCXTestCommon:: Iap with name %S not found!", &aIapName);
       
   214         VCXLOGLO1("<<<CVCXTestCommon::GetIapIdL");
       
   215         return found;
       
   216         }
       
   217 
       
   218     VCXLOGLO1("<<<CVCXTestCommon:: Iap with exact name was not found.");
       
   219 
       
   220     TBuf<128> searchFor(aIapName);
       
   221     searchFor.LowerCase();
       
   222 
       
   223     if(searchFor == _L("invalidiap") )
       
   224         {
       
   225         aIapId = 6000;
       
   226         VCXLOGLO1("<<<CVCXTestCommon::GetIapIdL");
       
   227         return ETrue;
       
   228         }
       
   229 
       
   230     TBool isWlanIapName( EFalse );
       
   231 
       
   232     if( aIapName == _L("wlan") )
       
   233         {
       
   234         found = GetIapIdByTypeL(CVCXTestCommon::EWlanIap, aIapId, 0);
       
   235         isWlanIapName = ETrue;
       
   236         }
       
   237     else
       
   238     if( aIapName == _L("wlan2") )
       
   239         {
       
   240         found = GetIapIdByTypeL(CVCXTestCommon::EWlanIap, aIapId, 1);
       
   241         isWlanIapName = ETrue;
       
   242         }
       
   243     else
       
   244     if( aIapName == _L("internet") )
       
   245         {
       
   246         found = GetIapIdByTypeL(CVCXTestCommon::EGprsIap, aIapId, 0);
       
   247         }
       
   248     else
       
   249     if( aIapName == _L("internet2") )
       
   250         {
       
   251         found = GetIapIdByTypeL(CVCXTestCommon::EGprsIap, aIapId, 1);
       
   252         }
       
   253 
       
   254     if( !found && !isWlanIapName )
       
   255         {
       
   256         VCXLOGLO1("<<<CVCXTestCommon:: Trying to find alternative IAP.");
       
   257 
       
   258         // Try search other known GPRS IAPs
       
   259         _LIT(KIapElisaInternet, "elisa internet");
       
   260         _LIT(KIapElisaMMS, "elisa mms");
       
   261         _LIT(KIapInternet, "internet");
       
   262         _LIT(KIapProinternet, "prointernet");
       
   263         _LIT(KGprsInternet, "gprs internet");
       
   264 
       
   265         if( GetIapIdByNameL(KIapElisaInternet, aIapId) ||
       
   266             GetIapIdByNameL(KIapElisaMMS, aIapId) ||
       
   267             GetIapIdByNameL(KIapInternet, aIapId) ||
       
   268             GetIapIdByNameL(KIapProinternet, aIapId) ||
       
   269             GetIapIdByNameL(KGprsInternet, aIapId) )
       
   270             {
       
   271             found = ETrue;
       
   272             }
       
   273 
       
   274         if( !found )
       
   275             {
       
   276             VCXLOGLO1("<<<CVCXTestCommon:: Any GPRS IAP is good...");
       
   277             found = GetIapIdByTypeL(CVCXTestCommon::EGprsIap, aIapId, 0);
       
   278             }
       
   279         }
       
   280     else
       
   281         {
       
   282         VCXLOGLO1("<<<CVCXTestCommon:: WLAN IAP wanted. Not found.");
       
   283         }
       
   284 
       
   285     VCXLOGLO1("<<<CVCXTestCommon::GetIapIdL");
       
   286     return found;
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CVCXTestCommon::GetIapIdByNameL
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 EXPORT_C TBool CVCXTestCommon::GetIapIdByNameL(const TDesC& aIapName, TUint32& aIapId)
       
   294     {
       
   295     VCXLOGLO1(">>>CVCXTestCommon::GetIapIdByNameL");
       
   296     TBool found = EFalse;
       
   297     aIapId = 0;
       
   298 
       
   299     TBuf<128> searchFor(aIapName);
       
   300     searchFor.LowerCase();
       
   301     
       
   302     // Get IAP names and ids from the database
       
   303     CCommsDatabase* cdb( NULL );
       
   304     TRAPD( err, cdb = CCommsDatabase::NewL( EDatabaseTypeIAP ) );
       
   305     if( err != KErrNone )
       
   306         {
       
   307         VCXLOGLO2("CVCXTestCommon::GetIapIdByNameL: CCommsDatabase::NewL left: %d, leaving", err);
       
   308         User::Leave( err );
       
   309         }
       
   310     CleanupStack::PushL( cdb );
       
   311 
       
   312     cdb->ShowHiddenRecords();
       
   313 
       
   314     CCommsDbTableView* view( NULL );
       
   315     TRAP( err, view = cdb->OpenTableLC( TPtrC(IAP) ); CleanupStack::Pop( view ); );
       
   316     CleanupStack::PushL( view );
       
   317     
       
   318     if( err != KErrNone )
       
   319         {
       
   320         VCXLOGLO2("CVCXTestCommon::GetIapIdByNameL: CCommsDatabase::OpenTableLC left: %d, leaving", err);
       
   321         User::Leave( err );
       
   322         }
       
   323     
       
   324     TBuf<40> name;
       
   325     TUint32 id;
       
   326     TInt res = view->GotoFirstRecord();
       
   327     while( res == KErrNone )
       
   328         {
       
   329         TRAP( err, view->ReadTextL( TPtrC(COMMDB_NAME), name ) );
       
   330         if( err != KErrNone ) continue;
       
   331         TRAP( err, view->ReadUintL( TPtrC(COMMDB_ID), id ) );
       
   332         if( err != KErrNone ) continue;
       
   333 
       
   334         name.LowerCase();
       
   335         if(searchFor == name)
       
   336             {
       
   337             aIapId = id;
       
   338             VCXLOGLO3("CVCXTestCommon:: Found IAP: %d, %S", aIapId, &aIapName);
       
   339             found = ETrue;
       
   340             break;
       
   341             }
       
   342         res = view->GotoNextRecord();
       
   343         }
       
   344 
       
   345     CleanupStack::PopAndDestroy( view );
       
   346     CleanupStack::PopAndDestroy( cdb );
       
   347 
       
   348     VCXLOGLO1("<<<CVCXTestCommon::GetIapIdByNameL");
       
   349     return found;
       
   350     }
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 // CVCXTestCommon::GetIapIdByTypeL
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 EXPORT_C TBool CVCXTestCommon::GetIapIdByTypeL(TIptvTestIapType aType, TUint32& aIapId, TInt aOrderNumber)
       
   357     {
       
   358     VCXLOGLO1(">>>CVCXTestCommon::GetIapIdByTypeL");
       
   359 
       
   360     aIapId = 0;
       
   361     TBool found( EFalse );
       
   362 
       
   363     #ifdef __WINSCW__
       
   364         found = GetIapIdByNameL( _L("Ethernet with Daemon Dynamic IP"), aIapId );
       
   365         VCXLOGLO1("<<<CVCXTestCommon::GetIapIdByTypeL");
       
   366         return found;
       
   367     #endif
       
   368 
       
   369     // Get AP names and ids from the database
       
   370     CCommsDatabase* TheDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
   371     CleanupStack::PushL( TheDb );
       
   372 
       
   373     TheDb->ShowHiddenRecords();
       
   374 
       
   375     CCommsDbTableView* view = TheDb->OpenTableLC( TPtrC(IAP) );
       
   376 
       
   377     TBuf<40> name;
       
   378     TUint32 id;
       
   379     TBuf<255> iapType;
       
   380     TInt matchCount(0);
       
   381 
       
   382     TInt res = view->GotoFirstRecord();
       
   383 
       
   384     while( res == KErrNone )
       
   385         {
       
   386         view->ReadTextL( TPtrC(COMMDB_NAME), name );
       
   387         view->ReadUintL( TPtrC(COMMDB_ID), id );
       
   388         view->ReadTextL( TPtrC(IAP_SERVICE_TYPE), iapType);
       
   389 
       
   390         VCXLOGLO3("CVCXTestCommon:: name: %S, id: %d", &name, id);
       
   391         VCXLOGLO2("CVCXTestCommon:: type: %S", &iapType);
       
   392 
       
   393         if( ( iapType == _L("LANService") && aType == EWlanIap && name != _L("Easy WLAN") ) ||
       
   394             ( iapType == _L("OutgoingGPRS") && aType == EGprsIap ) )
       
   395             {
       
   396             if( matchCount == aOrderNumber )
       
   397                 {
       
   398                 found = ETrue;
       
   399                 aIapId = id;
       
   400                 break;
       
   401                 }
       
   402             matchCount++;
       
   403             }
       
   404 
       
   405         res = view->GotoNextRecord();
       
   406         }
       
   407 
       
   408     CleanupStack::PopAndDestroy( view ); // view
       
   409     CleanupStack::PopAndDestroy( TheDb ); // TheDb
       
   410 
       
   411     VCXLOGLO1("<<<CVCXTestCommon::GetIapIdByTypeL");
       
   412     return found;
       
   413     }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CVCXTestCommon::GetIapNameById
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 EXPORT_C TBool CVCXTestCommon::GetIapNameById(TDes& aIapName, TUint32 aIapId)
       
   420     {
       
   421     TBool found = FALSE;
       
   422 
       
   423     // Get AP names and ids from the database
       
   424     CCommsDatabase* TheDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
   425     CleanupStack::PushL( TheDb );
       
   426 
       
   427     TheDb->ShowHiddenRecords();
       
   428 
       
   429     CCommsDbTableView* view = TheDb->OpenTableLC( TPtrC(IAP) );
       
   430 
       
   431     TBuf<40> name;
       
   432     TUint32 id;
       
   433     TInt res = view->GotoFirstRecord();
       
   434 
       
   435     while( res == KErrNone )
       
   436         {
       
   437         view->ReadTextL( TPtrC(COMMDB_NAME), name );
       
   438         view->ReadUintL( TPtrC(COMMDB_ID), id );
       
   439 
       
   440         res = view->GotoNextRecord();
       
   441         //VCXLOGLO3("IAP name, id: %S, %d", &name, id);
       
   442         if(id == aIapId)
       
   443             {
       
   444             found = TRUE;
       
   445             aIapName.Zero();
       
   446             aIapName.Append(name);
       
   447             break;
       
   448             }
       
   449         }
       
   450 
       
   451     CleanupStack::PopAndDestroy( view ); // view
       
   452     CleanupStack::PopAndDestroy( TheDb ); // TheDb
       
   453 
       
   454     return found;
       
   455     }
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // CVCXTestCommon::PrintIaps
       
   459 // -----------------------------------------------------------------------------
       
   460 //
       
   461 EXPORT_C void CVCXTestCommon::PrintIaps()
       
   462     {
       
   463     VCXLOGLO1(">>>CVCXTestCommon::PrintIaps");
       
   464     // Get IAP names and ids from the database
       
   465     CCommsDatabase* TheDb( NULL );
       
   466     TRAPD( err, TheDb = CCommsDatabase::NewL( EDatabaseTypeIAP ) );
       
   467 
       
   468     if( err == KErrNone && TheDb )
       
   469         {
       
   470         CleanupStack::PushL( TheDb );
       
   471 
       
   472         TheDb->ShowHiddenRecords();
       
   473 
       
   474         CCommsDbTableView* view( NULL );
       
   475         TRAP( err, view = TheDb->OpenTableLC( TPtrC(IAP) ); CleanupStack::Pop( view ); );
       
   476         CleanupStack::PushL( view );
       
   477 
       
   478         if( err == KErrNone && view )
       
   479             {
       
   480             TBuf<40> name;
       
   481             TUint32 id;
       
   482             err = view->GotoFirstRecord();
       
   483             while( err == KErrNone )
       
   484                 {
       
   485                 TRAP( err, view->ReadTextL( TPtrC(COMMDB_NAME), name ) );
       
   486                 if( err != KErrNone ) break;
       
   487                 TRAP( err, view->ReadUintL( TPtrC(COMMDB_ID), id ) );
       
   488                 if( err != KErrNone ) break;
       
   489                 VCXLOGLO3("CVCXTestCommon:: IAP name, id: %S, %d", &name, id);
       
   490 
       
   491                 err = view->GotoNextRecord();
       
   492                 if( err != KErrNone ) break;
       
   493                 }
       
   494             }
       
   495         CleanupStack::PopAndDestroy( view ); // view
       
   496         CleanupStack::PopAndDestroy( TheDb ); // TheDb
       
   497         }
       
   498     VCXLOGLO1("<<<CVCXTestCommon::PrintIaps");
       
   499     }
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // CIptvTestVerifyData::CreateVerifyData
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 EXPORT_C TInt CVCXTestCommon::CreateVerifyData(TDesC& aVerifyId, TBool aAppend)
       
   506     {
       
   507     VCXLOGLO2(">>>CVCXTestCommon::CreateVerifyData: %S", &aVerifyId);
       
   508     TInt result = KErrNone;
       
   509     TRAPD(err, result = iIptvVerifyData->CreateVerifyDataL(aVerifyId, aAppend));
       
   510     if(err != KErrNone)
       
   511         {
       
   512         VCXLOGLO2("CIptvVerifyData::CreateVerifyDataL caused a leave. %d", err);
       
   513         result = err;
       
   514         }
       
   515     VCXLOGLO1("<<<CVCXTestCommon::CreateVerifyData");
       
   516     return result;
       
   517     }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CIptvTestVerifyData::WriteVerifyData
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 EXPORT_C TInt CVCXTestCommon::WriteVerifyData(TDesC& aVerifyId, TDesC& aVerifyData)
       
   524     {
       
   525     //VCXLOGLO1(">>>CVCXTestCommon::WriteVerifyData");
       
   526     TInt result = KErrNone;
       
   527     TRAPD(err, result = iIptvVerifyData->WriteVerifyDataL(aVerifyId, aVerifyData));
       
   528     if(err != KErrNone)
       
   529         {
       
   530         VCXLOGLO2("CIptvVerifyData::WriteVerifyDataL caused a leave. %d", err);
       
   531         result = err;
       
   532         }
       
   533     //VCXLOGLO1("<<<CVCXTestCommon::WriteVerifyData");
       
   534     return result;
       
   535     }
       
   536 
       
   537 // -----------------------------------------------------------------------------
       
   538 // CIptvTestVerifyData::WriteVerifyData
       
   539 // -----------------------------------------------------------------------------
       
   540 //
       
   541 EXPORT_C TInt CVCXTestCommon::WriteVerifyData(TDesC& aVerifyId, TRefByValue<const TDesC> aFmt, ... )
       
   542     {
       
   543     //VCXLOGLO1(">>>CVCXTestCommon::WriteVerifyData(formatted)");
       
   544 
       
   545     VA_LIST argptr; //pointer to argument list
       
   546     VA_START( argptr, aFmt );
       
   547 
       
   548     HBufC* str;
       
   549     str = HBufC::NewLC(1024*3);
       
   550 
       
   551     //TBuf<512*3> str;
       
   552     //TBuf<512> format(_L("TESTI: %d, %S"));
       
   553 
       
   554     str->Des().FormatList(aFmt, argptr);
       
   555 
       
   556     TInt result = KErrNone;
       
   557     TRAPD(err, result = iIptvVerifyData->WriteVerifyDataL(aVerifyId, *str));
       
   558 
       
   559     CleanupStack::PopAndDestroy(str);
       
   560 
       
   561     if(err != KErrNone)
       
   562         {
       
   563         VCXLOGLO2("CIptvVerifyData::WriteVerifyDataL caused a leave. %d", err);
       
   564         result = err;
       
   565         }
       
   566 
       
   567     //VCXLOGLO1("<<<CVCXTestCommon::WriteVerifyData(formatted)");
       
   568     return result;
       
   569     }
       
   570 
       
   571 // -----------------------------------------------------------------------------
       
   572 // CIptvTestVerifyData::VerifyData
       
   573 // -----------------------------------------------------------------------------
       
   574 //
       
   575 EXPORT_C TInt CVCXTestCommon::VerifyData(TDesC& aVerifyId, CIptvTestVerifyData::TVerifyResult& aVerifyResult)
       
   576     {
       
   577     VCXLOGLO1(">>>CVCXTestCommon::VerifyData");
       
   578     TInt result = KErrNone;
       
   579     TRAPD(err, result = iIptvVerifyData->VerifyDataL(aVerifyId, aVerifyResult));
       
   580     if(err != KErrNone)
       
   581         {
       
   582         VCXLOGLO2("CIptvVerifyData::VerifyDataL caused a leave. %d", err);
       
   583         result = err;
       
   584         }
       
   585     VCXLOGLO1("<<<CVCXTestCommon::VerifyData");
       
   586     return result;
       
   587     }
       
   588 
       
   589 // -----------------------------------------------------------------------------
       
   590 // CIptvTestVerifyData::EnableVerifyTimestamps
       
   591 // -----------------------------------------------------------------------------
       
   592 //
       
   593 EXPORT_C void CVCXTestCommon::EnableVerifyTimestamps( TBool aUseTimestamps )
       
   594     {
       
   595     VCXLOGLO1(">>>CVCXTestCommon::EnableVerifyTimestamps");
       
   596     iIptvVerifyData->EnableTimestamps( aUseTimestamps );
       
   597     VCXLOGLO1("<<<CVCXTestCommon::EnableVerifyTimestamps");
       
   598     }
       
   599    
       
   600 // -----------------------------------------------------------------------------
       
   601 // CVCXTestCommon::ParseIntFromString
       
   602 // -----------------------------------------------------------------------------
       
   603 EXPORT_C TInt CVCXTestCommon::ParseIntFromString(TInt& aInt, TDesC& aString)
       
   604     {
       
   605     VCXLOGLO1(">>>CVCXTestCommon::ParseIntFromString");
       
   606 
       
   607     TLex lex(aString);
       
   608     TInt err = lex.Val(aInt);
       
   609 
       
   610     VCXLOGLO1("<<<CVCXTestCommon::ParseIntFromString");
       
   611     return err;
       
   612     }
       
   613     
       
   614 // -----------------------------------------------------------------------------
       
   615 // CVCXTestCommon::CreateBadIapL
       
   616 // Creates a not working, crappy iap with given name.
       
   617 // Use with caution, because there is no easy way of removing created iaps
       
   618 //
       
   619 // @param aName name of the iap to be created
       
   620 // @return iapId new iap's id.
       
   621 // -----------------------------------------------------------------------------
       
   622 //
       
   623 EXPORT_C TUint32 CVCXTestCommon::CreateBadIapL(TDesC& aName)
       
   624     {
       
   625     VCXLOGLO1(">>>CVCXTestCommon::CreateBadIapL");
       
   626     CCommsDatabase* cdb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
   627     CleanupStack::PushL( cdb );
       
   628 
       
   629     TBuf16<40> name;
       
   630     name.Copy( aName );
       
   631 
       
   632     TUint32 iapId( 0 );
       
   633     TUint32 iapServiceId( 1 );
       
   634     TUint32 id( 2 );
       
   635     TUint32 iapNetworkId( 3 );
       
   636     TUint32 weighting( 4 );
       
   637     TUint32 loc( 5 );
       
   638 
       
   639     User::LeaveIfError( cdb->BeginTransaction() );
       
   640 
       
   641     CCommsDbTableView* iapTable = cdb->OpenTableLC( TPtrC( IAP ) );
       
   642 
       
   643     User::LeaveIfError( iapTable->InsertRecord( iapId ) );
       
   644 
       
   645     iapTable->WriteTextL( TPtrC( COMMDB_NAME ), name );
       
   646     iapTable->WriteUintL( TPtrC( IAP_SERVICE ), iapServiceId );
       
   647     iapTable->WriteTextL( TPtrC( IAP_SERVICE_TYPE ), TPtrC( LAN_SERVICE ) );
       
   648     iapTable->WriteTextL( TPtrC( IAP_BEARER_TYPE ), TPtrC( LAN_BEARER ) );
       
   649     iapTable->WriteUintL( TPtrC( IAP_BEARER ), id );
       
   650     iapTable->WriteUintL( TPtrC( IAP_NETWORK ), iapNetworkId );
       
   651     iapTable->WriteUintL( TPtrC( IAP_NETWORK_WEIGHTING ), weighting );
       
   652     iapTable->WriteUintL( TPtrC( IAP_LOCATION ), loc );
       
   653 
       
   654     User::LeaveIfError( iapTable->PutRecordChanges( EFalse, EFalse ) );
       
   655 
       
   656     CleanupStack::PopAndDestroy( iapTable );
       
   657 
       
   658     User::LeaveIfError( cdb->CommitTransaction() );
       
   659 
       
   660     CleanupStack::PopAndDestroy( cdb );
       
   661     VCXLOGLO1("<<<CVCXTestCommon::CreateBadIapL");
       
   662     return iapId;
       
   663     }
       
   664 
       
   665 // -----------------------------------------------------------------------------
       
   666 // CVCXTestCommon::AdvanceSystemTimeSeconds
       
   667 // -----------------------------------------------------------------------------
       
   668 //
       
   669 EXPORT_C TInt CVCXTestCommon::AdvanceSystemTimeSeconds( TInt aCount )
       
   670 	{
       
   671 	VCXLOGLO1(">>>CVCXTestCommon::AdvanceSystemTimeSeconds");
       
   672 
       
   673     TTime now;
       
   674     now.HomeTime();
       
   675 
       
   676     TTimeIntervalSeconds second(1*aCount);
       
   677     now += second;
       
   678 
       
   679     TInt err = CVCXTestCommon::SetSystemTime(now);
       
   680 
       
   681 	VCXLOGLO1("<<<CVCXTestCommon::AdvanceSystemTimeSeconds");
       
   682 
       
   683 	return err;
       
   684 	}
       
   685 
       
   686 // -----------------------------------------------------------------------------
       
   687 // CVCXTestCommon::AdvanceSystemTimeMinutes
       
   688 // -----------------------------------------------------------------------------
       
   689 //
       
   690 EXPORT_C TInt CVCXTestCommon::AdvanceSystemTimeMinutes( TInt aCount )
       
   691     {
       
   692     VCXLOGLO1(">>>CVCXTestCommon::AdvanceSystemTimeMinutes");
       
   693 
       
   694     TTime now;
       
   695     now.HomeTime();
       
   696 
       
   697     TTimeIntervalSeconds minute(1*60*aCount);
       
   698     now += minute;
       
   699 
       
   700     TInt err = CVCXTestCommon::SetSystemTime(now);
       
   701 
       
   702     VCXLOGLO1("<<<CVCXTestCommon::AdvanceSystemTimeMinutes");
       
   703 
       
   704     return err;
       
   705     }
       
   706 
       
   707 // -----------------------------------------------------------------------------
       
   708 // CVCXTestCommon::AdvanceSystemTimeHours
       
   709 // -----------------------------------------------------------------------------
       
   710 //
       
   711 EXPORT_C TInt CVCXTestCommon::AdvanceSystemTimeHours( TInt aCount )
       
   712     {
       
   713     VCXLOGLO1(">>>CVCXTestCommon::AdvanceSystemTimeHours");
       
   714 
       
   715     TTime now;
       
   716     now.HomeTime();
       
   717 
       
   718     TTimeIntervalSeconds hour(1*60*60*aCount);
       
   719     now += hour;
       
   720 
       
   721     TInt err = CVCXTestCommon::SetSystemTime(now);
       
   722 
       
   723     VCXLOGLO1("<<<CVCXTestCommon::AdvanceSystemTimeHours");
       
   724     return err;
       
   725     }
       
   726 
       
   727 // -----------------------------------------------------------------------------
       
   728 // CVCXTestCommon::SetSystemTime()
       
   729 // -----------------------------------------------------------------------------
       
   730 //
       
   731 EXPORT_C TInt CVCXTestCommon::SetSystemTime(TTime aTime)
       
   732 	{
       
   733 	VCXLOGLO1(">>>CVCXTestCommon::SetSystemTime");
       
   734 
       
   735     TTime noDST(aTime);
       
   736     RTz tz;
       
   737     TInt err = tz.Connect();
       
   738     if(err != KErrNone)
       
   739     	{
       
   740     	VCXLOGLO2("RTz::Connect failed: %d", err);
       
   741     	VCXLOGLO1("<<<CVCXTestCommon::SetSystemTime");
       
   742     	return err;
       
   743     	}
       
   744     CleanupClosePushL(tz);
       
   745     err = tz.SetHomeTime(noDST);
       
   746     if(err != KErrNone)
       
   747     	{
       
   748     	VCXLOGLO2("RTz::SetHomeTime failed: %d", err);
       
   749     	VCXLOGLO1("<<<CVCXTestCommon::SetSystemTime");
       
   750     	CleanupStack::PopAndDestroy(&tz);
       
   751     	return err;
       
   752     	}
       
   753 
       
   754 	CleanupStack::PopAndDestroy(&tz);
       
   755 
       
   756 	VCXLOGLO1("<<<CVCXTestCommon::SetSystemTime");
       
   757 
       
   758 	return err;
       
   759 	}
       
   760 
       
   761 // -----------------------------------------------------------------------------
       
   762 // CVCXTestCommon::SetTimeZone()
       
   763 // -----------------------------------------------------------------------------
       
   764 //
       
   765 EXPORT_C TInt CVCXTestCommon::SetTimeZone(TDesC& aTimeZone)
       
   766 	{
       
   767 	VCXLOGLO1(">>>CVCXTestCommon::SetTimeZone");
       
   768 
       
   769     RTz tz;
       
   770     TInt err = tz.Connect();
       
   771     if(err != KErrNone)
       
   772     	{
       
   773     	VCXLOGLO2("RTz::Connect failed: %d", err);
       
   774     	VCXLOGLO1("<<<CVCXTestCommon::SetTimeZone");
       
   775     	return err;
       
   776     	}
       
   777     CleanupClosePushL(tz);
       
   778 
       
   779     TBuf8<256> timezone;
       
   780     timezone.Copy( aTimeZone ); // Conversion
       
   781 
       
   782     CTzId* tzId = CTzId::NewL( timezone );
       
   783     CleanupStack::PushL(tzId);
       
   784 
       
   785     TRAP(err, tz.SetTimeZoneL( *tzId ) );
       
   786 	CleanupStack::PopAndDestroy(tzId);
       
   787 	CleanupStack::PopAndDestroy(&tz);
       
   788 
       
   789     if(err != KErrNone)
       
   790     	{
       
   791     	VCXLOGLO2("RTz::SetTimeZone failed: %d", err);
       
   792     	VCXLOGLO1("<<<CVCXTestCommon::SetTimeZone");
       
   793     	return err;
       
   794     	}
       
   795 
       
   796 	VCXLOGLO1("<<<CVCXTestCommon::SetTimeZone");
       
   797 
       
   798 	return err;
       
   799 	}
       
   800 
       
   801 // -----------------------------------------------------------------------------
       
   802 // CVCXTestCommon::CreateVideoFileL()
       
   803 //
       
   804 // Creates a video file to file system.
       
   805 // -----------------------------------------------------------------------------
       
   806 //
       
   807 EXPORT_C void CVCXTestCommon::CreateVideoFileL( CIptvTestVideoCreator::TIptvTestVideoType aVideoType, TDesC& aFileName, TInt aSize )
       
   808     {
       
   809     VCXLOGLO1(">>>CVCXTestCommon::CreateVideoFileL");
       
   810     iVideoCreator->CreateVideoL( aVideoType, aFileName, aSize );
       
   811     VCXLOGLO1("<<<CVCXTestCommon::CreateVideoFileL");
       
   812     }
       
   813 
       
   814 // -----------------------------------------------------------------------------
       
   815 // CVCXTestCommon::CreateVideoFilesL()
       
   816 // -----------------------------------------------------------------------------
       
   817 //
       
   818 EXPORT_C void CVCXTestCommon::CreateVideoFilesL( CIptvTestVideoCreator::TIptvTestVideoType aVideoType, TDesC& aFileName, TInt aCount, RPointerArray<HBufC>& aFileArray )
       
   819     {
       
   820     VCXLOGLO1(">>>CVCXTestCommon::CreateVideoFilesL");
       
   821     iVideoCreator->CreateVideosL( aVideoType, aFileName, aCount, aFileArray );
       
   822     VCXLOGLO1("<<<CVCXTestCommon::CreateVideoFilesL");
       
   823     }
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CVCXTestCommon::SetDriveFreeSpaceL()
       
   827 // -----------------------------------------------------------------------------
       
   828 //
       
   829 EXPORT_C void CVCXTestCommon::SetDriveFreeSpaceL( TInt aDriveNumber, TUint aDesiredFreeSpace )
       
   830     {
       
   831     VCXLOGLO1(">>>CVCXTestCommon::SetDriveFreeSpaceL");
       
   832 
       
   833     const TInt KIptvTest1KB = 1024;
       
   834     const TInt KIptvTest1MB = KIptvTest1KB*KIptvTest1KB;
       
   835 
       
   836 #ifdef  __WINSCW__
       
   837     if(aDriveNumber == EDriveC)
       
   838         {
       
   839         VCXLOGLO1("CVCXTestCommon:: ABORT! No C drive fill in emulator.");
       
   840         User::Leave( KErrAbort );
       
   841         }
       
   842 #endif
       
   843 
       
   844     TChar driveLetter;
       
   845     User::LeaveIfError( RFs::DriveToChar( aDriveNumber, driveLetter ) );
       
   846 
       
   847     TBuf<255> path;
       
   848     path.Append( driveLetter );
       
   849     path.Append( _L(":\\data\\temp") );
       
   850     path.Append( KDoubleBacklash );
       
   851 
       
   852     // First check that if there's free space to fill.
       
   853 
       
   854     TInt64 spaceToReserve = 0;
       
   855     CalculateSpaceToReserveL(iFs, aDriveNumber, aDesiredFreeSpace, spaceToReserve);
       
   856 
       
   857     if( spaceToReserve == 0 )
       
   858         {
       
   859         VCXLOGLO1("<<<CVCXTestCommon::SetDriveFreeSpaceL");
       
   860         return;
       
   861         }
       
   862 
       
   863     // No space, try freeing by deleting existing dummy files.
       
   864     if( spaceToReserve < 0 )
       
   865         {
       
   866         VCXLOGLO1("CVCXTestCommon:: Trying to free some space.");
       
   867 
       
   868         for( TInt i=50; i>0; i-- )
       
   869             {
       
   870             TBuf<256> filePath;
       
   871             filePath.Zero();
       
   872             filePath.Append( path );
       
   873             filePath.AppendFormat( KDummyfileFormat, i );
       
   874             if( BaflUtils::FileExists( iFs, filePath ) )
       
   875                 {
       
   876                 VCXLOGLO2("CVCXTestCommon:: Deleting %S.", &filePath);
       
   877                 iFs.Delete( filePath );
       
   878                 CalculateSpaceToReserveL(iFs, aDriveNumber, aDesiredFreeSpace, spaceToReserve);
       
   879 
       
   880                 // Is there's enough free space now.
       
   881                 if( spaceToReserve > 0 )
       
   882                     {
       
   883                     break;
       
   884                     }
       
   885                 }
       
   886             }
       
   887 
       
   888         // Recheck free space.
       
   889         if( spaceToReserve < 0 )
       
   890             {
       
   891             VCXLOGLO1("CVCXTestCommon:: Error! There's already less than wanted space!");
       
   892             User::Leave( KErrAbort );
       
   893             }
       
   894         }
       
   895 
       
   896     BaflUtils::EnsurePathExistsL(iFs, path);
       
   897 
       
   898     // Start creating files of 256 MB size.
       
   899     TInt64 dummyFileSize = 256 * KIptvTest1MB;
       
   900 
       
   901     TInt count = 0;
       
   902     while( ETrue )
       
   903         {
       
   904         // Check that there's still enough free space for the dummyfile
       
   905         CalculateSpaceToReserveL( iFs, aDriveNumber, aDesiredFreeSpace, spaceToReserve );
       
   906 
       
   907         if( spaceToReserve <= 0 )
       
   908             {
       
   909             VCXLOGLO1("CVCXTestCommon:: Nothing to reserve anymore.");
       
   910             break;
       
   911             }
       
   912 
       
   913         // Fill all at once if less than 1MB to go.
       
   914         if( spaceToReserve < KIptvTest1MB )
       
   915             {
       
   916             dummyFileSize = spaceToReserve;
       
   917             }
       
   918 
       
   919         // Not enough space for dummy file, find smaller size.
       
   920         while( dummyFileSize > spaceToReserve )
       
   921             {
       
   922             dummyFileSize /= 2;
       
   923             }
       
   924 
       
   925         // Find free filename.
       
   926         TBuf<256> filePath;
       
   927         do
       
   928             {
       
   929             filePath.Zero();
       
   930             filePath.Append( path );
       
   931             count++;
       
   932             filePath.AppendFormat(KDummyfileFormat, count);
       
   933             }
       
   934         while ( BaflUtils::FileExists( iFs, filePath ) );
       
   935 
       
   936         VCXLOGLO3("Creating %Ld b file to '%S'", dummyFileSize, &filePath);
       
   937 
       
   938         // Create the file.
       
   939         RFile file;
       
   940         TInt err = file.Replace(iFs, filePath, EFileWrite);
       
   941         if(err != KErrNone)
       
   942             {
       
   943             VCXLOGLO2("file.Replace fail: %d", err);
       
   944             }
       
   945         User::LeaveIfError(err);
       
   946         err = file.SetSize( dummyFileSize );
       
   947         if(err != KErrNone)
       
   948             {
       
   949             VCXLOGLO2("file.SetSize fail: %d", err);
       
   950             }
       
   951         User::LeaveIfError(err);
       
   952         file.Close();
       
   953 
       
   954         TVolumeInfo volumeInfo;
       
   955         User::LeaveIfError(iFs.Volume(volumeInfo, aDriveNumber));
       
   956         VCXLOGLO2("Free space after: %Ld b", volumeInfo.iFree);
       
   957         }
       
   958 
       
   959     VCXLOGLO1("<<<CVCXTestCommon::SetDriveFreeSpaceL");
       
   960     }
       
   961 
       
   962 // -----------------------------------------------------------------------------
       
   963 // CVCXTestCommon::CalculateSpaceToReserve
       
   964 // -----------------------------------------------------------------------------
       
   965 //
       
   966 void CVCXTestCommon::CalculateSpaceToReserveL( RFs &aFs, TInt aDriveNumber, TInt aDesiredSpace, TInt64& aSpaceToReserve)
       
   967     {
       
   968     TVolumeInfo volumeInfo;
       
   969     User::LeaveIfError(aFs.Volume(volumeInfo, aDriveNumber));
       
   970 
       
   971     TInt64 driveSize       = volumeInfo.iSize;
       
   972     TInt64 reservedSpace   = 0;
       
   973     if(aDriveNumber == EDriveC)
       
   974         {
       
   975         reservedSpace = 1024*500; // Leave 500KB extra free to C drive
       
   976         }
       
   977 
       
   978     TInt64 driveFreeSpace  = volumeInfo.iFree;
       
   979     TInt64 usableSpace     = driveFreeSpace - reservedSpace;
       
   980     aSpaceToReserve        = usableSpace - aDesiredSpace;
       
   981 
       
   982     VCXLOGLO2("CVCXTestCommon: driveSize      = %Ld", driveSize);
       
   983     VCXLOGLO2("CVCXTestCommon: reservedSpace  = %Ld", reservedSpace);
       
   984     VCXLOGLO2("CVCXTestCommon: freeSpace      = %Ld", driveFreeSpace);
       
   985     VCXLOGLO2("CVCXTestCommon: usableSpace    = %Ld", usableSpace);
       
   986     VCXLOGLO2("CVCXTestCommon: desiredSpace   = %d", aDesiredSpace);
       
   987     VCXLOGLO2("CVCXTestCommon: spaceToReserve = %Ld", aSpaceToReserve);
       
   988     }
       
   989 
       
   990 // -----------------------------------------------------------------------------
       
   991 // CVCXTestCommon::DeleteDummyFilesL()
       
   992 // -----------------------------------------------------------------------------
       
   993 //
       
   994 EXPORT_C void CVCXTestCommon::DeleteDummyFilesL( TInt aDriveNumber )
       
   995     {
       
   996     VCXLOGLO1(">>>CVCXTestCommon::DeleteDummyFilesL");
       
   997 
       
   998     CFileMan* fileMan = CFileMan::NewL(iFs);
       
   999     CleanupStack::PushL(fileMan);
       
  1000 
       
  1001     TBuf<3> driveLetter;
       
  1002     TChar driveChar;
       
  1003     RFs::DriveToChar( aDriveNumber, driveChar );
       
  1004     driveLetter.Append(driveChar);
       
  1005 
       
  1006     TBuf<255>path;
       
  1007 
       
  1008     path.Format( KDummyfilePathFormat, &driveLetter );
       
  1009     path.Append(KDoubleBacklash);
       
  1010     fileMan->RmDir(path);
       
  1011 
       
  1012     CleanupStack::PopAndDestroy(fileMan);
       
  1013 
       
  1014     VCXLOGLO1("<<<CVCXTestCommon::DeleteDummyFilesL");
       
  1015     }
       
  1016 
       
  1017 // -----------------------------------------------------------------------------
       
  1018 // CVCXTestCommon::EnsureFileIsNotInUse()
       
  1019 // -----------------------------------------------------------------------------
       
  1020 //
       
  1021 EXPORT_C TInt CVCXTestCommon::EnsureFileIsNotInUse( const TPtrC& aFileName )
       
  1022     {
       
  1023     TInt error( KErrNone );
       
  1024     RFile file;
       
  1025     // MDS or someone else could have the file in exclusive use. Try 6 times in 10 second intervals.
       
  1026     for(TInt retry = 0; retry < 6; retry++)
       
  1027         {
       
  1028         error = file.Open(iFs, aFileName, EFileShareExclusive);
       
  1029         if( error == KErrInUse )
       
  1030             {
       
  1031             User::After( 1000000 * 10 );
       
  1032             }
       
  1033         else
       
  1034             {
       
  1035             break;
       
  1036             }
       
  1037         }
       
  1038 
       
  1039     file.Close();
       
  1040     VCXLOGLO2("CVCXTestCommon::EnsureFileIsNotInUse: %d", error);
       
  1041     return error;
       
  1042     }
       
  1043 
       
  1044 
       
  1045 // -----------------------------------------------------------------------------
       
  1046 // CVCXTestCommon::PrintDriveInfo()
       
  1047 // -----------------------------------------------------------------------------
       
  1048 //
       
  1049 void CVCXTestCommon::PrintDriveInfo( const TPtrC& aDriveLetter )
       
  1050     {
       
  1051     TInt driveNumber(-1);
       
  1052     TInt64 driveSize(0);
       
  1053     TInt64 driveFreeSpace(0);
       
  1054 
       
  1055     if( aDriveLetter.Length() > 0 && iFs.CharToDrive( aDriveLetter[0], driveNumber ) == KErrNone )
       
  1056         {
       
  1057         TVolumeInfo volumeInfo;
       
  1058         if( iFs.Volume(volumeInfo, driveNumber) == KErrNone )
       
  1059             {
       
  1060             driveSize       = volumeInfo.iSize / 1024 / 1024;
       
  1061             driveFreeSpace  = volumeInfo.iFree / 1024 / 1024;
       
  1062             VCXLOGLO2("CVCXTestCommon:: drive: %S", &aDriveLetter );
       
  1063             VCXLOGLO2("CVCXTestCommon::  - size: %d MB", driveSize);
       
  1064             VCXLOGLO2("CVCXTestCommon::  - free: %d MB", driveFreeSpace);
       
  1065             }
       
  1066         }
       
  1067     }
       
  1068 
       
  1069 // -----------------------------------------------------------------------------
       
  1070 // CVCXTestCommon::ListDir
       
  1071 // -----------------------------------------------------------------------------
       
  1072 //
       
  1073 EXPORT_C TInt CVCXTestCommon::ListDir( const TDesC& aDir, TInt aLevel )
       
  1074     {
       
  1075     CDir* fileList = NULL;
       
  1076     CDir* dirList = NULL;
       
  1077 
       
  1078     if( aLevel == 0 )
       
  1079         {
       
  1080         VCXLOGLO2("CVCXTestCommon:: Listing directory %S", &aDir);
       
  1081         }
       
  1082 
       
  1083     TInt err( KErrNone );
       
  1084     err = iFs.GetDir( aDir, KEntryAttMatchExclusive | KEntryAttDir, ESortByName, dirList );
       
  1085     if( err == KErrNone )
       
  1086         {
       
  1087         err = iFs.GetDir( aDir, KEntryAttMatchExclude | KEntryAttDir, ESortByName, fileList );
       
  1088         }
       
  1089 
       
  1090     CleanupStack::PushL( dirList );
       
  1091     CleanupStack::PushL( fileList );
       
  1092 
       
  1093     HBufC* pre = HBufC::NewL( 256 );
       
  1094     CleanupStack::PushL( pre );
       
  1095 
       
  1096     for( TInt i=0; i<aLevel; i++ )
       
  1097         {
       
  1098         pre->Des().Append( _L(" ") );
       
  1099         }
       
  1100 
       
  1101     if( err == KErrNone )
       
  1102         {
       
  1103         HBufC* fileName = HBufC::NewL( 256 );
       
  1104         CleanupStack::PushL( fileName );
       
  1105 
       
  1106         if( dirList )
       
  1107         for ( TInt file = 0; file < dirList->Count(); file++ )
       
  1108             {
       
  1109             fileName->Des().Zero();
       
  1110             fileName->Des().Append( aDir );
       
  1111             fileName->Des().Append( (*dirList)[file].iName );
       
  1112             VCXLOGLO3("%S (d) %S", pre, fileName);
       
  1113             fileName->Des().Append( _L("\\") );
       
  1114             fileName->Des().LowerCase();
       
  1115 #if 0
       
  1116             ListDir( *fileName, aLevel+1 );
       
  1117 #else
       
  1118             if( fileName->Des().Find( _L(":\\private\\") ) < 0 &&
       
  1119                 fileName->Des().Find( _L(":\\resource\\") ) < 0 &&
       
  1120                 fileName->Des().Find( _L(":\\sys\\") ) < 0 &&
       
  1121                 fileName->Des().Find( _L(":\\testframework\\") ) < 0 &&
       
  1122                 fileName->Des().Find( _L(":\\nokia\\") ) < 0 &&
       
  1123                 fileName->Des().Find( _L(":\\system\\") ) < 0 )
       
  1124                 {
       
  1125                 ListDir( fileName->Des(), aLevel+1 );
       
  1126                 }
       
  1127 #endif
       
  1128             }
       
  1129 
       
  1130         TUint32 totalSize(0);
       
  1131         if( fileList )
       
  1132         for ( TInt file = 0; file < fileList->Count(); file++ )
       
  1133             {
       
  1134             fileName->Des().Zero();
       
  1135             fileName->Des().Append( aDir );
       
  1136             fileName->Des().Append( (*fileList)[file].iName );
       
  1137 
       
  1138             RFile rf;
       
  1139             if( rf.Open( iFs, *fileName, EFileRead|EFileShareAny ) == KErrNone )
       
  1140                 {
       
  1141                 TInt size(0);
       
  1142                 if( rf.Size( size ) == KErrNone )
       
  1143                     {
       
  1144                     totalSize += size;
       
  1145                     VCXLOGLO4("%S (f) %S - %d KB", pre, fileName, size/1024 );
       
  1146                     }
       
  1147                 rf.Close();
       
  1148                 }
       
  1149             else
       
  1150                 {
       
  1151                 VCXLOGLO3("%S (f) %S", pre, fileName);
       
  1152                 }
       
  1153 
       
  1154             }
       
  1155             VCXLOGLO3("%S Total size: %d KB", pre, totalSize/1024 );
       
  1156             CleanupStack::PopAndDestroy( fileName );
       
  1157         }
       
  1158 
       
  1159     CleanupStack::PopAndDestroy( pre );
       
  1160     CleanupStack::PopAndDestroy( fileList );
       
  1161     CleanupStack::PopAndDestroy( dirList );
       
  1162 
       
  1163     if( aLevel == 0 )
       
  1164         {
       
  1165         VCXLOGLO1("CVCXTestCommon:: Directory listed.");
       
  1166         }
       
  1167 
       
  1168     return err;
       
  1169     }
       
  1170 
       
  1171 // -----------------------------------------------------------------------------
       
  1172 // CVCXTestCommon::GetPSProperty
       
  1173 // -----------------------------------------------------------------------------
       
  1174 //
       
  1175 EXPORT_C TInt CVCXTestCommon::GetPSProperty( const TUid aCategory, const TUint aKey, TInt& aValue )
       
  1176     {
       
  1177     VCXLOGLO2("CVCXTestCommon:: RProperty::Get key %d.", aKey);
       
  1178     TInt err = RProperty::Get( aCategory, aKey, aValue );
       
  1179     if( err != KErrNone )
       
  1180         {
       
  1181         VCXLOGLO2("CVCXTestCommon:: RProperty::Get int returned error: %d.", err);
       
  1182         }
       
  1183     return err;
       
  1184     }
       
  1185 
       
  1186 
       
  1187 // -----------------------------------------------------------------------------
       
  1188 // CVCXTestCommon::SetPSProperty
       
  1189 // -----------------------------------------------------------------------------
       
  1190 //
       
  1191 EXPORT_C TInt CVCXTestCommon::SetPSProperty( const TUid aCategory, const TUint aKey, const TInt aValue )
       
  1192     {
       
  1193     VCXLOGLO2("CVCXTestCommon:: RProperty::Set key %d.", aKey);
       
  1194     TInt err = RProperty::Set( aCategory, aKey, aValue );
       
  1195     if( err != KErrNone )
       
  1196         {
       
  1197         VCXLOGLO2("CVCXTestCommon:: RProperty::Set int returned error: %d.", err);
       
  1198         }
       
  1199     return err;
       
  1200     }
       
  1201 
       
  1202 // -----------------------------------------------------------------------------
       
  1203 // CVCXTestCommon::GetPSProperty
       
  1204 // -----------------------------------------------------------------------------
       
  1205 //
       
  1206 EXPORT_C TInt CVCXTestCommon::GetPSProperty( const TUid aCategory, const TUint aKey, TDes& aValue )
       
  1207     {
       
  1208     VCXLOGLO2("CVCXTestCommon:: RProperty::Get key %d.", aKey);
       
  1209     TInt err = RProperty::Get( aCategory, aKey, aValue );
       
  1210     if( err != KErrNone )
       
  1211         {
       
  1212         VCXLOGLO2("CVCXTestCommon:: RProperty::Get desc returned error: %d.", err);
       
  1213         }
       
  1214     return err;
       
  1215     }
       
  1216 
       
  1217 
       
  1218 // -----------------------------------------------------------------------------
       
  1219 // CVCXTestCommon::SetPSProperty
       
  1220 // -----------------------------------------------------------------------------
       
  1221 //
       
  1222 EXPORT_C TInt CVCXTestCommon::SetPSProperty( const TUid aCategory, const TUint aKey, const TDesC& aValue )
       
  1223     {
       
  1224     VCXLOGLO2("CVCXTestCommon:: RProperty::Set key %d.", aKey);
       
  1225     TInt err = RProperty::Set( aCategory, aKey, aValue );
       
  1226     if( err != KErrNone )
       
  1227         {
       
  1228         VCXLOGLO2("CVCXTestCommon:: RProperty::Set desc returned error: %d.", err);
       
  1229         }
       
  1230     return err;
       
  1231     }
       
  1232 
       
  1233 // -----------------------------------------------------------------------------
       
  1234 // CVCXTestCommon::ListFilesProcessesAndThreadsL
       
  1235 // -----------------------------------------------------------------------------
       
  1236 //
       
  1237 EXPORT_C void CVCXTestCommon::ListFilesProcessesAndThreadsL( RFs& aFs )
       
  1238     {
       
  1239     RArray<TInt> fileThreadIds;
       
  1240     CleanupClosePushL( fileThreadIds );
       
  1241     
       
  1242     RPointerArray<HBufC> fileNames;
       
  1243     CleanupResetAndDestroyPushL( fileNames );
       
  1244 
       
  1245     // Get list of open files.
       
  1246     CFileList* fileList = 0;
       
  1247     TOpenFileScan fileScan( aFs );
       
  1248     fileScan.NextL( fileList );
       
  1249     
       
  1250     CleanupStack::PushL( fileList );
       
  1251     
       
  1252     while( fileList )
       
  1253         {
       
  1254         for (TInt i = 0; i < fileList->Count(); ++i)
       
  1255             {
       
  1256             fileNames.Append( (*fileList)[i].iName.AllocL() );
       
  1257             fileThreadIds.Append( fileScan.ThreadId() );
       
  1258             //VCXLOGLO4("File: %S Size: %d Thread Id: %d", &(*fileList)[i].iName, (*fileList)[i].iSize, fileScan.ThreadId() );
       
  1259             }
       
  1260         CleanupStack::PopAndDestroy( fileList );
       
  1261         fileScan.NextL( fileList );
       
  1262         CleanupStack::PushL( fileList );
       
  1263         }
       
  1264     
       
  1265     CleanupStack::PopAndDestroy( fileList );
       
  1266     
       
  1267     // Get list of processes and their threads.    
       
  1268     TFindProcess findProcess;
       
  1269     TFullName processName;
       
  1270     
       
  1271     TInt err( KErrNone );
       
  1272     
       
  1273     // List processes.
       
  1274     while( findProcess.Next( processName ) == KErrNone )
       
  1275         {
       
  1276         RProcess process;
       
  1277         err = process.Open( processName );
       
  1278         if( err != KErrNone ) 
       
  1279             {
       
  1280             continue;            
       
  1281             }
       
  1282         CleanupClosePushL( process );
       
  1283 
       
  1284         TProcessId pid;
       
  1285         pid = process.Id();
       
  1286         TInt id = pid.Id();
       
  1287         VCXLOGLO4("Process: %S, ID: %d (%x)", &processName, id, pid.Id() );
       
  1288         
       
  1289         TFindThread findThread;
       
  1290         TFullName threadName;
       
  1291         
       
  1292         // List threads that belong to current process.
       
  1293         while( findThread.Next( threadName ) == KErrNone )
       
  1294             {
       
  1295             RThread thread;
       
  1296             err = thread.Open( threadName );
       
  1297             if( err == KErrNone )
       
  1298                 {
       
  1299                 CleanupClosePushL( thread );
       
  1300                 RProcess threadProcess;
       
  1301                 err = thread.Process( threadProcess ) ;
       
  1302                 if( err == KErrNone )
       
  1303                     {
       
  1304                     CleanupClosePushL( threadProcess );
       
  1305                     if( threadProcess.Id() == process.Id() )
       
  1306                         {
       
  1307                         TThreadId tid;
       
  1308                         tid = thread.Id();
       
  1309                         id = tid.Id();
       
  1310                         VCXLOGLO4(" - Thread: %S, ID: %d (%x)", &threadName, id, tid.Id() );
       
  1311                         
       
  1312                         // And list open files for the thread.
       
  1313                         for( TInt i = 0; i < fileThreadIds.Count(); i++ )
       
  1314                             {
       
  1315                             if( fileThreadIds[i] == tid.Id() )
       
  1316                                 {
       
  1317                                 VCXLOGLO2("   - %S", fileNames[i] );
       
  1318                                 }
       
  1319                             }
       
  1320                         }
       
  1321                     CleanupStack::PopAndDestroy( &threadProcess );
       
  1322                     }
       
  1323                 CleanupStack::PopAndDestroy( &thread );
       
  1324                 }        
       
  1325             }
       
  1326         
       
  1327         VCXLOGLO1("---");
       
  1328         CleanupStack::PopAndDestroy( &process );
       
  1329         }
       
  1330     
       
  1331     CleanupStack::PopAndDestroy( &fileNames );
       
  1332     CleanupStack::PopAndDestroy( &fileThreadIds );
       
  1333     }
       
  1334 
       
  1335 //  End of File