widgetmanager/tsrc/wmunittest/src/wmunittest_all.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     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 
       
    65         // test blocks for the persistent widget order class
       
    66         ENTRY( "WidgetOrderCreate", CWmUnitTest::WidgetOrderCreateL ),
       
    67         ENTRY( "WidgetOrderDelete", CWmUnitTest::WidgetOrderDeleteL ),
       
    68         ENTRY( "WidgetOrderLoad", CWmUnitTest::WidgetOrderLoadL ),
       
    69         ENTRY( "WidgetOrderSave", CWmUnitTest::WidgetOrderSaveL ),
       
    70         ENTRY( "WidgetOrderCheckIsEmpty", CWmUnitTest::WidgetOrderCheckIsEmptyL ),
       
    71         ENTRY( "WidgetOrderUse", CWmUnitTest::WidgetOrderUseL ),
       
    72         
       
    73         // test blocks for the image converter
       
    74         ENTRY( "ImageConverterCreate", CWmUnitTest::ImageConverterCreateL ),
       
    75         ENTRY( "ImageConverterDelete", CWmUnitTest::ImageConverterDeleteL ),
       
    76         ENTRY( "ImageConverterConvert", CWmUnitTest::ImageConverterConvertL ),
       
    77         ENTRY( "ImageConverterWaitResult", CWmUnitTest::ImageConverterWaitResultL ),
       
    78         ENTRY( "ImageConverterConversionMethod", CWmUnitTest::ImageConverterConversionMethodL ),
       
    79         ENTRY( "CancelConvert", CWmUnitTest::CancelConvertL ),
       
    80         
       
    81         };
       
    82 
       
    83     const TInt count = sizeof( KFunctions ) / 
       
    84                         sizeof( TStifFunctionInfo );
       
    85 
       
    86     return RunInternalL( KFunctions, count, aItem );
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CWmUnitTest::HeapSetL
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 TInt CWmUnitTest::HeapSetL( CStifItemParser& /*aItem*/ )
       
    94     {
       
    95     User::Heap().AllocSize( iHeapSize );
       
    96     _RETURN("HeapSetL End", KErrNone);
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CWmUnitTest::LogHeapL
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 TInt CWmUnitTest::LogHeapL( CStifItemParser& aItem )
       
   104     {
       
   105     TPtrC inputStr;
       
   106     aItem.SetParsingType( CStifItemParser::EQuoteStyleParsing );
       
   107     User::LeaveIfError( aItem.GetNextString( inputStr ) );
       
   108 
       
   109     TInt size = 0;
       
   110     User::Heap().AllocSize( size );
       
   111     iLog->Log( _L("Heap usage, %S: %d"), &inputStr, size );
       
   112     _RETURN("LogHeapL End", KErrNone);
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CWmUnitTest::HeapCheckL
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TInt CWmUnitTest::HeapCheckL( CStifItemParser& /*aItem*/ )
       
   120     {
       
   121     TInt ret = KErrNone;
       
   122     TInt heapSizeAtCheckpoint;
       
   123     User::Heap().AllocSize( heapSizeAtCheckpoint );
       
   124     if ( iHeapSize != heapSizeAtCheckpoint )
       
   125         {
       
   126         //ret = KErrTooBig; <-- not reliable
       
   127         _LOG("Warning: potential memory leak detected!!!");
       
   128         }
       
   129     _RETURN("HeapCheckL End", ret);
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CWmUnitTest::SetMassL
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 TInt CWmUnitTest::SetMassL( CStifItemParser& aItem )
       
   137     {
       
   138     aItem.GetNextInt( iMass );
       
   139     _RETURN("SetMassL End", KErrNone);
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CWmUnitTest::InstallWrtWidgetL
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 TInt CWmUnitTest::InstallWrtWidgetL( CStifItemParser& aItem )
       
   147     {
       
   148 	TInt ret = KErrNone;
       
   149     TPtrC inputStr;
       
   150     aItem.SetParsingType( CStifItemParser::EQuoteStyleParsing );
       
   151     User::LeaveIfError( aItem.GetNextString( inputStr ) );
       
   152     if ( inputStr.Length() == 0 ) User::Leave( KErrArgument );
       
   153 	
       
   154 	// install widget
       
   155     SwiUI::RSWInstSilentLauncher installer;
       
   156     User::LeaveIfError( installer.Connect() );
       
   157     CleanupClosePushL( installer );
       
   158 
       
   159     SwiUI::TInstallReqPckg installReqPckg;
       
   160     SwiUI::TInstallOptions options;
       
   161     TRequestStatus status = KRequestPending;
       
   162     
       
   163     options.iUpgrade = SwiUI::EPolicyAllowed;
       
   164     options.iOptionalItems = SwiUI::EPolicyAllowed;
       
   165     options.iOCSP = SwiUI::EPolicyAllowed;
       
   166     options.iIgnoreOCSPWarnings = SwiUI::EPolicyAllowed;
       
   167     options.iUntrusted = SwiUI::EPolicyAllowed;
       
   168     options.iPackageInfo = SwiUI::EPolicyAllowed;
       
   169     options.iCapabilities = SwiUI::EPolicyAllowed;
       
   170     options.iKillApp = SwiUI::EPolicyAllowed;
       
   171     options.iOverwrite = SwiUI::EPolicyAllowed;
       
   172     options.iDownload = SwiUI::EPolicyAllowed;
       
   173     options.iDrive = 'C';
       
   174     options.iLang = User::Language();
       
   175     options.iUsePhoneLang = ETrue;
       
   176     options.iUpgradeData = SwiUI::EPolicyAllowed;
       
   177     
       
   178     SwiUI::TInstallOptionsPckg optionsPkg( options );
       
   179     installer.SilentInstall( status , inputStr, optionsPkg );
       
   180     User::WaitForRequest( status );
       
   181     ret = status.Int();
       
   182 	CleanupStack::PopAndDestroy( &installer );
       
   183     _RETURN("InstallWrtWidgetL End", ret);
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CWmUnitTest::UninstallWrtWidgetL
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 TInt CWmUnitTest::UninstallWrtWidgetL( CStifItemParser& aItem )
       
   191     {
       
   192     TInt ret = KErrNone;
       
   193 	TPtrC inputStr;
       
   194     aItem.SetParsingType( CStifItemParser::EQuoteStyleParsing );
       
   195     User::LeaveIfError( aItem.GetNextString( inputStr ) );
       
   196     if ( inputStr.Length() == 0 ) User::Leave( KErrArgument );
       
   197 
       
   198 	TUid uid;
       
   199 	TLex lex( inputStr );
       
   200 	lex.SkipSpaceAndMark();
       
   201 	TPtrC mtoken = lex.MarkedToken();
       
   202 	TInt pos = mtoken.FindF( KHexPrefix );
       
   203 	if ( pos == 0 )
       
   204 		{
       
   205 		TLex lex( mtoken.Mid( KHexPrefix().Length() ) );
       
   206 		TUint id = 0;
       
   207 		ret = lex.Val( id, EHex );
       
   208 		uid = TUid::Uid( (TInt)id );
       
   209 		}
       
   210 	else
       
   211 		{
       
   212 		TInt id( 0 );
       
   213 		ret = lex.Val( id );
       
   214 		uid.iUid = id;
       
   215 		}
       
   216 
       
   217 	if ( ret == KErrNone )
       
   218 		{
       
   219 		// Uninstall widget
       
   220 		SwiUI::RSWInstSilentLauncher installer;
       
   221 		User::LeaveIfError( installer.Connect() );
       
   222 		CleanupClosePushL( installer );
       
   223 		
       
   224 		TRequestStatus status = KRequestPending;
       
   225 		SwiUI::TUninstallOptions optionsUninstall;
       
   226 		optionsUninstall.iBreakDependency = SwiUI::EPolicyAllowed;
       
   227 		optionsUninstall.iKillApp = SwiUI::EPolicyAllowed;
       
   228 		SwiUI::TUninstallOptionsPckg uninstallOptionsPkg( optionsUninstall );
       
   229 		
       
   230 		installer.SilentUninstall( status, uid, uninstallOptionsPkg, KWrtMime );
       
   231 		User::WaitForRequest( status );				
       
   232 		CleanupStack::PopAndDestroy( &installer );
       
   233 		}
       
   234 	
       
   235     _RETURN("UninstallWrtWidgetL End", ret);
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CWmUnitTest::ErrorPopup
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 TInt CWmUnitTest::ErrorPopupL( CStifItemParser& /*aItem*/ )
       
   243     {
       
   244     CWmResourceLoader* res = CWmResourceLoader::NewL( *CEikonEnv::Static() );
       
   245     res->ErrorPopup(KErrNone);
       
   246     delete res;
       
   247     _RETURN("ErrorPopupL End", KErrNone);
       
   248     }
       
   249 // End of File