imservices/xmppsettingsfetcher/tsrc/xmppsettingsfetchermt/src/xmppsettingsfetchermtCases.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 2002 - 2007 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:  xmppsettingsfetchermtCases.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // [INCLUDE FILES] - do not remove
       
    21 #include <e32math.h>
       
    22 #include "xmppsettingsfetchermt.h"
       
    23 #include "xmppsettingsfetcher.h"
       
    24 #include "xmppparameters.h"
       
    25 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 //extern  ?external_data;
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES  
       
    30 //extern ?external_function( ?arg_type,?arg_type );
       
    31 
       
    32 // CONSTANTS
       
    33 //const ?type ?constant_var = ?constant;
       
    34 
       
    35 // MACROS
       
    36 //#define ?macro ?macro_def
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 //const ?type ?constant_var = ?constant;
       
    40 //#define ?macro_name ?macro_def
       
    41 
       
    42 // MODULE DATA STRUCTURES
       
    43 //enum ?declaration
       
    44 //typedef ?declaration
       
    45 
       
    46 // LOCAL FUNCTION PROTOTYPES
       
    47 //?type ?function_name( ?arg_type, ?arg_type );
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 //class ?FORWARD_CLASSNAME;
       
    51 
       
    52 // ============================= LOCAL FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // ?function_name ?description.
       
    56 // ?description
       
    57 // Returns: ?value_1: ?description
       
    58 //          ?value_n: ?description_line1
       
    59 //                    ?description_line2
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 /*
       
    63 ?type ?function_name(
       
    64     ?arg_type arg,  // ?description
       
    65     ?arg_type arg)  // ?description
       
    66     {
       
    67 
       
    68     ?code  // ?comment
       
    69 
       
    70     // ?comment
       
    71     ?code
       
    72     }
       
    73 */
       
    74 
       
    75 // ============================ MEMBER FUNCTIONS ===============================
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // Cxmppsettingsfetchermt::Case
       
    79 // Returns a test case by number.
       
    80 //
       
    81 // This function contains an array of all available test cases 
       
    82 // i.e pair of case name and test function. If case specified by parameter
       
    83 // aCaseNumber is found from array, then that item is returned.
       
    84 // 
       
    85 // The reason for this rather complicated function is to specify all the
       
    86 // test cases only in one place. It is not necessary to understand how
       
    87 // function pointers to class member functions works when adding new test
       
    88 // cases. See function body for instructions how to add new test case.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 const TCaseInfo Cxmppsettingsfetchermt::Case ( 
       
    92     const TInt aCaseNumber ) const 
       
    93      {
       
    94 
       
    95     /**
       
    96     * To add new test cases, implement new test case function and add new 
       
    97     * line to KCases array specify the name of the case and the function 
       
    98     * doing the test case
       
    99     * In practice, do following
       
   100     * 1) Make copy of existing test case function and change its name
       
   101     *    and functionality. Note that the function must be added to 
       
   102     *    xmppsettingsfetchermt.cpp file and to xmppsettingsfetchermt.h 
       
   103     *    header file.
       
   104     *
       
   105     * 2) Add entry to following KCases array either by using:
       
   106     *
       
   107     * 2.1: FUNCENTRY or ENTRY macro
       
   108     * ENTRY macro takes two parameters: test case name and test case 
       
   109     * function name.
       
   110     *
       
   111     * FUNCENTRY macro takes only test case function name as a parameter and
       
   112     * uses that as a test case name and test case function name.
       
   113     *
       
   114     * Or
       
   115     *
       
   116     * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used
       
   117     * only with OOM (Out-Of-Memory) testing!
       
   118     *
       
   119     * OOM_ENTRY macro takes five parameters: test case name, test case 
       
   120     * function name, TBool which specifies is method supposed to be run using
       
   121     * OOM conditions, TInt value for first heap memory allocation failure and 
       
   122     * TInt value for last heap memory allocation failure.
       
   123     * 
       
   124     * OOM_FUNCENTRY macro takes test case function name as a parameter and uses
       
   125     * that as a test case name, TBool which specifies is method supposed to be
       
   126     * run using OOM conditions, TInt value for first heap memory allocation 
       
   127     * failure and TInt value for last heap memory allocation failure. 
       
   128     */ 
       
   129 
       
   130     static TCaseInfoInternal const KCases[] =
       
   131         {
       
   132         // [test cases entries] - do not remove
       
   133         
       
   134         // NOTE: When compiled to GCCE, there must be Classname::
       
   135         // declaration in front of the method name, e.g. 
       
   136         // Cxmppsettingsfetchermt::PrintTest. Otherwise the compiler
       
   137         // gives errors.
       
   138         
       
   139         ENTRY( "write and read valid settings", Cxmppsettingsfetchermt::SetAndReadSettingsL ),
       
   140         ENTRY( "read unexisting settings", Cxmppsettingsfetchermt::ReadUnexistingSettingsL ),
       
   141         ENTRY( "write and read incomplete settings", Cxmppsettingsfetchermt::ReadIncompleteSettingsL ),
       
   142         ENTRY( "descriptor values test", Cxmppsettingsfetchermt::ReadDescSettingsL ),
       
   143         ENTRY( "integer values test", Cxmppsettingsfetchermt::ReadIntSettingsL ),
       
   144 
       
   145 //        FUNCENTRY( Cxmppsettingsfetchermt::PrintTest ),
       
   146 
       
   147         // Example how to use OOM functionality
       
   148         //OOM_ENTRY( "Loop test with OOM", Cxmppsettingsfetchermt::LoopTest, ETrue, 2, 3),
       
   149         //OOM_FUNCENTRY( Cxmppsettingsfetchermt::PrintTest, ETrue, 1, 3 ),
       
   150         };
       
   151 
       
   152     // Verify that case number is valid
       
   153     if( (TUint) aCaseNumber >= sizeof( KCases ) / 
       
   154                                sizeof( TCaseInfoInternal ) )
       
   155         {
       
   156         // Invalid case, construct empty object
       
   157         TCaseInfo null( (const TText*) L"" );
       
   158         null.iMethod = NULL;
       
   159         null.iIsOOMTest = EFalse;
       
   160         null.iFirstMemoryAllocation = 0;
       
   161         null.iLastMemoryAllocation = 0;
       
   162         return null;
       
   163         } 
       
   164 
       
   165     // Construct TCaseInfo object and return it
       
   166     TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName );
       
   167     tmp.iMethod = KCases[ aCaseNumber ].iMethod;
       
   168     tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest;
       
   169     tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation;
       
   170     tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation;
       
   171     return tmp;
       
   172 
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // Cxmppsettingsfetchermt::LoopTest
       
   177 // Another printing to UI test.
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 TInt Cxmppsettingsfetchermt::SetAndReadSettingsL( TTestResult& aResult )
       
   181     {
       
   182     TUint32 settingId = 0;
       
   183     CXmppSettingsApi* api = CXmppSettingsApi::NewLC();
       
   184 
       
   185     TRAPD( error, api->CreateSettingsRecordL( settingId ) );
       
   186     User::LeaveIfError( error );
       
   187 	
       
   188 	WriteSettingsL( api, settingId, EPositiveTest );
       
   189     CleanupStack::PopAndDestroy( api );
       
   190 	
       
   191     CXmppParameters* xmppParams = CXmppParameters::NewL();
       
   192     CleanupStack::PushL( xmppParams );
       
   193     CXmppSettingsFetcher::ReadSettingsL( settingId, *xmppParams );
       
   194     
       
   195     //verify that all settings read are correct
       
   196     TBool verify = VerifySettingsL( xmppParams, settingId, EPositiveTest );
       
   197     CleanupStack::PopAndDestroy( xmppParams );
       
   198     
       
   199     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   200     if(verify)
       
   201     	aResult.SetResult( KErrNone, KTestcasePassed );
       
   202     else
       
   203     	aResult.SetResult( KErrGeneral, KVerificationFailed );
       
   204 
       
   205     // Case was executed
       
   206     return KErrNone;
       
   207     }
       
   208 
       
   209 
       
   210 TInt Cxmppsettingsfetchermt::ReadUnexistingSettingsL( TTestResult& aResult )
       
   211     {
       
   212     CXmppParameters* xmppParams = CXmppParameters::NewL();
       
   213     CleanupStack::PushL( xmppParams );
       
   214     CXmppSettingsFetcher::ReadSettingsL( 9999, *xmppParams ); //assuming 9999 records have not been created :)
       
   215     
       
   216     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   217     CleanupStack::PopAndDestroy( xmppParams );
       
   218 	aResult.SetResult( KErrNone, KTestcasePassed );
       
   219 
       
   220     // Case was executed
       
   221     return KErrNone;
       
   222     }
       
   223 
       
   224 
       
   225 TInt Cxmppsettingsfetchermt::ReadIncompleteSettingsL( TTestResult& aResult )
       
   226     {
       
   227     TUint32 settingId = 0;
       
   228     CXmppSettingsApi* api = CXmppSettingsApi::NewLC();
       
   229 
       
   230     TRAPD( error, api->CreateSettingsRecordL( settingId ) );
       
   231     User::LeaveIfError( error );
       
   232 	
       
   233 	WriteIncompleteSettingsL( api, settingId );
       
   234     CleanupStack::PopAndDestroy( api );
       
   235 	
       
   236     CXmppParameters* xmppParams = CXmppParameters::NewL();
       
   237     CleanupStack::PushL( xmppParams );
       
   238     TRAP( error, CXmppSettingsFetcher::ReadSettingsL( settingId, *xmppParams ) );
       
   239     CleanupStack::PopAndDestroy( xmppParams );
       
   240     
       
   241     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   242     if( error == KErrNotFound )
       
   243     	aResult.SetResult( KErrNone, KTestcasePassed );
       
   244     else
       
   245     	aResult.SetResult( KErrGeneral, KTestcaseFailed );
       
   246 
       
   247     // Case was executed
       
   248     return KErrNone;
       
   249     }
       
   250 
       
   251 
       
   252 TInt Cxmppsettingsfetchermt::ReadDescSettingsL( TTestResult& aResult )
       
   253     {
       
   254     TUint32 settingId = 0;
       
   255     CXmppSettingsApi* api = CXmppSettingsApi::NewLC();
       
   256 
       
   257     TRAPD( error, api->CreateSettingsRecordL( settingId ) );
       
   258     User::LeaveIfError( error );
       
   259 	
       
   260 	WriteSettingsL( api, settingId, EDescriptorTest );
       
   261     CleanupStack::PopAndDestroy( api );
       
   262 	
       
   263     CXmppParameters* xmppParams = CXmppParameters::NewL();
       
   264     CleanupStack::PushL( xmppParams );
       
   265     CXmppSettingsFetcher::ReadSettingsL( settingId, *xmppParams );
       
   266     
       
   267     //verify that all settings read are correct
       
   268     TBool verify = VerifySettingsL( xmppParams, settingId, EDescriptorTest );
       
   269     CleanupStack::PopAndDestroy( xmppParams );
       
   270     
       
   271     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   272     if(verify)
       
   273     	aResult.SetResult( KErrNone, KTestcasePassed );
       
   274     else
       
   275     	aResult.SetResult( KErrGeneral, KVerificationFailed );
       
   276 
       
   277     // Case was executed
       
   278     return KErrNone;
       
   279     }
       
   280 
       
   281 
       
   282 TInt Cxmppsettingsfetchermt::ReadIntSettingsL( TTestResult& aResult )
       
   283     {
       
   284     TUint32 settingId = 0;
       
   285     CXmppSettingsApi* api = CXmppSettingsApi::NewLC();
       
   286 
       
   287     TRAPD( error, api->CreateSettingsRecordL( settingId ) );
       
   288     User::LeaveIfError( error );
       
   289 	
       
   290 	WriteSettingsL( api, settingId, EIntegerTest );
       
   291     CleanupStack::PopAndDestroy( api );
       
   292 	
       
   293     CXmppParameters* xmppParams = CXmppParameters::NewL();
       
   294     CleanupStack::PushL( xmppParams );
       
   295     CXmppSettingsFetcher::ReadSettingsL( settingId, *xmppParams );
       
   296     
       
   297     //verify that all settings read are correct
       
   298     TBool verify = VerifySettingsL( xmppParams, settingId, EIntegerTest );
       
   299     CleanupStack::PopAndDestroy( xmppParams );
       
   300     
       
   301     // Sets test case result and description(Maximum size is KStifMaxResultDes)
       
   302     if(verify)
       
   303     	aResult.SetResult( KErrNone, KTestcasePassed );
       
   304     else
       
   305     	aResult.SetResult( KErrGeneral, KVerificationFailed );
       
   306 
       
   307     // Case was executed
       
   308     return KErrNone;
       
   309     }
       
   310 
       
   311 
       
   312 void Cxmppsettingsfetchermt::WriteSettingsL( CXmppSettingsApi* aApi, TUint32 aSettingId, TTestCase aTestCase )
       
   313 {
       
   314 	TInt error = KErrNone;
       
   315 	
       
   316     TRAP( error, aApi->SetParamL( aSettingId,
       
   317                                               XmppParams::KXmppParamHttpsProxyServerPort(),
       
   318                                               httpsProxyPort ) );
       
   319 	if( aTestCase == EIntegerTest )	//integer test
       
   320 		{
       
   321 	    TRAP( error, aApi->SetParamL( aSettingId,
       
   322 	                                              XmppParams::KXmppParamServerPort(),
       
   323 	                                              portNegative ) ); //negative value
       
   324 	    TRAP( error, aApi->SetParamL( aSettingId,
       
   325 	                                              XmppParams::KXmppParamSnapId(),
       
   326 	                                              iapIdZero ) ); //zero
       
   327 		}
       
   328 	else
       
   329 		{
       
   330 	    TRAP( error, aApi->SetParamL( aSettingId,
       
   331 	                                              XmppParams::KXmppParamServerPort(),
       
   332 	                                              port ) );
       
   333 	    TRAP( error, aApi->SetParamL( aSettingId,
       
   334 	                                              XmppParams::KXmppParamSnapId(),
       
   335 	                                              iapId ) );
       
   336 		}	
       
   337 
       
   338     // buffers
       
   339     TRAP( error, aApi->SetParamL( aSettingId,
       
   340                                               XmppParams::KXmppParamXmppServerAddress(),
       
   341                                               KXmppServerAddress ) );
       
   342 
       
   343 	if( aTestCase == EDescriptorTest )	//descriptor test
       
   344 		{
       
   345 	    TRAP( error, aApi->SetParamL( aSettingId,
       
   346 	                                              XmppParams::KXmppParamUsername(),
       
   347 	                                              KNullUsername ) ); //empty string
       
   348 	    TRAP( error, aApi->SetParamL( aSettingId,
       
   349 	                                              XmppParams::KXmppParamPassword(),
       
   350 	                                              KNullDesC ) ); //null descriptor
       
   351 		}
       
   352     else
       
   353 	    {
       
   354 	    TRAP( error, aApi->SetParamL( aSettingId,
       
   355 	                                              XmppParams::KXmppParamUsername(),
       
   356 	                                              KUsername ) );
       
   357 	    TRAP( error, aApi->SetParamL( aSettingId,
       
   358 	                                              XmppParams::KXmppParamPassword(),
       
   359 	                                              KPassword ) );
       
   360 	    }
       
   361 
       
   362 	// gabble specific things.........
       
   363     TRAP( error, aApi->SetParamL( aSettingId,
       
   364                                               XmppParams::KXmppParamResource(),
       
   365                                               KResouceText ) );
       
   366     TRAP( error, aApi->SetParamL( aSettingId,
       
   367                                               XmppParams::KXmppParamHttpsProxyServerAddress(),
       
   368                                               KHttpsProxyServerAddressText ) );
       
   369     TRAP( error, aApi->SetParamL( aSettingId,
       
   370                                               XmppParams::KXmppParamAlais(),
       
   371                                               KAliasText ) );
       
   372     TRAP( error, aApi->SetParamL( aSettingId,
       
   373                                               XmppParams::KXmppParamOldSSLRequired(),
       
   374                                               oldSSL ) );
       
   375     TRAP( error, aApi->SetParamL( aSettingId,
       
   376                                               XmppParams::KXmppParamRegisterRequired(),
       
   377                                               resigter ) );
       
   378     TRAP( error, aApi->SetParamL( aSettingId,
       
   379                                   XmppParams::KXmppParamConnMgrBus(),
       
   380                                   KConnMgrBus ) );
       
   381                                   
       
   382     TRAP( error, aApi->SetParamL( aSettingId,
       
   383                                   XmppParams::KXmppParamConnMgrPath(),
       
   384                                   KConnMgrPath ));
       
   385     
       
   386     TRAP( error, aApi->SetParamL( aSettingId,
       
   387                                               XmppParams::KXmppParamProtocol(),
       
   388                                               KParamProtocol ));
       
   389 
       
   390     }
       
   391 
       
   392 
       
   393 TBool Cxmppsettingsfetchermt::VerifySettingsL( CXmppParameters* aXmppParams, TUint32 aSettingsId, TTestCase aTestCase )
       
   394 {
       
   395 	switch (aTestCase)
       
   396 		{
       
   397 		case EPositiveTest:
       
   398 			if ( 
       
   399 				( aXmppParams->SettingsId() == aSettingsId ) &&
       
   400 				( aXmppParams->ServerPort() == port ) &&
       
   401 				( aXmppParams->ProxyPort() == httpsProxyPort ) &&
       
   402 				( aXmppParams->IapId() == iapId ) &&
       
   403 				( aXmppParams->ServerAddress() == KXmppServerAddress ) &&
       
   404 				( aXmppParams->UserName() == KUsername ) &&
       
   405 				( aXmppParams->Passwd() == KPassword ) &&
       
   406 				( aXmppParams->Resource() == KResouceText ) &&
       
   407 				( aXmppParams->ProxyServer() == KHttpsProxyServerAddressText ) &&
       
   408 				( aXmppParams->Ssl() == oldSSL )
       
   409 			   )
       
   410 				return ETrue;
       
   411 			else
       
   412 				return EFalse;	
       
   413 		case EDescriptorTest:
       
   414 			if ( 
       
   415 				( aXmppParams->SettingsId() == aSettingsId ) &&
       
   416 				( aXmppParams->ServerPort() == port ) &&
       
   417 				( aXmppParams->ProxyPort() == httpsProxyPort ) &&
       
   418 				( aXmppParams->IapId() == iapId ) &&
       
   419 				( aXmppParams->ServerAddress() == KXmppServerAddress ) &&
       
   420 				( aXmppParams->UserName() == KNullUsername ) && //empty string
       
   421 				( aXmppParams->Passwd() == KNullDesC ) && //null descriptor
       
   422 				( aXmppParams->Resource() == KResouceText ) &&
       
   423 				( aXmppParams->ProxyServer() == KHttpsProxyServerAddressText ) &&
       
   424 				( aXmppParams->Ssl() == oldSSL )
       
   425 			   )
       
   426 				return ETrue;
       
   427 			else
       
   428 				return EFalse;	
       
   429 		case EIntegerTest:
       
   430 			if ( 
       
   431 				( aXmppParams->SettingsId() == aSettingsId ) &&
       
   432 				( aXmppParams->ServerPort() == portNegative ) && //negative
       
   433 				( aXmppParams->ProxyPort() == httpsProxyPort ) && 
       
   434 				( aXmppParams->IapId() == iapIdZero ) && //zero
       
   435 				( aXmppParams->ServerAddress() == KXmppServerAddress ) &&
       
   436 				( aXmppParams->UserName() == KUsername ) &&
       
   437 				( aXmppParams->Passwd() == KPassword ) &&
       
   438 				( aXmppParams->Resource() == KResouceText ) &&
       
   439 				( aXmppParams->ProxyServer() == KHttpsProxyServerAddressText ) &&
       
   440 				( aXmppParams->Ssl() == oldSSL )
       
   441 			   )
       
   442 				return ETrue;
       
   443 			else
       
   444 				return EFalse;	
       
   445 		}
       
   446 	return EFalse;
       
   447  }
       
   448 
       
   449 
       
   450 void Cxmppsettingsfetchermt::WriteIncompleteSettingsL( CXmppSettingsApi* aApi, TUint32 aSettingId )
       
   451 {
       
   452 	TInt error = KErrNone;
       
   453 	
       
   454     TRAP( error, aApi->SetParamL( aSettingId,
       
   455                                               XmppParams::KXmppParamServerPort(),
       
   456                                               port ) );
       
   457 
       
   458     // buffers
       
   459     TRAP( error, aApi->SetParamL( aSettingId,
       
   460                                               XmppParams::KXmppParamXmppServerAddress(),
       
   461                                               KXmppServerAddress ) );
       
   462     TRAP( error, aApi->SetParamL( aSettingId,
       
   463                                               XmppParams::KXmppParamUsername(),
       
   464                                               KUsername ) );
       
   465     TRAP( error, aApi->SetParamL( aSettingId,
       
   466                                               XmppParams::KXmppParamPassword(),
       
   467                                               KPassword ) );
       
   468 	// gabble specific things.........
       
   469     TRAP( error, aApi->SetParamL( aSettingId,
       
   470                                               XmppParams::KXmppParamHttpsProxyServerAddress(),
       
   471                                               KHttpsProxyServerAddressText ) );
       
   472     TRAP( error, aApi->SetParamL( aSettingId,
       
   473                                               XmppParams::KXmppParamOldSSLRequired(),
       
   474                                               oldSSL ) );
       
   475     }
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // ?classname::?member_function
       
   479 // ?implementation_description
       
   480 // (other items were commented in a header).
       
   481 // -----------------------------------------------------------------------------
       
   482 //
       
   483 /*
       
   484 ?type ?classname::?member_function(
       
   485    ?arg_type arg,
       
   486    ?arg_type arg )
       
   487    {
       
   488 
       
   489    ?code
       
   490 
       
   491    }
       
   492 */
       
   493 
       
   494 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // ?function_name implements...
       
   498 // ?implementation_description.
       
   499 // Returns: ?value_1: ?description
       
   500 //          ?value_n: ?description
       
   501 //                    ?description
       
   502 // -----------------------------------------------------------------------------
       
   503 //
       
   504 /*
       
   505 ?type  ?function_name(
       
   506     ?arg_type arg,  // ?description
       
   507     ?arg_type arg )  // ?description
       
   508     {
       
   509 
       
   510     ?code
       
   511 
       
   512     }
       
   513 */
       
   514 //  [End of File] - do not remove