idlehomescreen/widgetmanager/tsrc/wmunittest/src/wmunittest_all.cpp
changeset 1 5315654608de
child 11 ff572dfe6d86
equal deleted inserted replaced
0:f72a12da539e 1:5315654608de
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: list of all test blocks
       
    15 *
       
    16 */
       
    17 
       
    18 //INCLUDE FILES
       
    19 #include <e32svr.h>
       
    20 #include <stdlib.h>
       
    21 #include <stifparser.h>
       
    22 #include <stiftestinterface.h>
       
    23 #include <bautils.h>
       
    24 #include <aknsskininstance.h>
       
    25 #include <swinstapi.h>
       
    26 #include <swinstdefs.h>
       
    27 #include <coemain.h>
       
    28 #include <EIKENV.H> 
       
    29 #include "wmunittest.h"
       
    30 #include "wmresourceloader.h"
       
    31 
       
    32 // CONSTANTS
       
    33 _LIT( KHexPrefix,     "0x" );
       
    34 _LIT8( KWrtMime, "application/x-nokia-widget");
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CWmUnitTest::RunMethodL
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 TInt CWmUnitTest::RunMethodL( 
       
    43     CStifItemParser& aItem ) 
       
    44     {
       
    45     static TStifFunctionInfo const KFunctions[] =
       
    46         {
       
    47         // general test blocks
       
    48         ENTRY( "HeapSet", CWmUnitTest::HeapSetL ),
       
    49         ENTRY( "LogHeap", CWmUnitTest::LogHeapL ),
       
    50         ENTRY( "HeapCheck", CWmUnitTest::HeapCheckL ),
       
    51         ENTRY( "SetMass", CWmUnitTest::SetMassL ),
       
    52         ENTRY( "ErrorPopup", CWmUnitTest::ErrorPopupL ),
       
    53         
       
    54 		// install/uninstall wrt widget for test
       
    55 		ENTRY( "InstallWrtWidget", CWmUnitTest::InstallWrtWidgetL ),
       
    56 		ENTRY( "UninstallWrtWidget", CWmUnitTest::UninstallWrtWidgetL ),
       
    57 
       
    58         // test blocks for the plugin
       
    59         ENTRY( "PluginCreate", CWmUnitTest::PluginCreateL ),
       
    60         ENTRY( "PluginDelete", CWmUnitTest::PluginDeleteL ),
       
    61         ENTRY( "PluginActivate", CWmUnitTest::PluginActivateL ),
       
    62         ENTRY( "PluginDeactivate", CWmUnitTest::PluginDeactivateL ),
       
    63         ENTRY( "PluginWidgetsChanged", CWmUnitTest::PluginWidgetsChangedL ),
       
    64         ENTRY( "ChangeContent", CWmUnitTest::ChangeContentL ),
       
    65 
       
    66         // test blocks for the persistent widget order class
       
    67         ENTRY( "WidgetOrderCreate", CWmUnitTest::WidgetOrderCreateL ),
       
    68         ENTRY( "WidgetOrderDelete", CWmUnitTest::WidgetOrderDeleteL ),
       
    69         ENTRY( "WidgetOrderLoad", CWmUnitTest::WidgetOrderLoadL ),
       
    70         ENTRY( "WidgetOrderSave", CWmUnitTest::WidgetOrderSaveL ),
       
    71         ENTRY( "WidgetOrderCheckIsEmpty", CWmUnitTest::WidgetOrderCheckIsEmptyL ),
       
    72         ENTRY( "WidgetOrderUse", CWmUnitTest::WidgetOrderUseL ),
       
    73         
       
    74         // test blocks for the image converter
       
    75         ENTRY( "ImageConverterCreate", CWmUnitTest::ImageConverterCreateL ),
       
    76         ENTRY( "ImageConverterDelete", CWmUnitTest::ImageConverterDeleteL ),
       
    77         ENTRY( "ImageConverterConvert", CWmUnitTest::ImageConverterConvertL ),
       
    78         ENTRY( "ImageConverterWaitResult", CWmUnitTest::ImageConverterWaitResultL ),
       
    79         ENTRY( "ImageConverterConversionMethod", CWmUnitTest::ImageConverterConversionMethodL ),
       
    80         ENTRY( "CancelConvert", CWmUnitTest::CancelConvertL ),
       
    81         
       
    82         };
       
    83 
       
    84     const TInt count = sizeof( KFunctions ) / 
       
    85                         sizeof( TStifFunctionInfo );
       
    86 
       
    87     return RunInternalL( KFunctions, count, aItem );
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CWmUnitTest::HeapSetL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 TInt CWmUnitTest::HeapSetL( CStifItemParser& /*aItem*/ )
       
    95     {
       
    96     User::Heap().AllocSize( iHeapSize );
       
    97     _RETURN("HeapSetL End", KErrNone);
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CWmUnitTest::LogHeapL
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 TInt CWmUnitTest::LogHeapL( CStifItemParser& aItem )
       
   105     {
       
   106     TPtrC inputStr;
       
   107     aItem.SetParsingType( CStifItemParser::EQuoteStyleParsing );
       
   108     User::LeaveIfError( aItem.GetNextString( inputStr ) );
       
   109 
       
   110     TInt size = 0;
       
   111     User::Heap().AllocSize( size );
       
   112     iLog->Log( _L("Heap usage, %S: %d"), &inputStr, size );
       
   113     _RETURN("LogHeapL End", KErrNone);
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CWmUnitTest::HeapCheckL
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 TInt CWmUnitTest::HeapCheckL( CStifItemParser& /*aItem*/ )
       
   121     {
       
   122     TInt ret = KErrNone;
       
   123     TInt heapSizeAtCheckpoint;
       
   124     User::Heap().AllocSize( heapSizeAtCheckpoint );
       
   125     if ( iHeapSize != heapSizeAtCheckpoint )
       
   126         {
       
   127         //ret = KErrTooBig; <-- not reliable
       
   128         _LOG("Warning: potential memory leak detected!!!");
       
   129         }
       
   130     _RETURN("HeapCheckL End", ret);
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CWmUnitTest::SetMassL
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 TInt CWmUnitTest::SetMassL( CStifItemParser& aItem )
       
   138     {
       
   139     aItem.GetNextInt( iMass );
       
   140     _RETURN("SetMassL End", KErrNone);
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CWmUnitTest::InstallWrtWidgetL
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 TInt CWmUnitTest::InstallWrtWidgetL( CStifItemParser& aItem )
       
   148     {
       
   149 	TInt ret = KErrNone;
       
   150     TPtrC inputStr;
       
   151     aItem.SetParsingType( CStifItemParser::EQuoteStyleParsing );
       
   152     User::LeaveIfError( aItem.GetNextString( inputStr ) );
       
   153     if ( inputStr.Length() == 0 ) User::Leave( KErrArgument );
       
   154 	
       
   155 	// install widget
       
   156     SwiUI::RSWInstSilentLauncher installer;
       
   157     User::LeaveIfError( installer.Connect() );
       
   158     CleanupClosePushL( installer );
       
   159 
       
   160     SwiUI::TInstallReqPckg installReqPckg;
       
   161     SwiUI::TInstallOptions options;
       
   162     TRequestStatus status = KRequestPending;
       
   163     
       
   164     options.iUpgrade = SwiUI::EPolicyAllowed;
       
   165     options.iOptionalItems = SwiUI::EPolicyAllowed;
       
   166     options.iOCSP = SwiUI::EPolicyAllowed;
       
   167     options.iIgnoreOCSPWarnings = SwiUI::EPolicyAllowed;
       
   168     options.iUntrusted = SwiUI::EPolicyAllowed;
       
   169     options.iPackageInfo = SwiUI::EPolicyAllowed;
       
   170     options.iCapabilities = SwiUI::EPolicyAllowed;
       
   171     options.iKillApp = SwiUI::EPolicyAllowed;
       
   172     options.iOverwrite = SwiUI::EPolicyAllowed;
       
   173     options.iDownload = SwiUI::EPolicyAllowed;
       
   174     options.iDrive = 'C';
       
   175     options.iLang = User::Language();
       
   176     options.iUsePhoneLang = ETrue;
       
   177     options.iUpgradeData = SwiUI::EPolicyAllowed;
       
   178     
       
   179     SwiUI::TInstallOptionsPckg optionsPkg( options );
       
   180     installer.SilentInstall( status , inputStr, optionsPkg );
       
   181     User::WaitForRequest( status );
       
   182     ret = status.Int();
       
   183 	CleanupStack::PopAndDestroy( &installer );
       
   184     _RETURN("InstallWrtWidgetL End", ret);
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CWmUnitTest::UninstallWrtWidgetL
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 TInt CWmUnitTest::UninstallWrtWidgetL( CStifItemParser& aItem )
       
   192     {
       
   193     TInt ret = KErrNone;
       
   194 	TPtrC inputStr;
       
   195     aItem.SetParsingType( CStifItemParser::EQuoteStyleParsing );
       
   196     User::LeaveIfError( aItem.GetNextString( inputStr ) );
       
   197     if ( inputStr.Length() == 0 ) User::Leave( KErrArgument );
       
   198 
       
   199 	TUid uid;
       
   200 	TLex lex( inputStr );
       
   201 	lex.SkipSpaceAndMark();
       
   202 	TPtrC mtoken = lex.MarkedToken();
       
   203 	TInt pos = mtoken.FindF( KHexPrefix );
       
   204 	if ( pos == 0 )
       
   205 		{
       
   206 		TLex lex( mtoken.Mid( KHexPrefix().Length() ) );
       
   207 		TUint id = 0;
       
   208 		ret = lex.Val( id, EHex );
       
   209 		uid = TUid::Uid( (TInt)id );
       
   210 		}
       
   211 	else
       
   212 		{
       
   213 		TInt id( 0 );
       
   214 		ret = lex.Val( id );
       
   215 		uid.iUid = id;
       
   216 		}
       
   217 
       
   218 	if ( ret == KErrNone )
       
   219 		{
       
   220 		// Uninstall widget
       
   221 		SwiUI::RSWInstSilentLauncher installer;
       
   222 		User::LeaveIfError( installer.Connect() );
       
   223 		CleanupClosePushL( installer );
       
   224 		
       
   225 		TRequestStatus status = KRequestPending;
       
   226 		SwiUI::TUninstallOptions optionsUninstall;
       
   227 		optionsUninstall.iBreakDependency = SwiUI::EPolicyAllowed;
       
   228 		optionsUninstall.iKillApp = SwiUI::EPolicyAllowed;
       
   229 		SwiUI::TUninstallOptionsPckg uninstallOptionsPkg( optionsUninstall );
       
   230 		
       
   231 		installer.SilentUninstall( status, uid, uninstallOptionsPkg, KWrtMime );
       
   232 		User::WaitForRequest( status );				
       
   233 		CleanupStack::PopAndDestroy( &installer );
       
   234 		}
       
   235 	
       
   236     _RETURN("UninstallWrtWidgetL End", ret);
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CWmUnitTest::ErrorPopup
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 TInt CWmUnitTest::ErrorPopupL( CStifItemParser& /*aItem*/ )
       
   244     {
       
   245     CWmResourceLoader* res = CWmResourceLoader::NewL( *CEikonEnv::Static() );
       
   246     res->ErrorPopup(KErrNone);
       
   247     delete res;
       
   248     _RETURN("ErrorPopupL End", KErrNone);
       
   249     }
       
   250 // End of File